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();
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.