Flutter 自学问题汇总(长期更新)

1.The argument type 'Color?' can't be assigned to the parameter type 'Color'

就这么改吧

 color: (Colors.blue[300])!,

这是dartNull safty中的一项功能。有关更多信息,请查看此链接

https://medium.com/flutter/null-safety-flutter-tech-preview-cb5c98aba187

 2.Try adding either an explicit non-‘null‘ default value or the ‘required‘ modifier.

高版本的dart语法要求不能为空,

如果报这个错要么添加Require关键字强调不能为空,

要么添加不为空的标识“?”比如:​​​​​​​

3.dart2.0 之后单例的书写方式(flutter2.12.0版本的dart单例模式)

class Singleton{

  Singleton._privateConstructor();

  static final Singleton _instance = Singleton._privateConstructor();

  static Singleton get instance { return _instance;}

}

或者可以这样写

猜你喜欢

转载自blog.csdn.net/iblue007/article/details/124376996