Const Widget

There are several techniques one can use to minimize the impact of rebuilding a stateful widget such as using const widgets where possible. This helps Flutter to rebuild only widgets that should be updated.

Example :

class _MyHomePageState extends State<MyHomePage> {

  @override

  Widget build(BuildContext context) {

    return Scaffold(

      appBarAppBar(

        titleconst Text("Test"),

      ),

      bodyColumn(

        children: [

          const Text("Text 1"),

          Container(

            marginconst EdgeInsets.all(20),

            colorconst Color.fromRGBO(210120801),

            childconst Text("Text 2"),

          ),

          const Padding(

            paddingEdgeInsets.all(40),

            childText("Text 3"),

          ),

        ],

      ),

      floatingActionButtonFloatingActionButton(

        childconst Icon(Icons.add),

        onPressed: () {},

      ),

    );

  }

}



flutter const widget