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,
)
),
)]
);
} }
Related
I am making an app with flutter and in my application I made an hidden drawer by putting 2 pages in a Stack widget and when I click on the menu icon, the homepage gets an offset and the drawer screen becomes visible. On the drawerscreen I have 2 selfmade buttons which are supposede to lead you to another page.
My drawer in my homepage is setup with an AnimatedContainer>Listview>Column>Container as in the code below.
import 'package:flutter/material.dart';
import 'package:paws_up/components/buttons/animated_button.dart';
import 'package:paws_up/components/buttons/category_button.dart';
import 'package:paws_up/pages/product_overview_page.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
#override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
double xOffset = 0;
double yOffset = 0;
double scaleFactor = 1;
bool isDrawerOpen = false;
#override
Widget build(BuildContext context) {
return AnimatedContainer(
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(40)),
duration: const Duration(milliseconds: 250),
transform: Matrix4.translationValues(xOffset, yOffset, 0)
..scale(scaleFactor),
child: ListView(
children: [
Column(
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 20,
),
height: 70,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
isDrawerOpen
? IconButton(
onPressed: () {
setState(() {
xOffset = 0;
yOffset = 0;
scaleFactor = 1;
isDrawerOpen = false;
});
},
icon: const Icon(
Icons.chevron_left_rounded,
color: Color.fromARGB(255, 0, 0, 0),
),
)
: IconButton(
onPressed: () {
setState(() {
xOffset = 230;
yOffset = 150;
scaleFactor = 0.6;
isDrawerOpen = true;
});
},
icon: const Icon(
Icons.menu,
color: Color.fromARGB(255, 0, 0, 0),
),
),
const Text(
'PawsUp',
style: TextStyle(
color: Color(0xff363636),
fontFamily: 'Ubuntu',
fontWeight: FontWeight.bold,
fontSize: 24),
),
Row(
children: [
IconButton(
icon: const Icon(Icons.notifications_outlined,
color: Color(0xff363636)),
onPressed: () {
// do something
},
),
IconButton(
icon: const Icon(Icons.person_outline_rounded,
color: Color(0xff363636)),
onPressed: () {
// do something
},
),
],
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 30,
horizontal: 20,
),
decoration: BoxDecoration(
color: const Color.fromARGB(255, 247, 247, 247),
borderRadius: BorderRadius.circular(8)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
IconButton(
icon: const Icon(FontAwesomeIcons.filter,
color: Color(0xff5891AC)),
onPressed: () {},
),
const Text(
'Search..',
style: TextStyle(
color: Color(0xffCAC9C9),
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 16),
),
],
),
Container(
decoration: BoxDecoration(
color: const Color(0xff5891AC),
borderRadius: BorderRadius.circular(8),
),
child: IconButton(
onPressed: () {},
icon: const Icon(
FontAwesomeIcons.magnifyingGlass,
color: Colors.white,
),
),
),
],
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20),
height: 140,
decoration: BoxDecoration(
color: const Color(0xffD5E5F4),
borderRadius: BorderRadius.circular(15.0),
),
child: Stack(
children: [
Positioned(
top: 50,
left: 135,
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(0),
bottomLeft: Radius.circular(0),
bottomRight: Radius.circular(15)),
child: Image.asset(
'images/Banner_photo.jpg',
height: 90.0,
width: 190.0,
fit: BoxFit.cover,
),
),
),
Positioned(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.fromLTRB(15, 8, 0, 8),
child: Text(
'Join our animal loving community',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(15, 0, 0, 0),
child: AnimatedButton(
height: 40,
width: 100,
text: 'Join Now',
textColor: const Color(0xffD5E5F4),
buttonColor: Colors.white,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const ProductOverviewPage()),
);
},
),
),
],
),
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 30,
horizontal: 20,
),
child: Column(
children: [
Row(
children: [
const Text(
'Pet Categories',
style: TextStyle(
color: Color(0xff363636),
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
const Spacer(),
TextButton(
onPressed: () {},
child: const Text(
'More Categroies',
style: TextStyle(
color: Color(0xff5891AC), fontFamily: 'Ubuntu'),
),
),
],
),
SizedBox(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
children: const [
CategoryButton(
text: 'Cat',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.cat,
),
CategoryButton(
text: 'Dog',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.dog,
),
CategoryButton(
text: 'Fish',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.fish,
),
CategoryButton(
text: 'Bird',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.dove,
),
],
),
)
],
),
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 30,
horizontal: 20,
),
child: Column(
children: [
Row(
children: [
const Text(
'Adopt Us',
style: TextStyle(
color: Color(0xff363636),
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
const Spacer(),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const ProductOverviewPage()),
);
},
child: const Text(
'See All',
style: TextStyle(
color: Color(0xff5891AC), fontFamily: 'Ubuntu'),
),
),
],
),
SizedBox(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
children: const [],
),
)
],
),
),
],
),
],
),
);
}
}
The drawerScreen code is as follows:
import 'package:flutter/material.dart';
import 'package:paws_up/components/buttons/drawer_button.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:paws_up/pages/home_page.dart';
import 'package:paws_up/pages/product_overview_page.dart';
class DrawerScreen extends StatefulWidget {
const DrawerScreen({super.key});
#override
State<DrawerScreen> createState() => _DrawerScreenState();
}
class _DrawerScreenState extends State<DrawerScreen> {
#override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: Color(0xffD5E5F4),
),
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: const EdgeInsets.symmetric(
vertical: 20,
horizontal: 20,
),
child: Row(
children: [
const CircleAvatar(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'Firstname Lastname',
style: TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.bold,
fontSize: 20),
),
Text(
'Location',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontSize: 16),
)
],
),
)
],
),
),
Container(
child: Column(
children: [
DrawerButton(
text: 'Home',
icon: Icons.home,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomeScreen()),
);
},
),
DrawerButton(
text: 'Adopt',
icon: FontAwesomeIcons.paw,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProductOverviewPage()),
);
},
),
// DrawerButton(
// text: 'Donate',
// icon: FontAwesomeIcons.circleDollarToSlot,
// ),
// DrawerButton(
// text: 'Favorites',
// icon: FontAwesomeIcons.solidHeart,
// ),
// DrawerButton(
// text: 'Messages',
// icon: FontAwesomeIcons.solidEnvelope,
// ),
// DrawerButton(
// text: 'Profile',
// icon: FontAwesomeIcons.solidUser,
// ),
],
),
),
Container(
padding: const EdgeInsets.fromLTRB(0, 20, 0, 70),
child: Row(
children: [
// DrawerButton(
// text: 'Settings',
// icon: FontAwesomeIcons.gear,
// ),
// DrawerButton(
// text: 'Log in',
// icon: FontAwesomeIcons.arrowRightToBracket,
// ),
],
),
)
],
),
),
);
}
}
I think the problem lies in the DrawerButton. It is supposed to lead you to different pages but it doesn't. This is my DrawerButton code:
import 'package:flutter/material.dart';
class DrawerButton extends StatefulWidget {
final String text;
final IconData icon;
DrawerButton({
super.key,
required this.text,
required this.icon,
required Null Function() onTap,
});
#override
_DrawerButtonState createState() => _DrawerButtonState();
}
class _DrawerButtonState extends State<DrawerButton>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late double _scale;
#override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
lowerBound: 0.0,
upperBound: 0.1,
)..addListener(() {
setState(() {});
});
}
#override
Widget build(BuildContext context) {
_scale = 1 - _controller.value;
return GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
child: Stack(
children: [
Transform.scale(
scale: _scale,
child: _DrawerButtonUi,
),
],
),
);
}
Widget get _DrawerButtonUi => Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
child: Row(
children: [
Icon(
widget.icon,
color: Colors.white,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(
widget.text,
style: const TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
),
);
void _onTapDown(TapDownDetails details) {
_controller.forward();
}
void _onTapUp(TapUpDetails details) {
_controller.reverse();
}
}
I thought maybe it had something to do with the stack widget I have in the gesturedetector of my DrawerButton. I have tried navigator.of(context).push instead of navigator.push, but that does not seem to make a difference.
But I am not quite sure how I can build that widget differently, keep the animation and have the navigator push work.
Does anybody have a solution?
You need to create a widget variable in order to access on state class.
class DrawerButton extends StatefulWidget {
final String text;
final IconData icon;
final VoidCallback onTap; //this will be used
const DrawerButton({
super.key,
required this.onTap,
And will be called on
void _onTapDown(TapDownDetails details) {
_controller.forward();
widget.onTap();
}
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:haufa/controllers/report_controller.dart';
import 'package:haufa/pages/Tabbar/homescreen_tabbar.dart';
class ReportSituationSelectRiskLevel extends StatefulWidget {
const ReportSituationSelectRiskLevel({Key? key}) : super(key: key);
#override
State<ReportSituationSelectRiskLevel> createState() =>
_ReportSituationSelectRiskLevelState();
}
bool scenarioOption = true;
class _ReportSituationSelectRiskLevelState
extends State<ReportSituationSelectRiskLevel> {
final controller = ReportController();
final ScrollController _controller = ScrollController();
#override
Widget build(BuildContext context) {
return Scaffold(
extendBodyBehindAppBar: false,
appBar: AppBar(
toolbarHeight: 0,
elevation: 0,
backgroundColor: Colors.transparent,
),
backgroundColor: Colors.white,
body: Column(
children: [
SizedBox(
height: 48.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(width: 60.w),
Text(
"Verify situation",
style: GoogleFonts.inter(
fontSize: 18,
fontWeight: FontWeight.w500,
color: Color(0xFFF374151),
),
),
IconButton(
splashRadius: 21,
color: Color(0xFFF9CA3AF),
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.close),
),
],
),
SizedBox(
height: 28.h,
),
Text(
"Select a scenario",
style: GoogleFonts.inter(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Color(0xFFF374151),
),
),
SizedBox(
height: 24.h,
),
// #### Here is where the iteration problem occured.
Container(
height: 475.h,
child: Scrollbar(
child: GridView.builder(
padding: EdgeInsets.only(left: 10.w, right: 10.w),
itemCount: 12,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemBuilder: (context, index) => scenarioCard(index),
)),
),
SizedBox(
height: 24.h,
),
Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 2,
shadowColor: Color(0xfff0000000D),
primary: Color(0xFFFD9D9D9),
minimumSize: Size.fromHeight(37.53),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(6),
),
),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomeScreenTabBar()),
);
// if (_formKey.currentState!.validate()) {
// _formKey.currentState!.save();
// KeyboardUtil.hideKeyboard(context);
// }
},
child: Text(
"Next",
style: GoogleFonts.inter(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Color(0xFFF8C8C8C),
),
),
),
),
],
),
);
}
Widget scenarioCard(int index) => Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: Container(
height: 175.h,
width: 149.w,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 100.0),
child: Radio<bool?>(
value: controller.reportCards[index].selectedValue,
groupValue: scenarioOption,
onChanged: (value) {
setState(
() {
scenarioOption = value!;
},
);
},
),
),
SvgPicture.asset(controller.reportCards[index].svgImage),
SizedBox(
height: 8.h,
),
Text(
controller.reportCards[index].title,
style: GoogleFonts.inter(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFFF434343),
),
),
// Text("data")
],
),
),
);
}
instead of using bool, to select a single item you can use int
int? selectedIndex ;
Padding(
padding: const EdgeInsets.only(right: 100.0),
child: Radio<int?>(
value: index,
groupValue: selectedIndex,
onChanged: (value) {
setState(
() {
selectedIndex = value;
},
);
},
),
),
Also Radio can be used with model or other data type.
To make a Card clickable you have to wrap it in an InkWell widget:
InkWell(
child: Card(...),
onTap:(){...}
)
https://api.flutter.dev/flutter/material/InkWell-class.html
However, in your code you have this comment // #### Here is where the iteration problem occured., but you didn't say what is the problem.
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
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),
),
],
),
);
}
}
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'),
),
],
);
}
}