no_logic_in_create_state
Don't put any logic in 'createState'.
Description
#The analyzer produces this diagnostic when an implementation of
createState
in a subclass of StatefulWidget
contains any logic other
than the return of the result of invoking a zero argument constructor.
Examples
#The following code produces this diagnostic because the constructor invocation has arguments:
dart
import 'package:flutter/material.dart';
class MyWidget extends StatefulWidget {
@override
MyState createState() => MyState(0);
}
class MyState extends State {
int x;
MyState(this.x);
}
Common fixes
#Rewrite the code so that createState
doesn't contain any logic:
dart
import 'package:flutter/material.dart';
class MyWidget extends StatefulWidget {
@override
MyState createState() => MyState();
}
class MyState extends State {
int x = 0;
MyState();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。