I noticed the style error warning pop up in some of my code but also in the some of the official Flutter/Dart documentation/cookbook examples; e.g. at for
...
class AnimatedContainerApp extends StatefulWidget { const AnimatedContainerApp({super.key}); @override _AnimatedContainerAppState createState() => _AnimatedContainerAppState();
}
class _AnimatedContainerAppState extends State<AnimatedContainerApp> {
... My understanding of OOP and its nomenclature is sketchy at best and I don't quite understand the warning, but my actual question is, are the examples with this warning wrong, or sub-ideal - or does that style issue only apply in certain contexts that is perhaps not relevant to the examples and or I should ignore it, or is it an result of flutter/dart versions or some such or other?
1 Answer
From the latest docs:
Subclasses should override this method to return a newly created
instance of their associated [State] subclass:
@override
State<MyWidget> createState() => _MyWidgetState();So you should replace
@override
_AnimatedContainerAppState createState() => _AnimatedContainerAppState();with
@override
State<AnimatedContainerApp> createState() => _AnimatedContainerAppState(); 1