3

I tried this link and it didn't work.

In this code when I try to change height of AppBar, but it doesn't any change.

Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Colors.transparent,
    body: Container(
      height: double.infinity,
        child: Column(
          children: <Widget>[
            PreferredSize(
              preferredSize: Size.fromHeight(150.0),
              child: AppBar(
                backgroundColor: Colors.white.withOpacity(0.9),
                title: Container(height: 150.0,),
              ),
            )
          ],
        )),
  );
}

Note: My AppBar(...) isn't used in appBar:

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
DolDurma
  • 15,753
  • 51
  • 198
  • 377

3 Answers3

4

Just use toolbarHeight:

appBar: AppBar(
  toolbarHeight: 150, // This is your height!
  title: Text('AppBar'),
)

However, if you don't want to use appBar property

Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Colors.transparent,
    body: Container(
      height: double.infinity,
      child: Column(
        children: <Widget>[
          Container(
            height: 150, // height of AppBar
            child: AppBar(
              backgroundColor: Colors.blue.withOpacity(0.9),
              title: Text("AppBar"),
            ),
          )
        ],
      ),
    ),
  );
}
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
1
   class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return new MaterialApp(
        title: 'Flutter Demo',
        theme: new ThemeData(
            primarySwatch: Colors.blue,
        ),
        home: new Scaffold(
            body: Stack(
            children: <Widget>[
            Container(
                color: Colors.blue,
            ),
            new Positioned(
                top: 0.0,
                left: 0.0,
                right: 0.0,
                child: AppBar(
                title: Text('App Bar'),
                backgroundColor: Colors.green,
                ),
            ),
            ],
        )),
        );
    }
    }

enter image description here

Amit Prajapati
  • 13,525
  • 8
  • 62
  • 84
0

For more controls , Use the PreferedSize widget to create your own appBar

Example :

appBar: PreferredSize(
     preferredSize: Size(100, 80), //width and height 
          // The size the AppBar would prefer if there were no other constraints.
     child: SafeArea(
       child: Container(
         height: 100,
         color: Colors.red,
         child: Center(child: Text('Fluter is great')),
       ),
     ),
),

Don't forget to use a SafeArea widget if you don't have a safeArea

Output :

enter image description here

Kab Agouda
  • 6,309
  • 38
  • 32