我是 flutter 新手,在传递字符串时遇到错误,并到处查找,最后将其添加到 StackOverflow 中
错误是
Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
void errorSnackBar(BuildContext context, String? text) {
ScaffoldMessenger.of(context).showSnackBar(new SnackBar(
duration: new Duration(seconds: 4),
content: new Row(
children: <Widget>[
Icon(
Icons.error,
color: Colors.red,
),
Padding(
padding: const EdgeInsets.fromLTRB(10.0, 0, 0, 0),
child: new Text(text),
),
],
),
));
}
Run Code Online (Sandbox Code Playgroud) dart android-studio visual-studio-code flutter flutter-layout