In this example, we are going to show you the easiest way to set the height of AppBar on Flutter app. We will use PreferredSize() widget to set the Height of AppBar. See the example below:
PreferredSize( //wrap with PreferredSize
preferredSize: Size.fromHeight(20), //height of appbar
child: AppBar(
title:Text("AppBar Height"), //appbar title
backgroundColor: Colors.redAccent //appbar background color
)
)
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: MyApp()
)
);
}
class MyApp extends StatefulWidget{
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize( //wrap with PreferredSize
preferredSize: Size.fromHeight(20), //height of appbar
child: AppBar(
title:Text("AppBar Height"), //appbar title
backgroundColor: Colors.redAccent //appbar background color
)
),
body: Container(
alignment:Alignment.topCenter,
padding: EdgeInsets.all(35),
child: Text("AppBar Height")
)
);
}
}
In this way, you can set AppBar Height in Flutter App.
Please Wait...
No any Comments on this Article