Drawer footer items
Solution 1
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),
),
),
);
}
}
Solution 2
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'))
],
))),
],
),
),
),
Solution 3
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.
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(),
);
}
}
Swift newbie
Updated on December 22, 2022Comments
-
Swift newbie over 1 year
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 !
-
Guillaume Roux almost 4 yearsIt won't work because Expanded try to take as much space as possible and ListView give it an infinite height.
-
Guillaume Roux almost 4 yearsYour solution is good but it is not fully responsive. Depending on the phone screen size and the number of
ListTile
you can get an overflow. -
Arham Anees almost 2 yearsif we use
ListView
instead ofColumn
insideExpanded
then overlapping issue is resolved.Container(child: Column(children: <Widget>[Expanded(child: ListView(children: <Widget>[/* top widgets*/]),),Align(alignment: FractionalOffset.bottomCenter,child: Column(children: const <Widget>[/* bottom widgets*/]))]))