在我的pubspec中将linter升级到新版本(flutter_lints: 2.0.1)之后

顺便说一句:我知道我可以禁用这个规则.

推荐答案

我遇到了同样的问题,现在当你生成一个StatefulWidget而不是在createState方法中返回_ExampleState时,它现在返回State<Example>,这避免了返回私有类型.我最终更新了我所有的小部件,使之适应这种方法.

所以

class Example extends StatefulWidget {
  const Example({Key? key}) : super(key: key);

  @override
  _ExampleState createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

可以重写为

class Example extends StatefulWidget {
  // you can al所以 now use a super initializer for key 
  // if you are using dart 2.17
  const Example({super.key});

  // now returning State<Example>
  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Flutter相关问答推荐

关闭视频通话,相机仍在运行!(Flutter WebRTC)

无法在GroupButton内部正确呈现

我可以在iOS设备上使用Ffltter实现Google Pay按钮吗?

底部导航栏项目在抖动中不更改 colored颜色

Flutter 动画列表一次构建所有项目,而不是仅构建可见的项目

有没有什么方法可以加快在Flutter 中加载Quill HTML编辑器的速度?

在VSCode中运行应用程序而不进行调试时,控制台仍显示为调试模式

如何确定Flutter 中的文本 colored颜色 ?

如何让两个展开的Widget根据其子窗口的屏幕大小

在创建显示此错误的Flutter 深度链接时

Flutter类调用另一个类中的另一个方法失败

如何在巡逻测试期间重新启动dart 侧应用程序状态?

如何在 Flutter (iOS) 中解决这个问题

如何将 chrome web 模拟器添加到 vs code

在 flutter 的另一个类中使用变量值

我想在一个屏幕上有两个相同区域的列表视图,我该如何设置?

在 CircleAvatar 中放置芯片

在 flutter 中自定义 agora 视频通话 UI

在 flutter 中使用 Firebase 实时数据库数据创建无限滚动效果

如何将所有行项目平等地放在一行中?Flutter