Drawer footer items - flutter

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

Related

How to remove children background color from ExpansionTile title on animation?

This is my code:
class Temp extends StatefulWidget {
const Temp({Key? key}) : super(key: key);
#override
State<Temp> createState() => _TempState();
}
// stores ExpansionPanel state information
class Item {
Item(bool exp) {
this.isExpanded = exp;
}
late bool isExpanded;
}
List<Item> items = [Item(false), Item(true), Item(true), Item(false)];
class _TempState extends State<Temp> {
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 4,
child: Scaffold(
body: SingleChildScrollView(
child: Container(
child: ExpansionPanelList(
expandedHeaderPadding: EdgeInsets.zero,
expansionCallback: (int index, bool isExpanded) {
setState(() {
items[index].isExpanded = !isExpanded;
});
},
children: [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text("Test", style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
leading: Icon(Icons.info),
minLeadingWidth : 4,
contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
dense:true,
);
},
body: Column(
children: [
ListTile(
title: Text("Test 1", style: TextStyle(fontSize: 16)),
leading: Icon(Icons.handshake_outlined),
minLeadingWidth : 4,
contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
dense:true,
),
ExpansionTile(
title: const Text('Test 2', style: TextStyle(color: Colors.black87),),
leading: Icon(Icons.handshake_outlined, color: Colors.black54,),
trailing: Column(),
children: <Widget>[
ListTile(
dense: true,
tileColor: Color(0xffffeed4),
title: Text('Foo', style: TextStyle (fontSize: 16),),
trailing: SizedBox(
child: Text("foo", style: TextStyle (fontSize: 16),)
),
),
ListTile(
tileColor: Color(0xffffeed4),
title: Text('Bar', style: TextStyle (fontSize: 16),),
dense: true,
trailing: SizedBox(
child: Text("bar", style: TextStyle (fontSize: 16),)
),
),
Container(
height: 10,
color: Color(0xffffeed4),
),
Container(
color: Color(0xffffeed4),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.indigo,
shape: CircleBorder(),
),
child: Icon(
Icons.copy,
color: Colors.white,
),
onPressed: () {},
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.indigo,
shape: CircleBorder(),
),
child: Icon(
Icons.delete_rounded,
color: Colors.white,
),
onPressed: () {},
),
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.indigo,
shape: CircleBorder(),
),
child: Icon(
Icons.info_outline,
color: Colors.white,
),
onPressed: () {},
),
],
),
),
Container(
height: 10,
color: Color(0xffffeed4),
)
],
onExpansionChanged: (bool expanded) {
//setState(() => _customTileExpanded = expanded);
},
),
],
),
isExpanded: items[1].isExpanded,
canTapOnHeader: true
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: null,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
)
);
}
}
And this is the result:
As you see when I click on ExpansionTile title/header then children background is visible not only on this ExpansionTile title/header (Test 2) but also on the previous one (Test 1). As a result it is rather ugly. I don't want children background color be visible on ExpansionTile title/header. Could anyone say how to do it?
It is a bug in flutter. Issue is here

Could not find method android() for arguments [build_1ebi9fgddm6fztg1dwfx76c67$_run_closure2#3e3a1649] on project ':app' of type org.gradle.api.Projec

my build.gradel
It is giving me this error.
** FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\Kamal\Documents\qr_final\android\app\build.gradle' line: 24
What went wrong:
A problem occurred evaluating project ':app'.
Could not find method android() for arguments [build_1ebi9fgddm6fztg1dwfx76c67$_run_closure2#3e3a1649] on project ':app' of type org.gradle.api.Project.
**
import 'package:flutter/services.dart';
import 'package:scan_qr_easily/page/qr_create_page.dart';
import 'package:scan_qr_easily/page/qr_scan_page.dart';
import 'package:scan_qr_easily/widget/button_widget.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
static final String title = 'QR CODE SCANNER';
#override
Widget build(BuildContext context) => MaterialApp(
debugShowCheckedModeBanner: false,
title: title,
theme: ThemeData(
primaryColor: Colors.blue,
scaffoldBackgroundColor: Colors.white,
),
home: MainPage(title: title),
);
}
class MainPage extends StatefulWidget {
final String title;
const MainPage({
required this.title,
});
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
#override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Stack(
children: [
Align(
alignment: Alignment.topLeft,
child: Builder(
builder: (context) => IconButton(
icon: Image.asset(
"assets/icon.png",
height: 30,
width: 44,
),
onPressed: () => Scaffold.of(context).openDrawer(),
),
),
),
Center(
child: Align(
alignment: Alignment.topCenter,
child: Text(
widget.title,
style: TextStyle(fontSize: 25.0),
)))
],
),
centerTitle: true,
titleSpacing: 0,
),
drawer: Drawer(
elevation: 10,
child: Container(
decoration: BoxDecoration(color: Colors.blue),
child: Column(
children: <Widget>[
Expanded(
child: Column(children: <Widget>[
SizedBox(
height: 70,
),
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
image: new DecorationImage(
image: AssetImage("assets/qr2.jpeg"),
fit: BoxFit.cover)),
),
ListTile(
title: Text(
'Create QR Code',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.qr_code,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRCreatePage(),
));
},
),
ListTile(
title: Text(
'Scan QR Code',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
leading: Icon(
Icons.qr_code_scanner_rounded,
size: 20.0,
color: Colors.white,
),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRScanPage(),
));
},
),
ListTile(
title: InkWell(
child: Text(
'About Developer',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
onTap: () => launch('https://github.com/kamal614'),
),
leading: Icon(
Icons.people,
size: 20.0,
color: Colors.white,
),
),
ListTile(
title: InkWell(
child: Text(
'Connect on LinkedIn',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
onTap: () =>
launch('https://www.linkedin.com/in/kamal614/'),
),
leading: Icon(
Icons.add,
size: 20.0,
color: Colors.white,
),
),
]),
),
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Column(
children: <Widget>[
Divider(),
Center(
child: new InkWell(
child: new Text(
"This app is open source and the Source code can be found at GitHub",
style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
onTap: () => launch(
'https://github.com/kamal614/Scan-QR-Bar-code-Easily'),
),
),
],
))),
],
),
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Image.asset(
"assets/qr.gif",
height: 250.0,
width: 250.0,
),
SizedBox(
height: 20.0,
),
Text(
"What do you want to do today?",
style: TextStyle(fontSize: 20.0, color: Colors.black),
),
SizedBox(
height: 30.0,
),
ButtonWidget(
text: 'Create QR Code',
onClicked: () => Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRCreatePage(),
)),
),
const SizedBox(height: 20),
ButtonWidget(
text: 'Scan QR Code',
onClicked: () => Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => QRScanPage(),
)),
),
],
),
),
);
}

How to change the whole background color of Drawer in Flutter

first of all i'm new to flutter and so i am quite confused how to change the "whole" background color in drawer flutter.
i managed to change my ListTile and my so called DrawerHeader to the color i want but the rest (below the ListTile is all white). And there is a line below the DrawerHeader that i don't really want but i can't get rid of it.
here is the code
import 'package:flutter/material.dart';
import '../style/theme.dart' as style;
class MyDrawer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
// width: MediaQuery.of(context).,
child: Drawer(
elevation: 0,
child: ListView(
children: <Widget>[
Container(
height: 170,
width: 170,
padding: EdgeInsets.only(top:30),
color: style.Colors.secondColor,
child: Column(children: <Widget>[
Material(
borderRadius: BorderRadius.all(Radius.circular(100)),
child: Padding(padding: EdgeInsets.all(20.0),
child: Image.asset('images/circle.png',width: 80, height: 80,),),
//TODO ganti logo
),
],),
),
Container(
color: style.Colors.secondColor,
child: Column(
children: <Widget>[
ListTile(
leading: Icon(Icons.help_outline_sharp),
title: Text('Help', style: TextStyle(fontSize: 18,),),
onTap: () {},
),
ListTile(
leading: Icon(Icons.person),
title: Text('About us', style: TextStyle(fontSize: 18,),),
onTap: () {},
),
],
),
),
],
),
),
);
}
}
here is the photo of the current situation
Here is the photo
Another Question
what if i want to put a single ListTile on the bottom? (like log out)
For changing the background color of drawer you can just swap the Drawer Widget with Container and give color to container
class MyDrawer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Drawer(
elevation: 0,
child: Container(
color: Colors.blue,
child: ListView(
children: <Widget>[
Container(
height: 170,
width: 170,
padding: EdgeInsets.only(top:30),
color: Colors.red,
child: Column(children: <Widget>[
Material(
borderRadius: BorderRadius.all(Radius.circular(100)),
child: Padding(padding: EdgeInsets.all(20.0),
child: Image.asset('images/circle.png',width: 80, height: 80,),),
),
],),
),
Container(
color: Colors.red,
child: Column(
children: <Widget>[
ListTile(
leading: Icon(Icons.help_outline_sharp),
title: Text('Help', style: TextStyle(fontSize: 18,),),
onTap: () {},
),
ListTile(
leading: Icon(Icons.person),
title: Text('About us', style: TextStyle(fontSize: 18,),),
onTap: () {},
),
],
),
),
],
),
),
);
}
}
This can be the final code you can use, it has answer to all your three questions
class MyDrawer extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Drawer(
child: Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
Container(
height: 170,
width: 170,
padding: EdgeInsets.only(top:30),
color: Colors.blue,
child: Column(children: <Widget>[
Material(
borderRadius: BorderRadius.all(Radius.circular(100)),
child: Padding(padding: EdgeInsets.all(20.0),
child: Image.asset('images/circle.png',width: 80, height: 80,),),
),
],
),
),
ListTile(
leading: Icon(Icons.help_outline_sharp),
title: Text('Help', style: TextStyle(fontSize: 18,),),
onTap: () {},
),
ListTile(
leading: Icon(Icons.person),
title: Text('About us', style: TextStyle(fontSize: 18,),),
onTap: () {},
),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: ListTile(
leading: Icon(Icons.logout),
title: Text('Logout')
),
),
],
),
);
}
}
To change the color, wrap the Drawer widget in a Theme widget as follows:
Scaffold(
drawer:Theme(
data:Theme.of(context).copyWith(
canvasColor://the desired color will go here
),
child:Drawer(/*drawer content*/)
)
)
Hope this is useful for someone

Align Property is not working in ListView in 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.

passing data from screen to drawer flutter

I want to display the data i have in my dashboard screen to my drawer. My dashboard screen received data from a previous page and i want to pass some of that data to my drawer.
Here is my dashboardscreen
class DashboardScreen extends StatefulWidget {
final AuthUser user;
DashboardScreen({Key key, this.user}) : super(key: key);
#override
_DashboardScreenState createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
floatingActionButton: buildSpeedDial(),
drawer: CollapsibleDrawer(),
backgroundColor: Color(0xffeee9f1),
body: Container(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
ClipPath(
clipper: DashboardClipper(),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Color(0xff6f3682).withOpacity(.8),
Color(0xff9f44d3).withOpacity(.53),
], begin: Alignment.bottomCenter, end: Alignment.topCenter)),
height: 48 * SizeConfig.heightMultiplier,
),
),
Positioned(
top: 40.0,
child: Container(
padding: EdgeInsets.only(left: 15.0, right: 15.0),
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.format_align_left,
color: Colors.white),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
},
),
Text(
'My Account',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700),
),
Column(
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.brown.shade800,
child: Text('AH'),
),
],
)
]),
)),
]
)
)
)]
};
My drawer is a stateful widget that looks like this
return Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: Container(
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
CustomPaint(
painter: CurvePainter(),
child: DrawerHeader(
child: Row(
children: <Widget>[
CircleAvatar(
radius: 40,
// backgroundImage: AssetImage('assets/images/person.jpg'),
),
SizedBox(
width: 20,
),
Text(
'',
style: textStyle,
)
],
),
),
),
Column(children: <Widget>[]),
ListTile(
title: Text(
'About Us',
style: textStyleTile,
),
trailing: Icon(
Icons.wrap_text,
color: Colors.black,
),
onTap: () {},
),
ListTile(
title: Text(
'SOS',
style: textStyleTile,
),
trailing: Icon(
Icons.help,
color: Colors.black,
),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text(
'Share',
style: textStyleTile,
),
trailing: Icon(
Icons.share,
color: Colors.black,
),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text(
'Settings',
style: textStyleTile,
),
trailing: Icon(
Icons.settings,
color: Colors.black,
),
onTap: () {
// Update the state of the app.
// ...
},
),
SizedBox(
height: MediaQuery.of(context).size.height / 11,
),
Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
onTap: () => print('tapped'),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Logout',
style: textStyleTile,
),
Icon(
Icons.settings_power,
color: Colors.black,
)
],
),
),
)
],
),
),
);
The opendrawer is opening the drawer from the dashboard screen. How can i display data from my dashboard inside my drawer?
Pass the data to the CollapsibleDrawer constructor. The same as how data is passed to DashboardScreen's constructor.
Change
drawer: CollapsibleDrawer(),
to
drawer: CollapsibleDrawer(user: this.user),