Flutter – the use of PreferredSize widget in flutter

dartflutter

I'm new in flutter, and I see there are few widgets for the layout design such as SizedBox and Container.
There is one widget which is PreferredSize Widget that I don't know and cannot find any example about it.
What makes it different from other widgets such as container and SizedBox which can set height and width?.
Can someone give an example?

Best Answer

https://flutter.dev/docs/catalog/samples/PreferredSize

Example : https://flutter.dev/docs/catalog/samples/app-bar-bottom

Any widget with a PreferredSize can appear at the bottom of an AppBar.

You can use PreferredSize to setting up your AppBar Size.

class MyApp1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Example',
        home: Scaffold(
            appBar: PreferredSize(
                preferredSize: Size.fromHeight(100.0), // here the desired height
                child: AppBar(
                  centerTitle: true,
                  title: Text("Example"),
                )
            ),

        )
    );
  }
}

enter image description here