flutter custom appbar vertical position relative to status bar - flutter

I used the example in the following link to create a custom appBar.
The code works, however the appbar is positioned at the top of the screen behind the Android status bar
How can I position the appBar such that it starts rendering under the status bar?
version used:
Flutter 1.26.0-8.0.pre • channel dev
Android R30

There is a widget called SafeArea that set the padding of your widget to avoid the intrusion of the status bar. You can use it as:
// Use the SafeArea here to position the AppBar under the status bar
SafeArea(
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size(double.infinity, 100),
child: Container(
decoration: BoxDecoration(
// ... other lines

Related

How to ignore bottomNavigationBar with the Align widget?

Say there is a Scaffold with a bottomNavigationBar property that is populated. If you use a Stack with a Align widget inside its body set to Alignment.center, the Align widget gets centered accounting to the bottomNavigationBar and centers in the remaining space minus that.
How do I get it so that it centers according to the total screen height, using all these widgets?
Stack(
body: Align widget with center alignment and some child,
bottomNavigationBar: Bottom app bar
)
I'm not entirely sure what you mean in your question - but I think you want the body of a Scaffold (not Stack) to center a widget for the whole height available on the device.
Here's how you could do that using a Scaffold, SizedBox and Center widgets along with a MediaQuery
Scaffold(
body: SizedBox(
height: MediaQuery.of(context).size.height,
child: Center(
child: Text("CENTERED")),
),
bottomNavigationBar: BottomNavigationBar(items: []),
)
Scaffold
Sized Box
Center
Media Query
Hopefully that puts you on the right path.

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'),
),

How do I align these widgets?

I am making a practice app in flutter and stuck on this:
How can i align widgets such that;
1. An icon stays at extreme left of appbar
2. Text widget stays in middle.
3. button stays at extreme right of appbar.
here is the image for what i am talking about
use actions property in appbar and then as a child use a row. in that row you can use MainAxisAlignment.spaceBetween or MainAxisAlignment.spaceAround for arranging items.
You can do it using AppBar widget.
Note: If you want to implement drawer then use drawer property.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Title"),
centerTitle: true,
leading: Icon(Icons.menu),
actions: [Icon(Icons.comment)],
),
body: Container(),
);
}
AppBar(title:Text("Your Text),leading:Icon(Icons.menu),actions:[Icon(Icons.favourite)])
Try this code

Transparent overlapping appbar

I'm trying to find a way to have a transparent appbar that overlaps the page content. I know I can use a SliverAppBar to show the appbar initially, and then have it slide out of view when scrolling, which is good. I can even give it a transparent background color. However, when you scroll to the top of the page, it always makes room for the bar to sit above the page content.
What I want is for the page content to be flush with the top of the page, as if there is no appbar, and then have a transparent appbar slide into view like a SliverAppBar does, so that I just have some action buttons overlapping the top of the page.
How can I pull that off? Is there a way to stack the appbar or change margins so it doesn't take space?
You can just put a scaffold and your "page" in a stack(), make sure the scaffold is the last item in the stack. You can get creative an add animations for the app bars yourself or even use the sliver app bar, just make sure you use the same scroll controller for your app bar and content.
eg:
#override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
// Your content
Container(
color: Colors.pink,
),
Scaffold(
appBar: AppBar(
title: Text("heading"),
bottom: AppBar(
title: Text("footer"),
),
),
),
],
);
}

Flutter IphoneX status bar color without app Bar

I have a case where I do not want the app bar in my application , the problem is if I remove the app bar the status bar is coming in default color and there is no property in scaffolding to update status bar color , there is no effect of wrapping Body in safe are or not the status bar always stays
Sample Code
return Scaffold(
body: ListView(
children: <Widget>[
You can change the color of the status bar by making AppBar invisible. With PreferredSize we can set the Height of AppBar to 0 and set the backgroundColor property for status bar color.
appBar: PreferredSize(child: AppBar(
backgroundColor: Colors.red,
elevation: 0.0,
),
preferredSize: Size.fromHeight(0.0)
)
If you don't want to use a scaffold Scaffold, you can change this widget to change the text/icon color of the status bar:
AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light, // or dark
child: <your page>,
)
To change the background color, use a Container or DecoratedBox.
You can get the height of the status bar from MediaQuery.of(context).padding.