Flutter remove space above AppBar for iOS - flutter

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(
// ...
)
),

Related

CircleAvatar() size is not changing inside the appBar

So am trying to display circular user image in the home page of an application the image position is at the top left of the screen, after searching and trying i managed to use this approach:
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(100.0),
child: AppBar(
backgroundColor: Colors.purple,
elevation: 0,
leading: CircleAvatar(
radius: 10,
backgroundColor: Colors.black,
backgroundImage: AssetImage('assets/DefaultImage.png'),
),
),
),
);
the image is displayed fine but i want to increase the size of it and "radius" is not working at all, i tried to wrap the avatar with container to add some margins but also didn't work.
my questions are :
1- how to increase the size of CircleAvatar() inside an AppBar().
2- is CircleAvatar() the right choice for user profile image especially if this image was retrieved from firestore?
leading is controlled by leadingWidth and toolbarHeight. You can increase the size to have more space.
child: AppBar(
backgroundColor: Colors.purple,
elevation: 0,
toolbarHeight: 100, //this
leadingWidth: 100, //this
leading: CircleAvatar(
radius: 60,
backgroundColor: Colors.black,
),
),

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?

how we can use two rows in appbar flutter Like first row with title and the second with search input field

Hi There I am working on a app where i need to use two sections in appbar one upper
1->section with logo and some Icons
2-> Search input field below the Title Section.
UI images are attached for better understanding.
you can customize the size of app bar by using toolbarHeight: 120.0 // set value
then use flexibleSpace to add column or rows
it will look something like this
import 'package:flutter/material.dart';
void main() => runApp(App());
class App extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
toolbarHeight: 120.10, //set your height
flexibleSpace: SafeArea(
child: Container(
color: Colors.blue, // set your color
child: Column(
children: [
Row(
children: [Text("Logo")],
),
Text("data"), // set an icon or image
IconButton(
icon: Icon(Icons.search),
onPressed: () {}) // set your search bar setting
],
),
),
),
),
),
);
}
}
Just simply create your AppBar as intended, in your screenshot, you don't actually need a second Row. A TextFormField will be enough (you will actually need to customise the InputDecoration as well):
return AppBar(
title: Column(children: [
Row(children: [
Icon(Icons.menu),
Text('First row'),
const Spacer(),
Icon(Icons.person),
]),
TextFormField(),
]),
);
You can use the bottom property from the AppBar widget.
AppBar(
title: YourFirstRowWidget(),
centerTitle: true,
bottom: PreferredSize(
child: YourSearchBarWidget(),
preferredSize: null),
)
But you may want to create your own AppBar widget for a perfect result.

Can I increase height of app bar in 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'),
),
),

How to replace title with image in AppBar

How can I replace the AppBar title with image logo in Flutter?
The title property takes a Widget, so you can pass any widget to it.
For example, an image added to assets
Scaffold(
appBar: AppBar(
title: Image.asset('assets/title.png', fit: BoxFit.cover),
),
body: ...
)
More info
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/logo.png',
fit: BoxFit.contain,
height: 32,
),
Container(
padding: const EdgeInsets.all(8.0), child: Text('YourAppTitle'))
],
),
)
App themes are probably best long term. (Make sure you've properly added the logo image to your assets folder and updated 'pubspec.yaml' file too).
Create a folder (e.g. 'themes') in your /lib path.
Create a "style" file (e.g. 'style.dart') in that folder. (Use this file also to implement different themes for your app: colors, fonts, etc.)
Create an image widget in your 'style' file, e.g. (height, weight, path, alignment up to you):
Image appLogo = new Image(
image: new ExactAssetImage("assets/images/AppLogo.png"),
height: 28.0,
width: 20.0,
alignment: FractionalOffset.center);
In the title field of your AppBar, add 'appLogo' (or whatever you
named the widget), like this (don't forget to import your 'style' file):
child: Scaffold(
appBar: AppBar(
title: appLogo,
),
Now, if ever you need to change this logo, you simply need to edit your style.dart file with the new image path and that's it. And if you have different themes and name your widgets the same way in each style file, you'll also be able to rapidly implement different styles (e.g. 'style1', 'style2', etc.) on the fly just by importing the respective file in just a couple places.
The problem is that the AppBar does not fit it Height with the image size. To solve this problem, i've set the image and the AppBar Height (including the padding)
Here's my code:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Image.asset(
"assets/images/logo_light.png",
fit: BoxFit.contain,
height: 72,
),
toolbarHeight: 88,
actions: [
IconButton(onPressed: () => {}, icon: Icon(Icons.search)),
],
),
);
AppBar(
centerTitle: true,
title: Image.asset('assets/your_logo.png', height: 32),
backgroundColor: Theme.of(context).primaryColor,
)
the above didn't quite work for me, this adds the picture background I want to the entire app bar and leaves the option to keep a title. updated for flutter/dart 2.0 null safety
Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
title: Text('App Bar!'),
flexibleSpace: Image(
image: AssetImage('images/bar1.jpg'),
fit: BoxFit.cover,
),
backgroundColor: Colors.transparent,
),
body: Container()
)