How to open drawer with iconbutton in Flutter? - flutter

Well, I was trying to create my custom appbar but I keep editing my column widget with properties I wanted in my appbar and it worked same as I wanted the appbar(as you can see in image) so I thought I dont need a appbar now. But now I want to implement a drawer which can be access by my iconbutton (which is implemented in top left corner of my widget). Actually drawer is implemented bcoz i can use it with sliding action, but I think its hidden behind my widget! I searched on internet and found some codes but since I dont have deep knowledge of any other programming knowledge so its little hard to understand the syntax for me. How can I access this drawer with my IconButton???
enter image description here
This is my page source code. NOTE: sorry i could not update the upper part of my bcoz i dont know how to format it in stackoverflow so its getting input as text instead of code snippet so I am avoiding it
return Scaffold(
backgroundColor: Colors.white,
drawer: CstmDrawer(),
body: SafeArea(
child: Column(
children: [
Row(
children: [
Container(
height: 150.0,
width: MediaQuery.of(context).size.width * 1.0,
child: Stack(
children: [
Container(
height: 130.0,
width: MediaQuery.of(context).size.width * 1.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.vertical(
bottom: Radius.elliptical(
MediaQuery.of(context).size.width, 100.0),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
Scaffold.of(context).openDrawer(); //I found this code on internet but it gives error "Scaffold.of() called with a context that does not contain a Scaffold."
},
icon: Icon(Icons.menu),
),
Container(
child: Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.notifications_active_outlined)),
IconButton(
onPressed: () {},
icon: Icon(Icons.shopping_cart_outlined)),
],
),
),
],
),
),
Positioned(
bottom: 20.0,
right: MediaQuery.of(context).size.width * 0.07,
child: Container(
height: 40.0,
width: MediaQuery.of(context).size.width * 0.85,
child: Theme(
data: ThemeData(primaryColor: Colors.black),
child: TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(Icons.search),
hintText: "Search Here",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
),
),
),
),
),
],
),
),
],
),
],
),
),
);
Drawer source code.
return Drawer(
elevation: 16.0,
child: Column(
children: [
UserAccountsDrawerHeader(
onDetailsPressed: (){},
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.white,
child: IconButton(
onPressed: (){},
tooltip: "Add Photo",
splashColor: Colors.black,
icon: Icon(
Icons.add_a_photo_rounded,
),
),
),
accountName: Text(
"My Name"
),
accountEmail: Text(
"myemail#gmail.com",
),
),
ListTile(
//tileColor: Colors.green,
onTap: (){},
leading: Icon(Icons.person),
hoverColor: Colors.grey,
title: Text("My Account"),
),
Divider(),
ListTile(
onTap: (){},
leading: Icon(Icons.shopping_cart_outlined),
hoverColor: Colors.grey,
title: Text("Cart"),
),
Divider(),
ListTile(
onTap: (){},
leading: Icon(Icons.storefront_sharp),
hoverColor: Colors.grey,
title: Text("Shop"),
),
Divider(),
ListTile(
onTap: (){},
leading: Icon(Icons.location_on_outlined),
hoverColor: Colors.grey,
title: Text("Map"),
),
Divider(
thickness: 2.0,
),
ListTile(
onTap: (){},
leading: Icon(Icons.settings),
hoverColor: Colors.grey,
title: Text("Settings"),
),
Divider(),
ListTile(
onTap: (){},
leading: Icon(Icons.logout),
hoverColor: Colors.grey,
title: Text("Logout"),
),
],
),
);

The issue is that your context does not contains yet the data from your Scaffold, the workaround you can apply would be to use a GlobalKey to refer to your current ScaffoldState:
class MyWidget extends StatelessWidget {
final _scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
backgroundColor: Colors.white,
drawer: CstmDrawer(),
body: SafeArea(
child: Column(
children: [
Row(
children: [
Container(
height: 150.0,
width: MediaQuery.of(context).size.width * 1.0,
child: Stack(
children: [
Container(
height: 130.0,
width: MediaQuery.of(context).size.width * 1.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.vertical(
bottom: Radius.elliptical(
MediaQuery.of(context).size.width, 100.0),
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
/// Use the _scaffoldKey to call openDrawer()
IconButton(
onPressed: () =>
_scaffoldKey.currentState.openDrawer(),
icon: Icon(Icons.menu),
),
Container(
child: Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.notifications_active_outlined)),
IconButton(
onPressed: () {},
icon: Icon(Icons.shopping_cart_outlined)),
],
),
),
],
),
),
Positioned(
bottom: 20.0,
right: MediaQuery.of(context).size.width * 0.07,
child: Container(
height: 40.0,
width: MediaQuery.of(context).size.width * 0.85,
child: Theme(
data: ThemeData(primaryColor: Colors.black),
child: TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(Icons.search),
hintText: "Search Here",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
),
),
),
),
),
],
),
),
],
),
],
),
),
);
}
}
Here the solution is to use _scaffoldKey to call openDrawer() so instead of doing Scaffold.of(context).openDrawer() you will do _scaffoldKey.currentState.openDrawer(), and do not forget to assign the key to your Scaffold, by doing key: _scaffoldKey.

You can use this I guess!
IconButton(
icon: Icon(Icons.menu),
onPressed: () => Scaffold.of(context).openDrawer()
)

Related

How do I add my app 3 rounded border buttons?

I need to add 3 buttons at the bottom, all buttons need in one row top of the body content
I need to add 3 buttons at the bottom of app
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('WinLife'),
elevation: 10,
backgroundColor: const Color(0XFF82B58D),
leading: Container(
padding: EdgeInsets.all(5),
child: Image.asset('assets/images/logo/WinLife.png'),
),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.favorite,
color: Colors.white,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.settings,
color: Colors.white,
),
onPressed: () {},
)
],
),
body: ListView.builder(
itemBuilder: (BuildContext ctx, int index) {
return Padding(
padding: EdgeInsets.all(10),
child: Card(
shadowColor: const Color(0XFF82B58D),
shape: Border.all(
color: const Color(0XFF82B58D),
width: 2,
),
elevation: 50,
color: const Color(0XFF82B58D),
child: Column(
children: <Widget>[
Image.asset(imgList[index]),
SizedBox(
height: 200,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const <Widget>[
Icon(
Icons.favorite,
color: Colors.white,
size: 25,
),
Icon(
Icons.download,
color: Colors.white,
size: 25,
),
Icon(
Icons.share,
color: Colors.white,
size: 25,
),
],
),
],
),
),
);
},
itemCount: imgList.length,
),
);
}
There is a property called persistentFooterButtons in scaffold widget. It is using to show widgets to the screen footer. you can add any type of widgets inside to that. below some example code with output image FYR
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('WinLife'),
elevation: 10,
backgroundColor: const Color(0XFF82B58D),
leading: Container(
padding: const EdgeInsets.all(5),
child: Image.asset('assets/images/logo/WinLife.png'),
),
actions: <Widget>[
IconButton(
icon: const Icon(
Icons.favorite,
color: Colors.white,
),
onPressed: () {},
),
IconButton(
icon: const Icon(
Icons.settings,
color: Colors.white,
),
onPressed: () {},
)
],
),
body: Container(),
persistentFooterButtons: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
persistentFooterButtonWidget(),
persistentFooterButtonWidget(),
persistentFooterButtonWidget(),
],
),
],
);
}
persistentFooterButtonWidget() {
return OutlinedButton.icon(
label: const Text("Book now", style: TextStyle(color: Colors.black)),
onPressed: () {},
icon: const Icon(Icons.library_add_check_sharp, color: Colors.black, size: 20.0),
style: ButtonStyle(
fixedSize: MaterialStateProperty.all(
const Size(170.0, 40.0),
),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
)),
side: MaterialStateProperty.all(
BorderSide(color: Colors.orange.shade200, width: 2)),
overlayColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.hovered)) {
return Colors.orange.shade200;
}
if (states.contains(MaterialState.pressed)) {
return Colors.orange.shade200;
}
return null; // Defer to the widget's default.
}),
),
);
}

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();
},
),
],
),

Flutter Dart Bottomsheet error context = context

I hope somebody can help me solve this error;
I used this showModalBottomSheet Widget already, and just tried to implement the structure onto a new site. The error I get and just don't understand in the BottomSheet has something to do with " context = context, " . Do I have to iplement the void funktion somwhere else or should I create a new class that is extending the Header class? Can somebody please help me?
class Home extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: ListView(
children: <Widget>[
Header(),
//SelectOption(),
//Chats(),
//MoodsDetector(),
//NextUp(),
//PostFeed(),
],
),
);
}
}
class Header extends StatelessWidget {
const Header({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(25, 50, 50, 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Welcome back,',
style: TextStyle(color: secondColor, fontSize: 20),
),
Text(
'Henri',
style: TextStyle(color: mainColor, fontSize: 30),
),
],
),
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(color: secondColor.withOpacity(0.5), blurRadius: 20),
],
),
child: new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: _showSearch,
),
),
],
),
);
}
void _showSearch(){
showModalBottomSheet(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topRight: Radius.circular(30.0),topLeft: Radius.circular(30.0))
),
isScrollControlled: true,
isDismissible: true,
context: context,
builder: (builder) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
SingleChildScrollView(
padding: const EdgeInsets.all(15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Card(
elevation: 8.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.green,
child: ListTile(
onTap: () {
//open edit profile
},
title: Text(
"Rate your Friendship",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
leading: CircleAvatar(
backgroundImage: AssetImage("assets/images/HenriKlein.jpeg"),
),
trailing: Icon(
Icons.star,
color: Colors.white,
),
),
),
const SizedBox(height:10.0),
Card(
elevation: 4.0,
margin: const EdgeInsets.fromLTRB(32.0, 8.0, 32.0, 16.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Column(
children: <Widget>[
ListTile(
leading: Icon(
Icons.people_outline,
color: Colors.lightGreen,
),
title: Text("Invite to event"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
},
),
sizedBox,
ListTile(
leading: Icon(
Icons.directions_run,
color: Colors.lightGreen,
),
title: Text("Challange Henri"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {},
),
sizedBox,
ListTile(
leading: Icon(
Icons.phone_iphone,
color: Colors.lightGreen,
),
title: Text("Text/Call Henri"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () { },
),
sizedBox,
ListTile(
leading: Icon(
Icons.lock_outline,
color: Colors.lightGreen,
),
title: Text("Delete Friend"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {},
),
],
),
),
const SizedBox(height: 5.0),
Center(
child: Text(
"Friens since 09/20/2019",
style: TextStyle(
fontSize: 15.0,
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 40.0,
child: GestureDetector(
onTap: () {
},
child: Material(
borderRadius: BorderRadius.circular(50.0),
shadowColor: Colors.black,
color: Colors.green,
elevation: 7.0,
child: Center(
child: Text(
'27 mutural friends', //Login Button
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat'),
),
),
),
),
),
],
),
),
],
),
],
),
);
});
}
}
You are getting the error because context is not defined in _showSearch.
You should modify the function definition and add context as a parameter as follows:
void _showSearch(BuildContext context) {
...
And when you are calling, you must pass context of the widget from where you are calling it, as follows:
child: new IconButton(
icon: new Icon(Icons.search),
highlightColor: Colors.pink,
onPressed: () {
_showSearch(context); //here
},
),

How to show a Container fixed at bottom of screen without using bottom navigation bar in Flutter?

In my flutter project, I have a container with some icons and text below them. I want this entire container to be fixed at bottom of the screen without using bottom navigation bar like the below image-
So, I need an entire example to fix that container at bottom and keep my other components inside body with a scroll view.
Ok,
Here you go....
return Scaffold(
appBar: AppBar(
title: Text("Header"),
),
body: Column(
children: <Widget>[
Expanded(
child: Container(
alignment: Alignment.center,
child: Text("Hello"),
),
),
Container(
height: 50,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
],
),
)
],
),
);
If you want to make a scrollable item/listview in the body section and want a fixed bottom container you can follow this code given below :
important note : Make sure wrap the listview with Expanded
import 'package:flutter/material.dart';
class ShoppingCart extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
),
actions: <Widget>[
GestureDetector(
onTap: () {
//your code
},
child: Padding(
padding: const EdgeInsets.only(right: 15.0),
child: Icon(
Icons.delete_outline_sharp,
color: Colors.black,
size: 30,
),
)),
//Add more icon here
],
elevation: 0,
centerTitle: false,
title:
Text("Shopping Cart", style: TextStyle(color: Colors.black))),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: shoppingCartItems.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(
top: 15.0, left: 12.0, right: 12.0),
child: Container(
decoration: BoxDecoration(
// color: Color(0xffF3F3F3),
color: Colors.red,
shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
height: 120,
width: 360,
),
);
},
),
),
Container(
height: 150,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange[200],
borderRadius:
BorderRadius.vertical(top: Radius.circular(20.0))),
)
],
));
}
}
Update :
This is built in now. You can use bottomNavigationBar and customize is as below :
bottomNavigationBar: BottomAppBar(
child: Container(
height: //set your height here
width: double.maxFinite, //set your width here
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){
//on Presses functionaluty goes here
},),
//add as many tabs as you want here
],
),
),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 50.0,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
],
),
),
),

How to implement a bottom navigation drawer in Flutter

I'm trying to implement a bottom navigation drawer, similar to the one used in the Reply Material Study, that is an extension of the bottom app bar, and opened and closed via an icon button in the bottom app bar.
I've tried bottom sheets, but that replaces, or hovers on top of, the bottom app bar. I want it to look like the one in the screenshot where the bottom app bar stays on the screen and the bottom navigation drawer slides up when the "menu" button is tapped.
The Material Design site shows this as a component, but doesn't link off to anywhere showing how to implement it in Flutter.
I quickly made it, but you are going to have to implement active page text/icon colors to the listview. Also, the full code is here if you want to copy from the gist.
class ScreenOne extends StatefulWidget {
#override
_ScreenOneState createState() => _ScreenOneState();
}
class _ScreenOneState extends State<ScreenOne> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Reply demo"),
),
bottomNavigationBar: BottomAppBar(
elevation: 0,
color: Color(0xff344955),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
height: 56.0,
child: Row(children: <Widget>[
IconButton(
onPressed: showMenu,
icon: Icon(Icons.menu),
color: Colors.white,
),
Spacer(),
IconButton(
onPressed: () {},
icon: Icon(Icons.add),
color: Colors.white,
)
]),
),
),
);
}
showMenu() {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
),
color: Color(0xff232f34),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
height: 36,
),
SizedBox(
height: (56 * 6).toDouble(),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
),
color: Color(0xff344955),
),
child: Stack(
alignment: Alignment(0, 0),
overflow: Overflow.visible,
children: <Widget>[
Positioned(
top: -36,
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
border: Border.all(
color: Color(0xff232f34), width: 10)),
child: Center(
child: ClipOval(
child: Image.network(
"https://i.stack.imgur.com/S11YG.jpg?s=64&g=1",
fit: BoxFit.cover,
height: 36,
width: 36,
),
),
),
),
),
Positioned(
child: ListView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ListTile(
title: Text(
"Inbox",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.inbox,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Starred",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.star_border,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Sent",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.send,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Trash",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.delete_outline,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Spam",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.error,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Drafts",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.mail_outline,
color: Colors.white,
),
onTap: () {},
),
],
),
)
],
))),
Container(
height: 56,
color: Color(0xff4a6572),
)
],
),
);
});
}
}
You can use BottomSheet . (Thanks to westdabestdb)
Working on flutter_gallery demo app:
class ModalBottomSheetDemo extends StatelessWidget {
static const String routeName = '/material/modal-bottom-sheet';
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Modal bottom sheet'),
actions: <Widget>[MaterialDemoDocumentationButton(routeName)],
),
body: Center(
child: RaisedButton(
child: const Text('SHOW BOTTOM SHEET'),
onPressed: () {
showModalBottomSheet<void>(context: context, builder: (BuildContext context) {
return Container(
child: Padding(
padding: const EdgeInsets.all(32.0),
child: Text('This is the modal bottom sheet. Tap anywhere to dismiss.',
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 24.0
)
)
)
);
});
}
)
)
);
}
}
Building up on westdabestdb's answer and this article:
If you want a bottom navigation drawer that is not blocking, with rounded corners and that is not depending on a black background, try this:
class GoogleMapsHomeUI extends StatelessWidget {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
showBottomDrawer();
return Scaffold(
key: scaffoldKey, // use the key to reference the Scaffold from outside
... the rest of your background Scaffold
);
}
void showBottomDrawer() {
// the next line is needed, because the Scaffold needs to be finished before this function continues.
WidgetsBinding.instance.addPostFrameCallback((_) {
PersistentBottomSheetController? bottomSheetController = scaffoldKey.currentState?.showBottomSheet((BuildContext context) {
return Container(
height: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.only( // makes the round corners
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
),
color: Color(0xff232f34),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
height: 36,
),
SizedBox(
height: (56 * 6).toDouble(),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.0),
topRight: Radius.circular(16.0),
),
color: Color(0xff344955),
),
child: Stack(
alignment: Alignment(0, 0),
children: <Widget>[
Positioned(
top: -36,
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(50)),
border: Border.all(
color: Color(0xff232f34), width: 10)),
child: Center(
child: ClipOval(
child: Image.network(
"https://i.stack.imgur.com/S11YG.jpg?s=64&g=1",
fit: BoxFit.cover,
height: 36,
width: 36,
),
),
),
),
),
Positioned(
child: ListView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ListTile(
title: Text(
"Inbox",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.inbox,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Starred",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.star_border,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Sent",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.send,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Trash",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.delete_outline,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Spam",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.error,
color: Colors.white,
),
onTap: () {},
),
ListTile(
title: Text(
"Drafts",
style: TextStyle(color: Colors.white),
),
leading: Icon(
Icons.mail_outline,
color: Colors.white,
),
onTap: () {},
),
],
),
)
],
))),
Container(
height: 56,
color: Color(0xff4a6572),
)
],
),
),
),
); // Container
},
backgroundColor: Colors.black,
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0)),
), clipBehavior: null,
enableDrag: true,
);
result (I'm not finished with the background yet, but you can interact with the background, while the drawer is open):