小编Avi*_*Jha的帖子

错误:(参数类型“String?”无法分配给参数类型“String”,因为“String?”可以为空,而“String”则不能。)在Flutter中

我是 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

2
推荐指数
1
解决办法
2万
查看次数