Can I increase height of app bar in flutter? - flutter

Is there any way of increasing height of app bar according to safe area in flutter cause the text in Center looks weird.

you can use toolbarHeight
AppBar(
toolbarHeight: 100,
title: Text('Main Page')
)

Yes you can do this like using below code. Put PreferredSize widget as a parent of AppBar and set a height.
appBar: PreferredSize(
preferredSize: Size.fromHeight(150.0),
child: AppBar(
title: Text('appbar'),
),
),

Related

Flutter: I enabled the immersive mode and the AppBar stays big. When I make it smaller the title becomes cropped and does not go up with the AppBar

The image above shows how I enabled the immersive mode.
This is how the AppBar looks without any modification.
And this is how it looks like, when I set the toolbarHeight to 10.
Here is the code from the image:
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xFF892D89),
toolbarHeight: 10,
centerTitle: true,
title: Container(
height: 30,
child: Image.asset('assets/fontlogo.png'),
),
),
);
}
I tried various of ways to solve this problem, but couldn't do it. One of those ways was to set resizeToAvoidBottomInset to true.
Scaffold(
resizeToAvoidBottomInset: true,
),
Or to use titleSpacing.
AppBar(
titleSpacing: 50,
title: Text('SignShine'),
),
If someone knows the solution, I would appreciate the reply and thank them in advance.

Flutter remove space above AppBar for iOS

The AppBar in iOS has an extra space above, and so the icon doesn't look like it's aligned vertically, how do you remove the extra space above? Thanks! Please refer to screenshots below:
Code:
Scaffold(
appBar: AppBar(
toolbarHeight: 70,
backgroundColor: Colors.white,
title: SvgPicture.asset(
Assets.mainLogo,
width: 7.w,
),
centerTitle: true,
),
);
just remove toolbarHeight:70 this line
You need to use PreferredSize
appBar: PreferredSize(
preferredSize: Size.fromHeight(50.0), // here the desired height
child: AppBar(
// ...
)
),

How to place banner ad on top of App Bar in Flutter?

How can I place a banner ad on the top of the top App Bar in Flutter? I have the banner ad at the bottom of the bottom app bar as shown below. I want to move it to the top, so that it becomes the first widget of the screen.
Try preferredSizeAppbar widget and increase the app bar height and use you banner.
You can use PreferredSize or flexibleSpace,
PreferredSize
appBar: PreferredSize(
preferredSize: Size.fromHeight(120), // change height of ads as you like
child: Container(
child: // here is ads
)
)
or
flexibleSpace
appBar: AppBar(
toolbarHeight: 120, // Set this appbar height
flexibleSpace: Container(
child: Text("this is add"), // make container of your ads
),
title: Text('Material App Bar'),
),

Trying to move widget position

I just started learning dart(flutter) using Angela's course, but unfortunately it seems outdated so I cant seem to understand how to do this from there.
I need to move the title to the center (I have it on the right just to test it, but even that didn't work):
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("I am Rich",textAlign:TextAlign.right),
),
),
));
}
The title property in the AppBar is centred by default. If you don't want that, you can set the 'centreTitle' property of the AppBar to false.
appBar: AppBar(
title: Text("Your title"),
),
appBar: AppBar(
centerTitle: false,
title: Text("Your title"),
),
On devices with text direction left to right, the title will be to the left it centerTitle is set it to false. If you really want to set it to the right, wrap your title widget with a Row Widget and set its mainAxisAlignment to mainAxisAlignment.end like this:
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text("Your title"),
],
),
),
On AppBar use centerTitle: true,
AppBar(
centerTitle: true,
title: Text("Chalo"),
),
does it solve on your case?

Expandable AppBar (onPressed)

How do I achieve this effect? I wanted to expand my AppBar after clicking on the dates.
The simplest way is to bring toggle a veriable then change the height of the bottom widget.
Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [IconButton(icon: Icon(Icons.place),onPressed: (){
setState((){
isOpen = !isOpen;
});
})],
bottom: PreferredSize(child: isOpen? Container(color:Colors.red, height: 100):Container(),preferredSize:Size.fromHeight(isOpen? 100:0) ,)
),)