flutter开发中Use ‘const’ with the constructor to improve performance. Try adding the ‘const’ keyword to the constructor invocation.
一个关于使用const关键字的警告。这个警告表示你可以在一些地方使用const关键字来提高性能。在Flutter中,如果一个小部件的所有参数都是常量,那么将其声明为const可以让Flutter更高效地重用它。
可以在以下地方添加const关键字来解决这个警告:
诸如:
DropdownButtonFormField 的 items 参数
TextField 构造函数
InputDecoration 构造函数
Text 构造函数
等等
做个例子:
Text(
"Please register your account",
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontFamily: "PingFang SC",
fontWeight: FontWeight.w800,
),
这样的代码 flutter就会提示警告
const Text(
"Please register your account",
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontFamily: "PingFang SC",
fontWeight: FontWeight.w800,
),
如果是这样,这个问题就能解决-ok 完美
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。