Flutter: set appbar custom title height - flutter

In App bar i added search widget like this:
return Scaffold(
appBar: AppBar(
title: Container(
margin: EdgeInsets.only(top: 30),
decoration: BoxDecoration(
color: Color.fromARGB(50, 255, 255, 255),
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: TextFormField(...
)),
),
),
)
],
),
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(100.0),
child: TabBar(...
I added margin from top equal 30 but search section is cropped:
How can i increase default title size in appbar?

You can use flexibleSpace instead of title.
return Scaffold(
appBar: AppBar(
flexibleSpace: Container(....

flexibleSpace works fine but another way is to use PreferredSize.
Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(100.0),
child:AppBar(
title:Text("title"),
)
),
body:...
)

Related

How to make whole screen scrollable in Flutter?

I have an issue with the whole screen scrolling in Flutter. Only the Expanded widget is able to scroll on-screen in my app but I want to make the whole screen scrollable. How can I do that? Here is my code e.g.
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
backgroundColor: Colors.white,
appBar: AppBar(
title: Text(
'My App',
style: AppTheme.of(context).title1,
),
elevation: 0,
backgroundColor: Colors.amber,
),
body: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 20, 10, 0),
child: Column(
. // Padding repeats two more times
.
.
.
Expanded(
child: MyWidget(
myProp1: value1,
myProp2: value2,
myProp3: value3,
myProp4: value4,
myProp5: value5,
myProp6: value6
) // MyWidget
), // Expanded
],
), // Column
); // Scaffold
}
I've tried to wrap Column with SingleChildScrollview widget but it didn't work for me. I guess I can not use Expanded widget in SingleChildScrollview. I also tried to use Container or etc. instead of Expanded and Column widgets but I couldn't solve this issue. Can anybody help me with it?
There is no need to wrap MyWidget with Expanded. Just Change Column into ListView:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text(
'My App',
),
elevation: 0,
backgroundColor: Colors.amber,
),
body: ListView(
children: [
Padding(
padding: EdgeInsetsDirectional.fromSTEB(10, 20, 10, 0),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 500,
decoration: BoxDecoration(color: Colors.black),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 500,
decoration: BoxDecoration(color: Colors.black),
),
)
],
))
],
), // Column
); // Scaffold
}
You also can use the SingleChildScroll view as Child of Expanded widget will work fine

How to resize a flutter table to take the whole available space?

I have a Flutter table that is currently being rendered in the Appbar title as follows:
My question is how to make the table take the maximum width and height of the AppBar?
The codes for defining the table in the Appbar is as follows:
Scaffold(
appBar: AppBar(
title: Table(
border: TableBorder.all(),
children: [
TableRow(
children: <Widget>[
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Center(child: Text("GPS"),),
),
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Center(child: Text("GPS"),),
),
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Center(child: Text("GPS"),),
),
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Center(child: Text("GPS"),),
)
],
)
],
),
))
Below is what I want to achieve:
Firstly, provide height on TableCell,
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Container(
height: kToolbarHeight,
alignment: Alignment.center,
child: Text("GPS"),
),
),
Option 1
You can use leadingWidth: 0,titleSpacing: 0, on AppBar.
AppBar(
leadingWidth: 0,
titleSpacing: 0,
title: myTable(),
),
Option 1 rendering:
Option 2
Also I think you will like using PreferredSize and customize the way you like
appBar: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: Container(
height: kToolbarHeight,
color: Colors.blue,
child: myTable(),
),
),
Option 2 rendering:
If you like to have the border, you can wrap your Table with Padding
title: Padding(
padding: const EdgeInsets.all(1),
child: myTable(),
),

Keep the Content after the AppBar

I in my project am using extendBodyBehindAppBar: true, for when the user scrolls there is a transparency in the AppBar.
But I have a problem with how I can put the content after the AppBar and keep the transparency when I scroll.
Scaffold(
backgroundColor: const Color.fromRGBO(240, 240, 240, 1),
extendBodyBehindAppBar: true,
extendBody: true,
appBar: AppBar(
elevation: 0,
title: const Text(
'O que visitar',
style: TextStyle(
color: Color.fromRGBO(11, 95, 119, 1),
),
),
backgroundColor: const Color.fromRGBO(240, 240, 240, 0.9),
iconTheme: Theme.of(context).primaryIconTheme,
),
drawer: const DrawerWidget(),
body: Container(
child: Padding(
padding: const EdgeInsets.only(left: 20),
child: Column(
children: [
Expanded(
),
],
),
),
),
),
I've already tried the SafeArea works but when scrolling the AppBar has no transparency
If you use extendBodyBehindAppBar, your body takes the whole screen height and body seems to appear behind Appbar. So in this case you can apply padding in top as kToolBarHeight + (your specific top padding)
const EdgeInsets.only(top: kToolBarHeight + 16)

Add a divider on top of a bottom navigation bar?

Is there a way to add a divider like this one to the top of a BottomNavigationBar()? I got it for the AppBar() as you can see below:
appBar: AppBar(
elevation: 0,
title: Text(
_views[_index]['title'],
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(10),
child: Divider(
thickness: 2,
height: 0,
),
),
),
But I wonder if there is a way to do the same with the BottomNavigationBar().
It should look like this in the end:
I just solved it like this:
body: Column(
children: [
_views[_index]['view'],
Spacer(),
Divider(
thickness: 2,
),
],
),
I just added a Divider() inside the body property under the actual content of the Scaffold() and pushed it down with a Spacer().
AppBar has the leading property
Use a colored container inside a PreferredSize widget for the AppBar widget's top
AppBar(
title: Text("Title"),
leading: PreferredSize(
child: Container(color: colors.Black, height: 5.0),
preferredSize: Size.fromHeight(5.0),
),
),

Flutter: increase appBar icon height

I want to put an icon instead of the title for appBar widget but I can't set proper height of this icon.
appBar: PreferredSize(
preferredSize: Size.fromHeight(220.0),
child: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/mobile-phone.png',
fit: BoxFit.contain,
width: 120,
height: 120,
)
],
),
elevation: 0.0,
backgroundColor: Colors.green,
brightness: Brightness.light,
),
),
The icon reaches it's maximum size about 60 (units?) despite that I set the height much more bigger and it's actual size is bigger also.
How to force height setup for the icon in appBar widget?
this should looks like this
appBar: PreferredSize(
preferredSize: Size.fromHeight(220.0),
child: AppBar(
flexibleSpace: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/mobile-phone.png',
fit: BoxFit.contain,
width: 120,
height: 120,
)
],
),
elevation: 0.0,
backgroundColor: Colors.green,
brightness: Brightness.light,
),
),