CircleAvatar() size is not changing inside the appBar - flutter

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

Related

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

Flutter 3 Transparent AppBar with transparent shadowColor is still visible

I'm trying to make a screen layout with a transparent AppBar that has to scroll content under it.
The problem is that when content is scrolled, the AppBar shows a shadow, shadowColor, but it is set to transparent color.
EDIT: I noticed that the cause of this is having useMaterial3 set to true in my App Theme.
I'm using Flutter 3.0.2.
This is my code:
Stack(
fit: StackFit.expand,
children: [
//AuthBackground(),
Container(color: Colors.brown,),
Theme(
data: AppStyles.mainDarkTheme.copyWith(
textTheme: AppStyles.mainDarkTheme.textTheme.apply(
bodyColor: Colors.blue,
displayColor: Colors.blue,
)
),
child: Scaffold(
backgroundColor: Colors.transparent,
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
elevation: 0.0,
bottomOpacity: 0.0,
),
body: _content(),
),
),
],
)
Here you have a pic where you can notice the shadow on AppBar when content is scrolled:
Thanks in advance!
Finally I got it.
I answered myself on this post:
I had same problem.
In my case i had an AppBar with transparent background and a Scaffold
with extendBodyBehindAppBar set to true.
I tried with shadowColor and surfaceTintColor with Colors.transparent
value, but the shadow was still visible.
Then I noticed the scrolledUnderElevation property of AppBar. Setting
it to 0.0 was the solution.
Set elevation = 0 works for me
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
This is because the default elevation property is set to appbar. so the simple solution is to set the elevation property. like below
elevation: 0,
it's done.

How do I get a SliverAppBar with this effect?

This is an example of the header in the Grailed App, there's a title in the top left, and when the page is scrolled down the title shows in the top centre:
This is what I have so far:
class AccountPageHeader extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SliverAppBar(
backgroundColor: kMainBG,
expandedHeight: 90,
toolbarHeight: 50,
pinned: true,
elevation: 0,
automaticallyImplyLeading: false,
flexibleSpace: FlexibleSpaceBar(
centerTitle: false,
title: Text(
"Account",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.w800),
),
titlePadding: EdgeInsets.all(kDefaultPadding),
),
actions: [],
);
}
}
My title is in the flexible space and just sort of transitions on to the top left whe scrolled down on the page.
If anyone could lead me to the right place on how to achieve the app bar on the Grailed example I would appreciate it! TYIA!
We can get this effect using CupertinoSliverNavigationBar.
CupertinoSliverNavigationBar(
largeTitle: Text("Account"),
),

Flutter web vertical tab navigation

How to create vertical tab navigation for dashboard in flutter web and whats it the best way?
You can you a NavigationRail to get this look. It was added to flutter this year. It works almost like the bottom tab bar.
I believe you want something similiar to what is shown in the screenshot right?
If so, I would recommend you to use the Scaffold Widget and making use of the attributes appBar and drawer.
For further information about the Scaffold Widget please check this link.
Here a simple example:
In your main Widget modify the build function like this.
#override
Widget build(BuildContext context) {
GlobalKey<ScaffoldState> key = GlobalKey();
return Scaffold(
key: key,
drawer: Padding(
padding: const EdgeInsets.fromLTRB(0, 70, 0, 0),
child: Container(
color: Colors.red,
width: 300,
child: Column(children: [Text("1"), Text("2"), Text("3")])),
),
appBar: AppBar(
toolbarHeight: 70,
elevation: 5,
centerTitle: true,
backgroundColor: Colors.black,
leading: RawMaterialButton(
child: Icon(Icons.menu),
onPressed: () => key.currentState.openDrawer(),
),
title: Container(child: Text("Title Widget")),
),
body: Container(
child: Text("Main Widget"),
));
}
The result would look like this:

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()
)