【发布时间】:2021-02-19 05:16:25
【问题描述】:
我在这里阅读了有关Final and Const 的文章。我还看到 Flutter 团队的许多示例代码尽可能地使用了许多 const(只需阅读来自包 river_pod 的 todos list 的示例),以及一些关于如何编译时常量小部件 有利于性能 (like this)。
是否有任何简单的方法让 IDE 插件/lint 尽可能多地自动添加 const Widget/Variable?或者给一些提示,比如This Widget/Variable' is better to use with const。
我在这里查看了lint package 并阅读了Effective Dart:Style,但没有看到任何相关信息。
感谢您的帮助!
我添加一些例子:
ListView(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 40), // here
children: [ ...
const SizedBox(height: 42), //here
const Image( //here
width: 100,
height: 100,
image: AssetImage('assets/logo.png'),
)
...
甚至是一个班级
Container(
child: const Toolbar(), //here
...
class Toolbar extends HookWidget {
const Toolbar({Key key}) : super(key: key); //here
...
【问题讨论】:
标签: performance flutter dart