Flutter 2.5 更新 - 每个静态 Widget 上的 const 关键字 [英] Flutter 2.5 update - const keyword on every static Widget

查看:16
本文介绍了Flutter 2.5 更新 - 每个静态 Widget 上的 const 关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

flutter 2.5更新后,每个使用静态数据的widget都需要放入const关键字

After flutter 2.5 update, every widget that uses static data need to by put in const keyword

如何摆脱该警告以使用 const或者在 Flutter 代码中创建小部件时如何自动插入 const

How to get ride of that warning to use const or how to auto insert const when we create widget in flutter code

推荐答案

这是因为默认情况下我们现在有 flutter_lints 规则.使用 const 关键字是一个好习惯.但是,如果您想删除它,可以编辑 static_analysis.yaml 文件并添加以下内容:

This is because by default we now have the flutter_lints rules. It is a good practice to use the const keyword. However if you feel like removing it, you can edit your static_analysis.yaml file and add the following:

linter:
  rules:
    prefer_const_constructors: false

21 年 11 月 24 日更新

dart fix --apply 现在可以修复 prefer_const_constructors 警告.

dart fix --apply can now fix prefer_const_constructors warnings.

这篇关于Flutter 2.5 更新 - 每个静态 Widget 上的 const 关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆