convert stateless widget to stateful widget code example

Example 1: convert stateless to stateful component flutter

To convert a stateless widget to a stateful widget, simply clik
on it, press alt + enter and select the convert option

Example 2: flutter stateful widget

class YellowBird extends StatefulWidget {
  const YellowBird({ Key key }) : super(key: key);

  
  _YellowBirdState createState() => _YellowBirdState();
}

class _YellowBirdState extends State<YellowBird> {
  
  Widget build(BuildContext context) {
    return Container(color: const Color(0xFFFFE306));
  }
}

Example 3: creating a stateful widget

class MyApp extends StatefulWidget {
  
  State<StatefulWidget> createState() {
    return _MyAppState();
  }
}

class _MyAppState extends State<MyApp> {
  
  Widget build(BuildContext context) {
    return Container(color: const Color(0xFFFFE306));
  }
}

Tags:

Dart Example