Im new in flutter stuff can anyone help me to design layout list menu like this in flutter
ListView(
padding: const EdgeInsets.all(0), children: [
Card(
child: ListTile(
leading: Text(
'List Item 1',
),
trailing: Wrap(
spacing: 12,
children: <Widget>[
Text("Full Service"),
Icon(Icons.arrow_forward_ios_sharp,color: Colors.red,),
],
),
)
),
Card(
child: ListTile(
title:Text("List Item 2", style: mainNavigation,) ,
)
),
], shrinkWrap: true, ),
Use ListTile widget for making this UI. Try below example.
ListTile(
leading: Text(
'Tipe Akun',
),
trailing: Wrap(
spacing: 12,
children: <Widget>[
Text("Full Service"),
Icon(Icons.arrow_forward_ios_sharp,color: Colors.red,),
],
),
);
P.S :- Adjust your desire icon size
Find more articles of ListTile widget :
Various examples of ListTile
ListTile Official Document
Related
Hi trying to figure out why my hamburger is getting misaligned when i add another Expanded() code within the body.
I tried to follow this url to develop a hamburger menu and responsive for all platforms at once.
Flutter Blog
Below is the code that i tried where i added Expanded() below the Row()
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
return Scaffold(
key: _scaffoldKey,
drawer: AppDrawer(),
body: Row(
children: [
Row(
children: [
Padding(
padding: const EdgeInsets.all(16),
child: IconButton(
icon: Icon(Icons.menu, size: 30),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
}),
),
],
),
Expanded(
child: Container(
width: width,
child: Column(
children: [
Expanded(
child: Lottie.network(
'https://assets2.lottiefiles.com/datafiles/6WfDdm3ooQTEs1L/data.json'),
),
Expanded(
child: Column(
children: [
Flexible(
child: Text(
"Multivariate Testing",
style: GoogleFonts.montserrat(
fontSize: 50,
),
),
),
SizedBox(
height: 10,
),
Flexible(
child: Text(
'Run experiments to make key flows more effective.',
style: GoogleFonts.montserrat(
fontSize: 25,
),
),
),
SizedBox(
height: 35,
),
// ignore: deprecated_member_use
TextButton(
onPressed: () {},
child: Text(
'Create Experiment',
style: GoogleFonts.montserrat(
fontSize: 20,
),
),
)
],
),
),
],
),
),
)
],
),
);
}
}
and the output that i am seeing from mobile view. Appreciate any help. Sorry for too big screenshot!
This is because of the default functionality of Row.
So change your first child for your top level Row to this,
Scaffold(
key: _scaffoldKey,
drawer: AppDrawer(),
body: Row(
children: [
Align(
alignment: Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.all(16),
child: IconButton(
icon: Icon(Icons.menu, size: 30),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
})),
),
Expanded( ...... rest of your code
Here, we are using the Align widget with alignment: Alignment.topCenter.
Align widget takes the entire available space in the parent and then depending on the alignment property, aligns it't child inside it.
So, saying Alignment.topCenter will place it at the top vertically and middle horizontally.
Using an AppBar will unnecessarily complicate your situation since now, the AppBar is going to take up space a the top, but in your case, you want your Lottie view to be visible at the top, so it will overlap.
Because Expanded fills up the whole space and that's why your hamburger is getting misaligned.
Why don't you try using appbar for the hamburger?
I want to implement a horizontal scroll with categories:
I put my Categories section in Column (maybe it is not the right way, correct me please if I am wrong) and then I try to make my categories scrollable using ListView/Slivers. I have faced with issue that I need to specify constraints for ListView if I use it inside Column. I tried to wrap it with Expanded widget but it didnt work for me. Then I tried CustomScrollView and Slivers but it seems I am doing something wrong. Can you please suggest me the right structure of the widgtes for this view or correct me.
Container(
margin: EdgeInsets.all(40),
child: Column(
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Category',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
Text(
'8 CATEGORIES',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
],
),
SizedBox(
height: 30,
),
CustomScrollView(
scrollDirection: Axis.horizontal,
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate([
CategoryCard(
title: 'Featured',
previewImageAsset:
'assets/images/bliny-shokolad-klubnika.jpg',
),
]),
)
],
),
Row(
children: <Widget>[
CategoryCard(
title: 'Featured',
previewImageAsset:
'assets/images/bliny-shokolad-klubnika.jpg',
),
],
),
],
),
),
],
),
),
You are getting the error when using the ListView the renderview port was exceeded. To fix this, warp your ListView in a Container widget and give it the height and width property:
Check below:
Container(
// change your height based on preference
height: 80,
width: double.infinity,
child: ListView(
// set the scroll direction to horizontal
scrollDirection: Axis.horizontal,
children: <Widget>[
// add your widgets here
CategoryCard(
title: 'Featured',
previewImageAsset:
'assets/images/bliny-shokolad-klubnika.jpg',
),
// space them using a sized box
SizedBox(width: 15,),
CategoryCard(
title: 'Featured',
previewImageAsset:
'assets/images/bliny-shokolad-klubnika.jpg',
),
],
),
),
I have a navigation drawer with a bunch of items and I want the logout item aligned to the very bottom of the drawer.
return Drawer(
child: Column(
children: [
DrawerAccountHeader(UserType.worker),
DrawerNavigationItem(
"Home",
Icons.home,
),
new ListTile(
title: new Text('Jobs', style: TextStyle(color: Colors.black54),),
dense: true,
),
DrawerNavigationItem(
"Nearby",
Icons.location_on,
),
DrawerNavigationItem(
"Applied",
Icons.check_circle_outline,
),
DrawerNavigationItem(
"Hired",
Icons.check_circle,
),
Expanded(child: Container()),
Divider(),
DrawerNavigationItem(
"Logout",
Icons.exit_to_app,
)
],
),
);
But on smaller screen I get overflow error because that topmost column height is bigger than screen height. So I tried changing the column to a ListBox and then I get an exception "Vertical viewport was given unbounded height", because I have the Expanded() in between the items to make that gap so that Login buttons sticks to the bottom of the list.
Is there any way to achieve below?
Have the login button (and possibly a group of buttons) stick to the bottom of the screen when there's vertical space.
Make the drawer item scrollable when there's not enough vertical space.
(nice to have) The scrollable, the entire drawer can be scrolled. I.e. on a small screen the user will need to scroll the drawer to get to the logout option.
Try this,
Drawer(
child: LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraint.maxHeight),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
DrawerHeader(
margin: EdgeInsets.all(0.0),
child: Center(
child: Text("Header"),
),
),
ListTile(
leading: Icon(Icons.home),
title: Text("Home"),
onTap: () {},
),
new ListTile(
title: new Text(
'Jobs',
style: TextStyle(color: Colors.black54),
),
dense: true,
),
ListTile(
leading: Icon(Icons.location_on),
title: Text("Nearby"),
onTap: () {},
),
ListTile(
leading: Icon(Icons.check_circle_outline),
title: Text("Applied"),
onTap: () {},
),
ListTile(
leading: Icon(Icons.check_circle),
title: Text("Hired"),
onTap: () {},
),
const Expanded(child: SizedBox()),
const Divider(height: 1.0, color: Colors.grey),
ListTile(
leading: Icon(Icons.exit_to_app),
title: Text("Logout"),
onTap: () {},
)
],
),
),
),
);
},
),
)
Use the Align widget to position bottom
Align(
alignment: Alignment.bottomCenter, //you can set it as per your requirement
child: Container(
child: Image.asset(
"assets/drawerCycleImage.png", //or Text widget or More Any
)),
#override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(
title:Text('Title')),
drawer:Drawer(
child:Stack(
children:[
ListView(
shrinkWrap:true,
children: List.generate(25,(ind){
//SizedBox is to remain space for logout button !
return ind==25 ?
SizedBox(height:60)
: ListTile(title:Text('Item $ind'));
})
),
Align(
alignment:Alignment.bottomCenter,
child: Container(
height:60,
color:Colors.black,
child: ListTile(
leading:Icon(Icons.exit_to_app),
title:Text('Logout')
),
),
)
]
)
),
body: Container(
alignment:Alignment.center,
child: Text('Hello !')
),
);
}
I would like to add Subtitle and divider in navigation drawer like below image screen shot.
I have written below code for navigation drawer but not able to find where i can put Subtitle & divider.
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: const <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text(
'Drawer Header',
style: TextStyle(
color: Colors.white,
fontSize: 24,
),
),
),
ListTile(
leading: Icon(Icons.message),
title: Text('Messages'),
),
ListTile(
leading: Icon(Icons.account_circle),
title: Text('Profile'),
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
),
],
),
),
there is a widget for it called Divider
you could simply add a Divider as one of the childrens of the ListView
for the subtitle you could add a Text widget and style it to look how you need it to look using a TextStyle
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: const <Widget>[
DrawerHeader(...),
Divider(), //here is a divider
Text("subtitle", style: TextStyle(...)),
ListTile(...),
ListTile(...),
Divider(), //here is a divider
ListTile(...),
//rest of your items
],
),
),
You can do it with Divider wigdet https://api.flutter.dev/flutter/material/Divider-class.html
Just Provide a Divider() within every ListTile where you wanna put that thin line on.
I had the same problem and solved it as follows:
class DividerWithSubheader extends StatelessWidget {
const DividerWithSubheader({Key? key, required this.subHeader,}) : super(key: key);
final String subHeader;
#override
Widget build(BuildContext context) {
return Stack(
children: [
Divider(),
Container(
padding: const EdgeInsets.only(left: 20),
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text(
subHeader,
style: Theme.of(context).textTheme.caption,
textAlign: TextAlign.start,
),
),
),
],
);
}}
And use it like this:
ListView(children: <Widget>[
DividerWithSubheader(subHeader: 'subheader Test'),
]),
I created a Drawer with a child of a ListView like the core documentation suggests. It works. But I want to put a widget fixed at the bottom of my drawer. So I wrapped my ListView in a Column. But when I do this my Drawer contents disappear completely.
final Widget _leftDrawer = Drawer(
child: Column(
children: <Widget>[
ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Image.asset('assets/images/logo_1024.png'),
),
ListTile(
title: Text('Line 1'),
),
ListTile(
title: Text('Line 2'),
),
AboutListTile(),
],
),
],
),
);
When you put a ListView inside a Column, the ListView does not know about its boundary anymore. You need to wrap your ListView inside an Expanded widget.
final Widget _leftDrawer = Drawer(
child: Column(
children: <Widget>[
Expanded(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Image.asset('assets/images/logo_1024.png'),
),
ListTile(
title: Text('Line 1'),
),
ListTile(
title: Text('Line 2'),
),
AboutListTile(),
],
),
),
],
),
);