How to create a vertical scrolling menu effect in Flutter - flutter

this question is an improvement for this question. In this case, I would like to reproduce the vertical menu the you can see on the left side of this we base. If you click the link relative to the example on the left you see a number of menu. For instance, clicking on Base you are going to see a vertical menu appearing and disappearing. I would like to know how to reproduce it as well. An example code would be really appreciated.
Thanks all

You can achieve this by simply using a StatefulWidget & managing the hide/show functionality using a boolean value.
Here is the updated code:
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatefulWidget {
#override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget>
with SingleTickerProviderStateMixin {
final colors = <Color>[Colors.indigo, Colors.blue, Colors.orange, Colors.red];
double _size = 250.0;
bool _large = true;
void _updateSize() {
setState(() {
_size = _large ? 250.0 : 0.0;
_large = !_large;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
AnimatedSize(
curve: Curves.easeIn,
vsync: this,
duration: Duration(seconds: 1),
child: LeftDrawer(size: _size)),
Expanded(
flex: 4,
child: Container(
child: Column(
children: [
Container(
color: Colors.white,
padding: const EdgeInsets.all(8),
child: Row(
children: [
IconButton(
icon: Icon(Icons.menu, color: Colors.black87),
onPressed: () {
_updateSize();
},
),
FlatButton(
child: Text(
'Dashboard',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
FlatButton(
child: Text(
'User',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
FlatButton(
child: Text(
'Settings',
style: const TextStyle(color: Colors.black87),
),
onPressed: () {},
),
const Spacer(),
IconButton(
icon: Icon(Icons.brightness_3, color: Colors.black87),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.notification_important,
color: Colors.black87),
onPressed: () {},
),
CircleAvatar(),
],
),
),
Container(
height: 1,
color: Colors.black12,
),
Card(
margin: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0),
),
child: Container(
color: Colors.white,
padding: const EdgeInsets.all(20),
child: Row(
children: [
Text(
'Home / Admin / Dashboard',
style: const TextStyle(color: Colors.black),
),
],
),
),
),
Expanded(
child: ListView(
children: [
Row(
children: [
_container(0),
_container(1),
_container(2),
_container(3),
],
),
Container(
height: 400,
color: Color(0xFFE7E7E7),
padding: const EdgeInsets.all(16),
child: Card(
color: Colors.white,
child: Container(
padding: const EdgeInsets.all(16),
child: Text(
'Traffic',
style: const TextStyle(color: Colors.black87),
),
),
),
),
],
),
),
],
),
),
),
],
),
);
}
Widget _container(int index) {
return Expanded(
child: Container(
padding: const EdgeInsets.all(20),
color: Color(0xFFE7E7E7),
child: Card(
color: Color(0xFFE7E7E7),
child: Container(
color: colors[index],
width: 250,
height: 140,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Text(
'9.823',
style: TextStyle(fontSize: 24),
)),
Icon(Icons.more_vert),
],
),
Text('Members online')
],
),
),
),
),
);
}
}
class LeftDrawer extends StatefulWidget {
LeftDrawer({
Key key,
this.size,
}) : super(key: key);
final double size;
#override
_LeftDrawerState createState() => _LeftDrawerState();
}
class _LeftDrawerState extends State<LeftDrawer> {
bool dropdownVisible = false;
#override
Widget build(BuildContext context) {
return Expanded(
flex: 1,
child: Container(
width: widget.size,
color: const Color(0xFF2C3C56),
child: ListView(
children: [
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(16),
color: Color(0xFF223047),
child: Text('CORE UI'),
),
_tile('Dashboard'),
Container(
padding: const EdgeInsets.only(left: 10),
margin: const EdgeInsets.only(top: 30),
child: Text('THEME',
style: TextStyle(
color: Colors.white54,
))),
_tile('Colors'),
_tile('Typography'),
_tileDropdown('Base'),
_tile('Buttons'),
],
),
),
);
}
Widget _tile(String label) {
return ListTile(
title: Text(label),
onTap: () {},
);
}
Widget _option(String label) {
return ListTile(
tileColor: Color(0xFF223047),
contentPadding: const EdgeInsets.only(left: 40),
title: Text(label),
onTap: () {},
);
}
Widget _tileDropdown(String label) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: Text(label),
onTap: () {
setState(() {
dropdownVisible = !dropdownVisible;
});
},
trailing: dropdownVisible
? Icon(Icons.arrow_drop_up)
: Icon(Icons.chevron_left),
),
Visibility(
visible: dropdownVisible,
child: _option('Breadcrumbs'),
),
Visibility(
visible: dropdownVisible,
child: _option('Cloud'),
),
Visibility(
visible: dropdownVisible,
child: _option('Carousel'),
),
Visibility(
visible: dropdownVisible,
child: _option('Collapse'),
),
],
);
}
}

Related

flutter showPicker not displayed

I have a chip widget. I have added an InkWell to have OnTap.
But, when OnTap call the class ShowPickerUnit, the ShowPicker is not displayed.
I have tried stateless, void, widget and I am getting the same result.
I just want the user to be able to select between several values.
I do not understand what I am missing. Please, can you help?
Thank you.
Widget chipGoal (){
return Row(
children: [
Wrap(
// space between chips
spacing: 10,
// list of chips
children: [
InkWell(
child: Chip(
label: Text('Working'),
avatar: Icon(
Icons.work,
color: Colors.red,
),
backgroundColor: Colors.amberAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
onTap: (){
ShowPickerUnit();
},
),
Chip(
label: Text('Music'),
avatar: Icon(Icons.headphones),
backgroundColor: Colors.lightBlueAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
Chip(
label: Text('Music'),
avatar: Icon(Icons.headphones),
backgroundColor: Colors.lightBlueAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
]),
],
);
}
class ShowPickerUnit extends StatefulWidget {
const ShowPickerUnit({Key key}) : super(key: key);
#override
_ShowPickerUnitState createState() => _ShowPickerUnitState();
}
class _ShowPickerUnitState extends State<ShowPickerUnit> {
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
decoration: BoxDecoration(
color: Color(0xffffffff),
border: Border(
bottom: BorderSide(
color: Color(0xff999999),
width: 0.0,
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CupertinoButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 5.0,
),
),
DefaultTextStyle(
style: TextStyle(fontSize: 16.0,
color: Colors.black,
fontWeight: FontWeight.bold),
child: Text('Select what you want'),
),
// Text('Energy Needed', style: TextStyle(fontSize: 12.0, color: Colors.black),
// ),
CupertinoButton(
child: Text('Confirm'),
onPressed: () {
setState(() {
});
Navigator.of(context).pop();
},
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 5.0,
),
),
],
),
),
Container(
//width: 360,
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
child:
CupertinoPicker(
children: [
Text("India"),
Text("Usa"),
Text("Uk"),
Text("Australia"),
Text("Africa"),
Text("New zealand"),
Text("Germany"),
Text("Italy"),
Text("Russia"),
Text("China"),
],
onSelectedItemChanged: (value){
},
itemExtent: 25,
)
)]
);
} }
If you want to show it in a dialog, use this showDialog
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return chipGoal();
}
}
Widget chipGoal() {
return Builder(
builder: (BuildContext context) {
return Row(
children: [
Wrap(
// space between chips
spacing: 10,
// list of chips
children: [
InkWell(
child: Chip(
label: Text('Working'),
avatar: Icon(
Icons.work,
color: Colors.red,
),
backgroundColor: Colors.amberAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return ShowPickerUnit();
},
);
},
),
Chip(
label: Text('Music'),
avatar: Icon(Icons.headphones),
backgroundColor: Colors.lightBlueAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
Chip(
label: Text('Music'),
avatar: Icon(Icons.headphones),
backgroundColor: Colors.lightBlueAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
]),
],
);
},
);
}
class ShowPickerUnit extends StatefulWidget {
const ShowPickerUnit({Key? key}) : super(key: key);
#override
_ShowPickerUnitState createState() => _ShowPickerUnitState();
}
class _ShowPickerUnitState extends State<ShowPickerUnit> {
#override
Widget build(BuildContext context) {
return Column(mainAxisAlignment: MainAxisAlignment.end, children: [
Container(
decoration: BoxDecoration(
color: Color(0xffffffff),
border: Border(
bottom: BorderSide(
color: Color(0xff999999),
width: 0.0,
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CupertinoButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 5.0,
),
),
DefaultTextStyle(
style: TextStyle(
fontSize: 16.0,
color: Colors.black,
fontWeight: FontWeight.bold),
child: Text('Select what you want'),
),
// Text('Energy Needed', style: TextStyle(fontSize: 12.0, color: Colors.black),
// ),
CupertinoButton(
child: Text('Confirm'),
onPressed: () {
setState(() {});
Navigator.of(context).pop();
},
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 5.0,
),
),
],
),
),
Container(
//width: 360,
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
child: CupertinoPicker(
children: [
Text("India"),
Text("Usa"),
Text("Uk"),
Text("Australia"),
Text("Africa"),
Text("New zealand"),
Text("Germany"),
Text("Italy"),
Text("Russia"),
Text("China"),
],
onSelectedItemChanged: (value) {},
itemExtent: 25,
))
]);
}
}
It shows the dialog when you tap on "Working"
Use showModalBottomSheet for data selection
Widget chipGoal (){
return Row(
children: [
Wrap(
// space between chips
spacing: 10,
// list of chips
children: [
InkWell(
child: Chip(
label: Text('Working'),
avatar: Icon(
Icons.work,
color: Colors.red,
),
backgroundColor: Colors.amberAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
onTap: (){
showModalBottomSheet<void>(
// context and builder are
// required properties in this widget
context: context,
builder: (BuildContext context) {
return ShowPickerUnit();
},
);
},
),
Chip(
label: Text('Music'),
avatar: Icon(Icons.headphones),
backgroundColor: Colors.lightBlueAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
Chip(
label: Text('Music'),
avatar: Icon(Icons.headphones),
backgroundColor: Colors.lightBlueAccent,
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10),
),
]),
],
);
}
class ShowPickerUnit extends StatefulWidget {
const ShowPickerUnit({Key? key}) : super(key: key);
#override
_ShowPickerUnitState createState() => _ShowPickerUnitState();
}
class _ShowPickerUnitState extends State<ShowPickerUnit> {
#override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
decoration: BoxDecoration(
color: Color(0xffffffff),
border: Border(
bottom: BorderSide(
color: Color(0xff999999),
width: 0.0,
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CupertinoButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 5.0,
),
),
DefaultTextStyle(
style: TextStyle(fontSize: 16.0,
color: Colors.black,
fontWeight: FontWeight.bold),
child: Text('Select what you want'),
),
// Text('Energy Needed', style: TextStyle(fontSize: 12.0, color: Colors.black),
// ),
CupertinoButton(
child: Text('Confirm'),
onPressed: () {
setState(() {
});
Navigator.of(context).pop();
},
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 5.0,
),
),
],
),
),
Expanded(
child: Container(
//width: 360,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
child:
CupertinoPicker(
children: [
Text("India"),
Text("Usa"),
Text("Uk"),
Text("Australia"),
Text("Africa"),
Text("New zealand"),
Text("Germany"),
Text("Italy"),
Text("Russia"),
Text("China"),
],
onSelectedItemChanged: (value){
},
itemExtent: 25,
)
),
)]
);
} }

when I am running this code on a small device is overflowing flutter

This code is overflowing in the small devices in a flutter.
I want to make this screen responsive.
I am posting because it's not been solved past 8 days
Below is my main.dart
import 'package:flutter/material.dart';
import 'package:mop_n_maid/utils/route_name.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
const themeColor = Color(0xFF353E58);
class OnboardingPage extends StatefulWidget {
const OnboardingPage({Key? key}) : super(key: key);
#override
_OnboardingPageState createState() => _OnboardingPageState();
}
class _OnboardingPageState extends State<OnboardingPage> {
final controller = PageController();
bool isLastPage = true;
void dispose() {
controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.only(bottom: 80),
child: PageView(
controller: controller,
onPageChanged: (index) {
setState(() => isLastPage = index == 3);
},
children: [
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/Helping.jpg',
title: 'What do you look for when hiring a maid?',
),
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/verified.jpg',
title: 'Are your domestic helper verified?',
),
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/changeplan.jpg',
title: 'Changed plans because your maid coming late?',
),
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/Solution.jpg',
title: 'All Solutions at one stop!',
),
],
),
),
bottomSheet: isLastPage
? TextButton(
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: themeColor,
minimumSize: Size.fromHeight(80),
),
onPressed: () {
Navigator.pushReplacementNamed(context, MyRoutes.loginRoute);
},
child: const Text(
'Get Started',
style: TextStyle(fontSize: 24),
),
)
: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
height: 80,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
controller.jumpToPage(3);
},
child: Text(
'SKIP',
style: TextStyle(color: themeColor),
),
),
Center(
child: SmoothPageIndicator(
controller: controller,
count: 4,
effect: WormEffect(
spacing: 16,
dotColor: Colors.black26,
activeDotColor: themeColor,
),
onDotClicked: (index) => controller.animateToPage(
index,
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
),
),
),
TextButton(
onPressed: () {
controller.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.easeInOut);
},
child: Text(
'NEXT',
style: TextStyle(
color: themeColor,
),
),
),
],
),
),
);
}
}
Widget buildPage({
required Color color,
required String urlImage,
required String title,
}) {
return Container(
color: color,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 400,
child: Image.asset(
urlImage,
fit: BoxFit.cover,
width: double.infinity,
),
),
const SizedBox(
height: 64,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Text(
title,
style: TextStyle(
color: themeColor,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
],
),
);
}
This image is showing my problem in detail
Try this
Widget buildPage({
required Color color,
required String urlImage,
required String title,
}) {
return Container(
color: color,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.4,
child: Image.asset(
urlImage,
fit: BoxFit.cover,
width: double.infinity,
),
),
const SizedBox(
height: 64,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Expanded(
Text(
title,
style: TextStyle(
color: themeColor,
fontSize: 25,
fontWeight: FontWeight.bold,
)),
),
),
],
),
);
}`enter code here`

onPressed widget does not working,when ever i click on any view it does not show any splash action,in flutter

i want to apply onTap or onpressed widget to below listview items and icons. please help me to sort out this problem. onPressed widget does not working, when ever I click on any view item it does not show any splash action, what to do please help me.i want to apply onTap or onpressed widget to below listview items and icons. please help me to sort out this problem. onPressed widget does not working, when ever I click on any view item it does not show any splash action, what to do please help me.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'screen_two.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Screens",
theme: ThemeData(primarySwatch: Colors.red),
home: LocationApp(),
);
}
}
class LocationApp extends StatefulWidget {
#override
_LocationAppState createState() => _LocationAppState();
}
class _LocationAppState extends State<LocationApp> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
maxWidth: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black54.withOpacity(0.1),
offset: Offset(15.0, 20.0),
blurRadius: 20.0,
)
],
color: Colors.red.withOpacity(0.8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Expanded(
flex: 4,
child: Padding(
padding: const EdgeInsets.only(left: 131.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 70.0, bottom: 30.0),
child: Container(
width: 130.0,
height: 130.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/she.png'),
fit: BoxFit.fill,
),
borderRadius:
BorderRadius.all(Radius.circular(100.0)),
border: Border.all(
color: Colors.white,
width: 4.0,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
"Alisa",
style: TextStyle(fontSize: 30.0, color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"22 want | 35 done",
style: TextStyle(fontSize: 17.0, color: Colors.white),
),
),
],
),
),
),
Expanded(
flex: 4,
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
children: [
CustomTile(
Icon(
Icons.chat_bubble_outline,
color: Colors.orangeAccent,
),
"Order",
() => {},
),
CustomTile(
Icon(
Icons.trip_origin_outlined,
color: Colors.pink,
),
"Like",
() => {},
),
CustomTile(
Icon(
Icons.star,
color: Colors.orange,
),
"Comment",
() {},
),
CustomTile(
Icon(
Icons.android_rounded,
color: Colors.pink,
),
"Download",
() => {},
),
CustomTile(
Icon(
Icons.zoom_out_sharp,
color: Colors.green,
),
"Edit",
() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Secondscreen()));
},
),
],
),
),
Container(
height: 70,
color: Colors.black26.withOpacity(0.1),
),
Padding(
padding: const EdgeInsets.only(
top: 0.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.add_chart,
),
onPressed: () {
setState(() {});
},
),
Text('TIPS',
style: TextStyle(
color: Colors.orange, fontSize: 10)),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
tooltip: '',
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.person,
color: Colors.red),
onPressed: () {},
tooltip: '',
),
Text('Profile',
style: TextStyle(
color: Colors.red, fontSize: 10)),
],
)
],
),
)
],
),
),
)
],
),
),
),
);
}
}
class CustomTile extends StatelessWidget {
Icon icon;
String text;
Function onTap;
CustomTile(this.icon, this.text, this.onTap);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.orangeAccent,
onTap: onTap,
child: Container(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
icon,
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
text,
style: TextStyle(fontSize: 16.0),
),
)
],
),
Icon(Icons.arrow_right)
],
),
),
),
),
);
}
}
//class CustomTile extends StatelessWidget {
// Icon icon;
// String text;
// Function onTap;
// String news;
//
// CustomTile(this.icon, this.text, this.onTap, this.news);
//
// #override
// Widget build(BuildContext context) {
// return Container(
// decoration: BoxDecoration(
// border:
// Border(bottom: BorderSide(color: Colors.grey.withOpacity(0.4)))),
// child: InkWell(
// splashColor: Colors.orangeAccent,
// onTap: onTap,
// child: Container(
// height: 50,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: <Widget>[
// Row(
// children: <Widget>[
// icon,
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: Text(
// text,
// style: TextStyle(fontSize: 16.0),
// ),
// )
// ],
// ),
// Padding(
// padding: const EdgeInsets.only(left: 240.0),
// child: Text(
// news,
// style: TextStyle(fontSize: 17, color: Colors.red),
// ),
// ),
// Icon(Icons.chevron_right)
// ],
// ),
// ),
// ),
// );
// }
//}
According to the documentation of the Inkwell widget, an ancestor of this widget must be Material widget. By adding Material as a parent widget of your CustomTile, it will show you the colors. I also changed the onTap attribute to ()=>onTap() so that your function is triggered.
This code should work like you want:
class CustomTile extends StatelessWidget {
Icon icon;
String text;
Function onTap;
CustomTile(this.icon, this.text, this.onTap);
#override
Widget build(BuildContext context) {
return Material(
child: Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade400))),
child: InkWell(
splashColor: Colors.orangeAccent,
onTap: ()=>onTap(),
child: Container(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
icon,
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
text,
style: TextStyle(fontSize: 16.0),
),
)
],
),
Icon(Icons.arrow_right)
],
),
),
),
),
),
);
}
}
The InkWell in your CustomTitle class must have a Material ancestor to cause ink reactions. So do something like this:
class CustomTile extends StatelessWidget {
final Icon icon;
final String text;
final void Function() onTap;
CustomTile(this.icon, this.text, this.onTap);
#override
Widget build(BuildContext context) {
return Material(child:
Padding(
padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
child: Container(...
See InkWell class docs

icon on pressed function isnt working,whenever i click on any icon,i want to show any action there,what to do?

please help me. when ever I clicked on home icon it does not show any action however I applied on pressed function. icon on pressed function is not working, whenever I click on any icon, I want to show any action there, what to do???. I want to show any action there, what to do???. I want to show any action there, what to do???
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'screen_two.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Screens",
theme: ThemeData(primarySwatch: Colors.red),
home: LocationApp(),
);
}
}
class LocationApp extends StatefulWidget {
#override
_LocationAppState createState() => _LocationAppState();
}
class _LocationAppState extends State<LocationApp> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
maxWidth: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black54.withOpacity(0.1),
offset: Offset(15.0, 20.0),
blurRadius: 20.0,
)
],
color: Colors.red.withOpacity(0.8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Expanded(
flex: 4,
child: Padding(
padding: const EdgeInsets.only(left: 131.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 70.0, bottom: 30.0),
child: Container(
width: 130.0,
height: 130.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/she.png'),
fit: BoxFit.fill,
),
borderRadius:
BorderRadius.all(Radius.circular(100.0)),
border: Border.all(
color: Colors.white,
width: 4.0,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
"Alisa",
style: TextStyle(fontSize: 30.0, color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"22 want | 35 done",
style: TextStyle(fontSize: 17.0, color: Colors.white),
),
),
],
),
),
),
Expanded(
flex: 4,
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
children: [
CustomTile(
Icon(
Icons.chat_bubble_outline,
color: Colors.orangeAccent,
),
"Order",
() => {},
""),
CustomTile(
Icon(
Icons.trip_origin_outlined,
color: Colors.pink,
),
"Like",
() => {},
"new"),
CustomTile(
Icon(
Icons.star,
color: Colors.orange,
),
"Comment",
() {},
""),
CustomTile(
Icon(
Icons.android_rounded,
color: Colors.pink,
),
"Download",
() => {},
""),
CustomTile(
Icon(
Icons.zoom_out_sharp,
color: Colors.green,
),
"Edit", () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Secondscreen()));
}, ""),
],
),
),
Container(
height: 70,
color: Colors.black26.withOpacity(0.1),
),
Padding(
padding: const EdgeInsets.only(
top: 0.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.add_chart,
),
onPressed: () {},
),
Text('TIPS',
style: TextStyle(
color: Colors.orange, fontSize: 10)),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
onPressed: () {
Scaffold.of(context).openDrawer();
print('Menu Icon pressed');
},
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.person,
color: Colors.red),
onPressed: () {},
tooltip: '',
),
Text('Profile',
style: TextStyle(
color: Colors.red, fontSize: 10)),
],
)
],
),
)
],
),
),
)
],
),
),
),
);
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'screen_two.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Screens",
theme: ThemeData(primarySwatch: Colors.red),
home: LocationApp(),
);
}
}
class LocationApp extends StatefulWidget {
#override
_LocationAppState createState() => _LocationAppState();
}
class _LocationAppState extends State<LocationApp> {
#override
Widget build(BuildContext context) {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
return Scaffold(
key:_scaffoldKey,
body: SingleChildScrollView(
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
maxWidth: MediaQuery.of(context).size.width,
),
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black54.withOpacity(0.1),
offset: Offset(15.0, 20.0),
blurRadius: 20.0,
)
],
color: Colors.red.withOpacity(0.8),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
Expanded(
flex: 4,
child: Padding(
padding: const EdgeInsets.only(left: 131.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 70.0, bottom: 30.0),
child: Container(
width: 130.0,
height: 130.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/she.png'),
fit: BoxFit.fill,
),
borderRadius:
BorderRadius.all(Radius.circular(100.0)),
border: Border.all(
color: Colors.white,
width: 4.0,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
"Alisa",
style: TextStyle(fontSize: 30.0, color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
"22 want | 35 done",
style: TextStyle(fontSize: 17.0, color: Colors.white),
),
),
],
),
),
),
Expanded(
flex: 4,
child: Container(
decoration: BoxDecoration(color: Colors.white),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
children: [
CustomTile(
Icon(
Icons.chat_bubble_outline,
color: Colors.orangeAccent,
),
"Order",
() => {},
""),
CustomTile(
Icon(
Icons.trip_origin_outlined,
color: Colors.pink,
),
"Like",
() => {},
"new"),
CustomTile(
Icon(
Icons.star,
color: Colors.orange,
),
"Comment",
() {},
""),
CustomTile(
Icon(
Icons.android_rounded,
color: Colors.pink,
),
"Download",
() => {},
""),
CustomTile(
Icon(
Icons.zoom_out_sharp,
color: Colors.green,
),
"Edit", () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Secondscreen()));
}, ""),
],
),
),
Container(
height: 70,
color: Colors.black26.withOpacity(0.1),
),
Padding(
padding: const EdgeInsets.only(
top: 0.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.add_chart,
),
onPressed: () {},
),
Text('TIPS',
style: TextStyle(
color: Colors.orange, fontSize: 10)),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
onPressed: () {
_scaffoldKey.currentState.openDrawer(),
),print('Menu Icon pressed');
},
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.person,
color: Colors.red),
onPressed: () {},
tooltip: '',
),
Text('Profile',
style: TextStyle(
color: Colors.red, fontSize: 10)),
],
)
],
),
)
],
),
),
)
],
),
),
),
);
}
}
Add a scaffold key
Then use the key to open the drawer
First, check if your print msg print on the terminal or log while pressing on IconButton
Like this code,
IconButton(
iconSize: 25.0,
icon: const Icon(Icons.home),
onPressed: () {
print('Menu Icon pressed');
},
),
The below code will help you to Open drawer,
declare and define scaffold key then also define drawer,
I hope the below code will help you, keep Fluttering :)
import 'package:flutter/material.dart';
class OpenDrawer extends StatefulWidget {
const OpenDrawer({Key key}) : super(key: key);
#override
_OpenDrawerState createState() => _OpenDrawerState();
}
class _OpenDrawerState extends State<OpenDrawer> {
GlobalKey<ScaffoldState> globalKey = GlobalKey();
#override
Widget build(BuildContext context) {
return Scaffold(
key: globalKey,
drawer: Drawer(child: YourDrawerWidget()),
body: Column(
children: [
IconButton(
iconSize: 25.0,
icon: const Icon(
Icons.home,
),
onPressed: () {
globalKey.currentState.openDrawer();
print('Menu Icon pressed');
},
),
Text(
'Home',
style: TextStyle(fontSize: 10),
),
],
),
);
}
}

How to align the icon left and text middle in a Raised button in flutter?

I have a button with an icon and a text where both of them aligned in the middle,i want the icon to be in the left and the text of the button to be in the middle. can someone look into it and help me with how to do it.
Here's My code:
Widget _signInButton() {
return ButtonTheme(
height: 30,
minWidth: 250,
child: RaisedButton(
color: Colors.white,
splashColor: Colors.grey,
onPressed: () {
signInWithGoogle().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return FirstScreen();
},
),
);
});
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
// borderSide: BorderSide(color: Colors.grey),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage("Assets/google_logo.png"), height: 35.0),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
'Sign in with Google',
style: TextStyle(
fontSize: 15,
color: Colors.black87,
You can copy paste run full code below
You can use Expanded flex 1 for image, Expanded flex 2 for text
code snippet
Expanded(
flex: 1,
child: Image(
image: AssetImage("Assets/google_logo.png"),
height: 35.0),
),
Expanded(
flex: 2,
child: Padding(
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,
),
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 Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_signInButton(),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Widget _signInButton() {
return ButtonTheme(
height: 30,
minWidth: 250,
child: RaisedButton(
color: Colors.white,
splashColor: Colors.grey,
onPressed: () {
/*signInWithGoogle().whenComplete(() {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return FirstScreen();
},
),
);
});*/
},
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
highlightElevation: 0,
// borderSide: BorderSide(color: Colors.grey),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
flex: 1,
child: Image(
image: AssetImage("Assets/google_logo.png"),
height: 35.0),
),
Expanded(
flex: 2,
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Text('Sign in with Google',
style: TextStyle(
fontSize: 15, color: Colors.black87))))
]))));
}
In my case I had the same situation. I tried this way and it worked for me.
Inside your button child widget paste the Row widget portion.
Here is the code:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
....
Row(
children: <Widget>[
Expanded(
flex: 1,
child: Align(
alignment: Alignment.centerLeft,
child: IconButton(
onPressed: () { //do whatever you want},
icon: const Icon(
Icons.clear,
),
),
),
),
Expanded(
flex: 2,
child: Text(
'Your Button Text',
),
)
],
)
)