如果我required从命名参数中删除,它会给我一个错误:
参数 'color' // 因其类型而不能具有值 'null',但隐式默认值为 'null'。
它们之间有什么区别,我们什么时候需要使用它们?
class RoundedButton extends StatelessWidget {
late final Color color;
final String title;
final VoidCallback? onPressedInput;
RoundedButton(
{required this.color,
required this.title,
@required this.onPressedInput});
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Material(
color: color,
borderRadius: BorderRadius.circular(30.0),
elevation: 5.0,
child: MaterialButton(
onPressed: onPressedInput,
minWidth: 200.0,
height: 42.0,
child: Text(
title,
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud) 使文本的随机部分在不带 textSpan 的 flutter 中可点击,因为当我更改语言时,单词的顺序也会改变。对于 textSpan,我们知道文本的顺序很重要。
\n下面有土耳其语和吉尔吉斯语的用户协议文本。如果语言环境为土耳其语,则应显示土耳其语用户协议,否则应显示吉尔吉斯语用户协议。
\n示例文本:
\n