I'm new to flutter/dart, so while I try to make an app I also try to understand why things are a certain way. In the flutter docs there is example code of a stateful widget as shown:
class YellowBird extends StatefulWidget {
const YellowBird({ Key key }) : super(key: key);
@override
_YellowBirdState createState() => new _YellowBirdState();
}
class _YellowBirdState extends State<YellowBird> {
@override
Widget build(BuildContext context) {
return new Container(color: const Color(0xFFFFE306));
}
}
Questions:
Why are they defined with two classes as opposed to one? I'm guessing the State class can be used somewhere else so it was better to be split up.
From what I understand the
createState()
function returns an object of typeState
, so having_YellowBirdState extends State
makes sense, but why isYellowBird
passed into the generic class ofState
? My guess it has something to do withYellowbird
extending theStatefulWidget
class but not quite sure.