What is the use of PreferredSize widget in flutter?

https://api.flutter.dev/flutter/widgets/PreferredSize-class.html

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

Leave a Comment