Align Property is not working in ListView in Flutter - flutter

I want one of my Menu item to be placed at the bottom the Drawer Menu(Specifically Logout, to be at the bottom of the Menu). I'm trying to use Align widget but not able to do so, even I've tried wrapping it inside Expanded widget after watching many solutions but still not able to fix it.
Here is my Code:
drawer: Drawer(
child: Expanded(
child: ListView(
padding: EdgeInsets.all(0.0),
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.black),
accountName: _userName!=null?Text(_userName,):Container(),
accountEmail: _userNumber!=null?Text(_userNumber):Container(),
currentAccountPicture: CircleAvatar(
backgroundColor:
Theme.of(context).platform == TargetPlatform.iOS
? Colors.blue
: Colors.white,
child:_userName!=null? Text(
"${_userName[0]}",
style: TextStyle(fontSize: 40.0,color: Colors.black),
):Container(),
),
),
InkWell(
onTap: (){
print('Home');
Navigator.pop(context);
},
child: ListTile(
title: Text("Home",),
leading: Icon(Icons.home,color: Colors.black,),
),
),
InkWell(
onTap: (){
print('My Orders');
Navigator.push(context, MaterialPageRoute(
builder: (context)=>OrderScreen(Pin:_userPin,Number:_userNumber)
));
},
child: ListTile(
title: Text("My Orders"),
leading: Icon(Icons.fastfood,color: Colors.black,),
),
),
InkWell(
onTap: (){
print('My Address');
},
child: ListTile(
title: Text("My Address"),
leading: Icon(Icons.location_on,color: Colors.black,),
),
),
InkWell(
onTap: (){
print('My Cart');
Navigator.pop(context);
},
child:
ListTile(
title: Text("My Cart"),
leading: Icon(Icons.shopping_cart,color: Colors.black,),
),
),
ListTile(
title: Text("Help"),
leading: Icon(Icons.help,color: Colors.black,),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: ListTile(
title: Text("Logout"), //<-- I want this to be at the bottom.
leading: Icon(Icons.exit_to_app,color: Colors.black,),
),
),
),
],
),
),
),

Just check out this example:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Sample app'),),
drawer: Drawer(
child: Column(
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.black),
accountName: Text('Username'),
accountEmail: Text('UserEmail'),
currentAccountPicture: CircleAvatar(
backgroundColor:
Theme.of(context).platform == TargetPlatform.iOS
? Colors.blue
: Colors.white,
child: Text(
"sample name",
style: TextStyle(fontSize: 10.0, color: Colors.black),
),
),
),
InkWell(
onTap: () {
print('Home');
Navigator.pop(context);
},
child: ListTile(
title: Text(
"Home",
),
leading: Icon(
Icons.home,
color: Colors.black,
),
),
),
InkWell(
onTap: () {
print('My Orders');
/* Navigator.push(context, MaterialPageRoute(
builder: (context)=>OrderScreen(Pin:_userPin,Number:_userNumber)
)); */
},
child: ListTile(
title: Text("My Orders"),
leading: Icon(
Icons.fastfood,
color: Colors.black,
),
),
),
InkWell(
onTap: () {
print('My Address');
},
child: ListTile(
title: Text("My Address"),
leading: Icon(
Icons.location_on,
color: Colors.black,
),
),
),
InkWell(
onTap: () {
print('My Cart');
Navigator.pop(context);
},
child: ListTile(
title: Text("My Cart"),
leading: Icon(
Icons.shopping_cart,
color: Colors.black,
),
),
),
ListTile(
title: Text("Help"),
leading: Icon(
Icons.help,
color: Colors.black,
),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: ListTile(
title:
Text("Logout"), //<-- I want this to be at the bottom.
leading: Icon(
Icons.exit_to_app,
color: Colors.black,
),
),
),
),
],
),
),
body: Text('Sample'),
));
}
}
Change this according to your data and just replace the listview with the Column widget.
And Let me know if it works.

Related

Align drawer list tile at the bottom of the drawer

I've created a drawer for my app.It works fine but Im unable to align the logout button to the bottom of the drawer.Ive tried the align widget,it didnt work.Tried align widget inside an expanded widget,still didnt work.Almost tried everything that I could find.Dont know why it wont align.Please help.
drawer: Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: Align(
alignment: Alignment.topLeft,
child: Container(
child: Column(
children: [
CircleAvatar(
backgroundColor: Colors.yellow,
child: const Text('USER'),
radius: 25,
),
Text(name),
Text(email)
],
),
),
),
),
ListTile(
title: Text("Settings",style:TextStyle(fontWeight: FontWeight.bold),),
trailing: Icon(Icons.settings),
onTap: () {
context.read<NavCubit>().showHome();
Navigator.pop(context);
},
),
Container(
height: 1.0,
width: MediaQuery.of(context).size.width,
color: Colors.tealAccent,
),
ListTile(
title: Text("Learning",style:TextStyle(fontWeight: FontWeight.bold),),
trailing: Icon(Icons.book),
onTap: () {
context.read<NavCubit>().showContracts();
},
),
Container(
height: 1.0,
width: MediaQuery.of(context).size.width,
color: Colors.tealAccent,
),
Align(
alignment: Alignment.bottomCenter,
child: ListTile(
title: Text("Log Out",style:TextStyle(fontWeight: FontWeight.bold),),
trailing: Icon(Icons.logout),
onTap: () {
context.read<NavCubit>().showContracts();
},
),
),
],
),
Refer below code hope it help to you.
drawer: Container(
width: 250,
child: Drawer(
//drawer Code
child: Column(
children: <Widget>[
ListTile(
hoverColor: Colors.blue,
dense: true,
visualDensity: VisualDensity(vertical: -4),
leading: Icon(
Icons.show_chart,
color: Colors.black,
),
title: Text('All Leads'),
onTap: () {},
),
Divider(
color: Colors.grey,
),
ListTile(
hoverColor: Colors.blue,
dense: true,
visualDensity: VisualDensity(vertical: -4),
leading: Icon(
Icons.bar_chart_rounded,
color: Colors.black,
),
title: Text('Graphs'),
onTap: () { },
),
Divider(
color: Colors.grey,
),
ListTile(
hoverColor: Colors.blue,
dense: true,
visualDensity: VisualDensity(vertical: -4),
leading: Icon(
Icons.group,
color: Colors.black,
),
title: Text('Agents'),
onTap: () {},
),
Divider(
color: Colors.grey,
),
ListTile(
hoverColor: Colors.blue,
dense: true,
visualDensity: VisualDensity(vertical: -4),
leading: Icon(
Icons.book,
color: Colors.black,
),
title: Text('About Us'),
onTap: () {},
),
Divider(
color: Colors.grey,
),
Expanded(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: ListTile(
hoverColor: Colors.blue,
dense: true,
visualDensity: VisualDensity(vertical: -4),
leading: Icon(
Icons.logout,
color: Colors.black,
),
title: Text('Logout'),
onTap: () {},
),
),
),
],
),
),
),
Your Drawer Look like this->
drawer: Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: Align(
alignment: Alignment.topLeft,
child: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircleAvatar(
backgroundColor: Colors.yellow,
child: const Text('USER'),
radius: 25,
),
Text(name),
Text(email)
],
),
),
),
),
ListTile(
title: Text("Settings",style:TextStyle(fontWeight: FontWeight.bold),),
trailing: Icon(Icons.settings),
onTap: () {
context.read<NavCubit>().showHome();
Navigator.pop(context);
},
),
Container(
height: 1.0,
width: MediaQuery.of(context).size.width,
color: Colors.tealAccent,
),
ListTile(
title: Text("Learning",style:TextStyle(fontWeight: FontWeight.bold),),
trailing: Icon(Icons.book),
onTap: () {
context.read<NavCubit>().showContracts();
},
),
//code change and use Divider widget for gap/space bw widgets rather than Container
Expanded(
child: Container(
width: MediaQuery.of(context).size.width,
color: Colors.tealAccent,
)
),
ListTile(
title: Text("Log Out",style:TextStyle(fontWeight: FontWeight.bold),),
trailing: Icon(Icons.logout),
onTap: () {
context.read<NavCubit>().showContracts();
},
),
],
),

How can i change to my drawerMenuBar background colors in flutter?

Below is my code, i've been able to change the drawerheader to black, but the when i did color: Colors.grey[800] for the listtiles, only it's area is covered in grey, the remaining extra space is white..
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
Container(
height: 130,
child: DrawerHeader(
child: new Text(
'Hi Bolade',
style: TextStyle(color: Colors.white),
),
decoration: BoxDecoration(
color: Colors.black,
),
),
),
Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.zero,
decoration: BoxDecoration(
color: Colors.grey[800],
),
child: Column(
children: [
ListTile(
leading: Icon(Icons.home),
title: Text('Dashboard'),
onTap: () {},
),
ListTile(
leading: FaIcon(FontAwesomeIcons.tree),
title: Text('Savings'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.trending_up),
title: Text('Investments'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.account_box_sharp),
title: Text('Products'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.wallet_membership),
title: Text('Wallet'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.card_giftcard),
title: Text('Cards & Bank'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.card_giftcard),
title: Text('Share & Earn'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.chat),
title: Text('Support'),
onTap: () {},
),
],
),
),
],
),
),
enter image description here
Image of the current state here below
just wrap your Driver with Theme widget and replace canvasColor
drawer: Theme(
data: Theme.of(context).copyWith(canvasColor: Colors.grey[800]),
child: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
Container(
height: 130,
child: DrawerHeader(
child: Text('Hi Bolade', style: TextStyle(color: Colors.white)),
decoration: BoxDecoration(color: Colors.black),
),
),
Column(
children: [
ListTile(
leading: Icon(Icons.home),
title: Text('Dashboard'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.trending_up),
title: Text('Savings'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.trending_up),
title: Text('Investments'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.account_box_sharp),
title: Text('Products'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.wallet_membership),
title: Text('Wallet'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.card_giftcard),
title: Text('Cards & Bank'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.card_giftcard),
title: Text('Share & Earn'),
onTap: () {},
),
ListTile(
leading: Icon(Icons.chat),
title: Text('Support'),
onTap: () {},
),
],
),
],
),
),
),
also in this case you don't need Container above Column anymore
Keep your listview inside a Container and give a color to this container.
Container(
color: Colors.grey[800]
child: ListView(
....
)
)
I didn't get you question completely .....But I'm guessing that the header is black as expected, but only the tiles are covered in the grey color and the remaining space is white.(the default color).
If this is the case then you can maybe wrap your listview with a container and give it the grey color. By doing this the newly added grey container will act as a background color.
Keep your listview inside a Container and give a color to this container.
Container(
height: MediaQuery.of(context).size.height,
color: Colors.grey[800]
child: ListView(
....
)
)

How can I add background image on sidebar menu with Flutter?

I have following code below I want it to have background for all of them just one image but I couldn't:
drawer: new Drawer(
child: new ListView(
children: <Widget>[
//header
InkWell(
//click özelliği burada back-end sonra yapılacak
onTap:(){},
child: ListTile(
title: Text("Little Sister's Farm"),
leading: Icon(Icons.wb_sunny,color: Colors.orangeAccent),
subtitle: Text('Deneme#gmail.com'),
),
),
// yan tarafta açılan sidebar menü
new UserAccountsDrawerHeader(
accountName: Text('Kullanıcı Adı'),
accountEmail: Text('deneme#gmail.com'),
decoration:
new BoxDecoration(
color: Colors.green,
image: DecorationImage(
image: AssetImage("images/wood.jpg"),
fit: BoxFit.cover)
),
),
// body
InkWell(
//click özelliği burada back-end sonra yapılacak
onTap:(){},
child: ListTile(
title: Text('Kayıt/Giriş'),
leading: Icon(Icons.person_add,color: Colors.blueGrey),
),
),
InkWell(
//click özelliği burada back-end sonra yapılacak
onTap:(){},
child: ListTile(
title: Text('Anasayfa'),
leading: Icon(Icons.home,color: Colors.green),
),
),
InkWell(
onTap:(){},
child: ListTile(
title: Text('Hesabım'),
leading: Icon(Icons.account_box,color: Colors.deepPurple),
),
),
InkWell(
onTap:(){},
child: ListTile(
title: Text('Siparişlerim'),
leading: Icon(Icons.fastfood,color: Colors.tealAccent),
),
),
InkWell(
onTap:(){},
child: ListTile(
title: Text('Kategoriler'),
leading: Icon(Icons.dashboard,color: Colors.orange),
),
),
InkWell(
onTap:(){},
child: ListTile(
title: Text('Favoriler'),
leading: Icon(Icons.favorite,color: Colors.red),
),
),
Divider(),
InkWell(
onTap:(){},
child: ListTile(
title: Text('Ayarlar'),
leading: Icon(Icons.settings,color: Colors.lightBlueAccent),
),
),
InkWell(
onTap:(){},
child: ListTile(
title: Text('Yardım'),
leading: Icon(Icons.help_outline,color: Colors.yellow),
),
),
InkWell(
//click özelliği burada back-end sonra yapılacak
onTap:(){},
child: ListTile(
title: Text('Lokasyon'),
leading: Icon(Icons.location_city,color: Colors.black),
),
),
],
),
),
use Stack() widget and put your background image and drawer items in it.
Drawer(
child: Stack(
children: <Widget>[
Image.asset("your image adress"),
ListView(
children: <Widget>[
// your Drawer Items
],
)
],
),
);

Drawer footer items

i have some little trouble with the drawer , i've searched on stack a solution for this , and found a solution , but after trying it out , it didnt work for me ! :) the idea is , i want to have some items in drawers displayed in the very end of it ! :)
Drawer(
child: Container(
decoration: BoxDecoration(color: Color(0xFF0098c2)),
child: ListView(
children: <Widget>[
ListTile(
title: Text(
'Dealer',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.person,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => dealerBuilder()));
},
),
ListTile(
title: Text(
'Shuffler',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.shuffle,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => shufflerBuilder()));
},
),
ListTile(
title: Text(
'Mistakes',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.info_outline,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => mistakePage()));
},
),
ListTile(
title: Text(
'Important links',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.border_color,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => importantLinks()));
},
),
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Column(
children: <Widget>[
Divider(),
ListTile(
leading: Icon(Icons.settings),
title: Text('Facebook')),
ListTile(
leading: Icon(Icons.help),
title: Text('Instagram'))
],
))),
],
),
),
),
thats the code that i've got in my drawer , so far its displaying this way !
You can copy paste run full code below
You can replace ListView with Column and wrap first group with Expaned Column
child: Column(
children: <Widget>[
Expanded(
child: Column(children: <Widget>[
...
Container(
child: Align(
working demo
full code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
drawer: Drawer(
child: Container(
decoration: BoxDecoration(color: Color(0xFF0098c2)),
child: Column(
children: <Widget>[
Expanded(
child: Column(children: <Widget>[
ListTile(
title: Text(
'Dealer',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.person,
size: 20.0,
color: Colors.white,
),
onTap: () {
/* Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => dealerBuilder()));*/
},
),
ListTile(
title: Text(
'Shuffler',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.shuffle,
size: 20.0,
color: Colors.white,
),
onTap: () {
/*Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => shufflerBuilder()));*/
},
),
ListTile(
title: Text(
'Mistakes',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.info_outline,
size: 20.0,
color: Colors.white,
),
onTap: () {
/* Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => mistakePage()));*/
},
),
ListTile(
title: Text(
'Important links',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.border_color,
size: 20.0,
color: Colors.white,
),
onTap: () {
/*Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => importantLinks()));*/
},
),
]),
),
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Column(
children: <Widget>[
Divider(),
ListTile(
leading: Icon(Icons.settings),
title: Text('Facebook')),
ListTile(
leading: Icon(Icons.help),
title: Text('Instagram'))
],
))),
],
),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}
Try this:
Drawer(
child: Container(
decoration: BoxDecoration(color: Color(0xFF0098c2)),
child: ListView(
children: <Widget>[
ListTile(
title: Text(
'Dealer',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.person,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => dealerBuilder()));
},
),
ListTile(
title: Text(
'Shuffler',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.shuffle,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => shufflerBuilder()));
},
),
ListTile(
title: Text(
'Mistakes',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.info_outline,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => mistakePage()));
},
),
ListTile(
title: Text(
'Important links',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.border_color,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.of(context).push(new MaterialPageRoute(
builder: (context) => importantLinks()));
},
),
Expanded(),
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Column(
children: <Widget>[
Divider(),
ListTile(
leading: Icon(Icons.settings),
title: Text('Facebook')),
ListTile(
leading: Icon(Icons.help),
title: Text('Instagram'))
],
))),
],
),
),
),
Here is a way of doing it
Code:
Scaffold(
appBar: AppBar(),
drawer: Drawer(
child: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: Container(
decoration: BoxDecoration(color: Color(0xFF0098c2)),
child: ConstrainedBox(
constraints: constraints.copyWith(
minHeight: constraints.maxHeight,
maxHeight: double.infinity,
),
child: IntrinsicHeight(
child: SafeArea(
child: Column(
children: [
Column(
children: <Widget>[
// your ListTile here
],
),
Expanded(
child: Align(
alignment: Alignment.bottomLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// your footer widgets here
],
),
),
)
],
),
),
),
),
),
);
},
),
),
body: Container(),
);
By using LayoutBuilder, ConstrainedBox and IntrinsicHeight you are going to be able to use Expanded even inside a ScrollView and keep your image footer at the bottom. It ensure you to have a responsive layout on any phone screen.
Result in image:
Full test code used
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyWidget(),
);
}
}
class MyWidget extends StatefulWidget {
#override
State<StatefulWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
drawer: Drawer(
child: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: Container(
decoration: BoxDecoration(color: Color(0xFF0098c2)),
child: ConstrainedBox(
constraints: constraints.copyWith(
minHeight: constraints.maxHeight,
maxHeight: double.infinity,
),
child: IntrinsicHeight(
child: SafeArea(
child: Column(
children: [
Column(
children: <Widget>[
...List<Widget>.generate(
5,
(index) => ListTile(
title: Text(
"$index",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.person,
size: 20,
color: Colors.white,
),
onTap: () => Navigator.pop(context),
)),
],
),
Expanded(
child: Align(
alignment: Alignment.bottomLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: Icon(Icons.settings),
title: Text('Facebook'),
onTap: () => Navigator.pop(context),
),
ListTile(
leading: Icon(Icons.help),
title: Text('Instagram'),
onTap: () => Navigator.pop(context),
),
],
),
),
)
],
),
),
),
),
),
);
},
),
),
body: Container(),
);
}
}
Expanded on SizedBox works for me!
class CustomDrawer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Drawer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
DrawerHeader(child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
// SizedBox(height: 10,),
Padding(
padding: const EdgeInsets.all(10.0),
child: ProfileAvatar(),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
Text("Syed Tariq Ullah"),
Spacer(),
IconButton(onPressed: (){},
icon:Icon(CupertinoIcons.play_arrow)),
],
),
),
],)),
SizedBox(height: 5.0,),
ListTile(
leading: Icon(CupertinoIcons.chat_bubble_2_fill),
title: Text("Messages"),
),
ListTile(
leading: Icon(CupertinoIcons.chart_bar),
title: Text("Stats"),
),
ListTile(
leading: Icon(CupertinoIcons.briefcase),
title: Text("Your Content"),
),
ListTile(
leading: Icon(CupertinoIcons.bookmark),
title: Text("Bookmarks"),
),
ListTile(
leading: Icon(CupertinoIcons.doc_text),
title: Text("Drafts"),
),
Divider(height: 2.0,),
Expanded(child: SizedBox(height: 20,)),
Align(
alignment: Alignment.bottomCenter,
child: ListTile(leading: Icon(CupertinoIcons.settings_solid),
title: Text("Settings"),
trailing: Icon(CupertinoIcons.ellipsis),
),
),
// Spacer(),
],),
);
}
}
You can use Scaffold. If you want a header that doesn't move, you can set appBar to a PreferredSize widget with the child as DrawerHeader or whatever you want. Set body to ListView for a scrollable list. And set bottomNavigationBar to Container with some height (say 144 for 3 buttons), then the child to a Column widget.
return Drawer(
child: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(144),
child: DrawerHeader(child: Image.asset("")),
),
body: ListView(
children: [
ListTile(
title: const Text("dark mode"),
leading: const Icon(Icons.dark_mode_rounded),
trailing: Switch(
value: true,
onChanged: (value) {},
),
),
ListTile(
title: const Text("metric"),
leading: const Icon(Icons.thermostat_rounded),
trailing: Switch(
value: true,
onChanged: (value) {}
),
),
],
),
bottomNavigationBar: Container(
height: 144,
child: Column(
children: [
ListTile(
title: Text("Settings"),
leading: Icon(Icons.settings_outlined),
onTap: () {},
),
ListTile(
title: Text("Help"),
leading: Icon(Icons.help_outline_outlined),
onTap: () {},
),
ListTile(
title: Text("Log Out"),
leading: Icon(Icons.logout_outlined),
onTap: () {},
),
],
),
)),
);
hey I think I figured out the answer it might help -
you can use a spacer widget that occupies all the streched space spaces

Flutter: Navigation drawer with expansion tile

I`m trying to build a navigation drawer with expansion tile, when i click on the header it collapse and vice versa
but when i set the the drawer header as a child of ExpansionTile, original header padding is lost
Widget _buildDrawer() {
return Drawer(
child: ExpansionTile(
title: UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.deepPurple),
accountName: Text("Mohamed Ali"),
accountEmail: Text("mohamed.ali6996#hotmail.com"),
currentAccountPicture: CircleAvatar(
child: Text("M"),
backgroundColor: Colors.white,
),
),
children: <Widget>[
ListTile(
title: Text("page one"),
trailing: Icon(Icons.android),
onTap: () => _onSelectedItem(0),
),
ListTile(
title: Text("page two"),
trailing: Icon(Icons.accessible),
onTap: () => _onSelectedItem(1),
),
Divider(),
ListTile(
title: Text("Log out"),
trailing: Icon(Icons.exit_to_app),
),
],
initiallyExpanded: false,
)
);
}
The problem is that the header takes the place of the first tile in the ExpansionTile.
One possible solution is to use a Stack and tweak the content with an Align so the expansion icon is at the bottom of the header.
Changing the color of the expanding icon may not work for you. There is a reported issue here for which I have already submitted a PR here. Don't know when it will land in master.
_buildDrawer(BuildContext context) {
ThemeData theme = Theme.of(context);
return Drawer(
child: Stack(
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.indigo),
),
Positioned(
top: 120.0,
left: 0.0,
right: 0.0,
child: Theme(
data: theme.copyWith(
textTheme: theme.textTheme.copyWith(
subhead: theme.textTheme.subhead.copyWith(
color: Colors.grey,
),
),
accentColor: Colors.white,
unselectedWidgetColor: Colors.grey,
iconTheme: theme.iconTheme.copyWith(color: Colors.white),
dividerColor: Colors.transparent,
),
child: ExpansionTile(
title: Align(
heightFactor: 0.4,
alignment: Alignment.bottomCenter,
child: UserAccountsDrawerHeader(
decoration: BoxDecoration(color: Colors.transparent),
accountName: Text("Mohamed Ali"),
accountEmail: Text("mohamed.ali6996#hotmail.com"),
currentAccountPicture: CircleAvatar(
child: Text("M"),
backgroundColor: Colors.white,
),
),
),
children: <Widget>[
ListTile(
title: Text("page one"),
trailing: Icon(Icons.android),
onTap: () => {},
),
ListTile(
title: Text("page two"),
trailing: Icon(Icons.accessible),
onTap: () => {},
),
Container(
height: 1.0,
color: Color(0xFFDDDDDD),
),
ListTile(
title: Text("Log out"),
trailing: Icon(Icons.exit_to_app),
),
],
initiallyExpanded: false,
),
),
),
],
),
)
}