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:
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:
import 'package:flutter/material.dart';
class MyWidget extends StatefulWidget {
@override
MyState createState() => MyState();
}
class MyState extends State {
int x = 0;
MyState();
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.