DropDownButton arrow not expanded - dart

Trying to expand Two DropDownButtons in a row to fill up the space. The buttons get expanded but the arrow doesn't expand. Is there a way to make this work properly? Can't seem to find any solution so far.
This is my sample Code:
body: Form(
key: _formKey,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: DropdownButton<String>(
isDense: true,
items: ['Jan', 'Feb', 'March'].map((month) => DropdownMenuItem<String>( child: Text(month),)).toList(),
onChanged: (month){
print(month);
},
),
),
SizedBox(width: 20.0,),
Expanded(
child: DropdownButton<String>(
items: ['1', '2', '3'].map((day) => DropdownMenuItem<String>( child: Text(day),)).toList(),
onChanged: (day){
print(day);
},
),
)
],
)
],
),
),
This is the current view:

Related

How to wrap row items in a card with flutter

I have a card that contains row of items (text and checkbox widgets). The problem is that the card can only fill up limited space each row, but it isn't going to the next line in the row. I tried using the wrap widget but it had no effect. I keep getting this:
As you can see it is not wrapping to the next but trying to fit everything in that one line. Here is my code:
Widget _buildCategories() {
return Card(
margin: const EdgeInsets.only(top: 20.0),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text(
'Categories',
style: TextStyle(fontFamily: 'MonteSerrat', fontSize: 16.0),
),
Wrap(
children: <Widget>[
Row(
children: <Widget>[
_checkBox('Gaming'),
_checkBox('Sports'),
_checkBox('Casual'),
_checkBox('21 +'),
_checkBox('Adult'),
_checkBox('Food'),
_checkBox('Club'),
_checkBox('Activities'),
_checkBox('Shopping'),
],
)
],
)
],
),
));
}
Widget _checkBox(String category) {
return Expanded(
child: Column(
children: <Widget>[
Text(
'$category',
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'MonteSerrat'),
),
Checkbox(
value: false,
onChanged: (value) {
// We will update the value to the firebase data here
print('updated value to: $value');
},
)
],
));
}
I fixed your code with the following changes:
Removed Row widget inside Wrap.
Removed Expanded widget.
Add the property maxLines to your Text widget.
Widget _buildCategories() {
return Card(
margin: const EdgeInsets.only(top: 20.0),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text(
'Categories',
style: TextStyle(fontFamily: 'MonteSerrat', fontSize: 16.0),
),
Wrap(
children: <Widget>[
_checkBox('Gaming'),
_checkBox('Sports'),
_checkBox('Casual'),
_checkBox('21 +'),
_checkBox('Adult'),
_checkBox('Food'),
_checkBox('Club'),
_checkBox('Activities'),
_checkBox('Shopping')
],
)
],
),
));
}
Widget _checkBox(String category) {
return Column(
children: <Widget>[
Text(
'$category',
maxLines: 1,
textAlign: TextAlign.center,
style: TextStyle(fontFamily: 'MonteSerrat'),
),
Checkbox(
value: false,
onChanged: (value) {
// We will update the value to the firebase data here
print('updated value to: $value');
},
)
],
);
}
}
Also you can add the properties runSpacing and spacing to your Wrap widget to give more space between your items in horizontal and vertical.
Wrap(
runSpacing: 5.0,
spacing: 5.0,
More info here: https://api.flutter.dev/flutter/widgets/Wrap-class.html

How to Create Listtile leading with 2 Widgets?

How can i create a leading Widget that contains an image and a checkbox?
i tried with a Row Widget but then my listtile grows up to much.
ListTile(
leading: Row(
children: <Widget>[
LoadImage(),
Checkbox(value: false, onChanged: null),öööö
],
),
title: Text(snapshot.data.documents[index]["Name"]),
subtitle: Text(snapshot.data.documents[index]["Status"]),
trailing: IconButton(
onPressed: (){
showDialog(
context: context,
builder: (_) {
return DialogSpielerLoeschen(
snapshot: snapshot,
index: index,
);
},
);
},
icon: Icon(Icons.delete),
),
);
without the row and with only the image, title and subtitle are visible.
pls help.
Ty
use CheckboxListTile
ListView(
children: List.generate(
30,
(item) => CheckboxListTile(
dense: true,
controlAffinity: ListTileControlAffinity.leading,
secondary: Icon(Icons.delete),
value: false,
onChanged: (g) {},
title: Row(
children: <Widget>[
FlutterLogo(),
Expanded(
child: Text("item"),
),
],
),
)),
)

Flutter - Fix Drawer Header

Following this link Add a Drawer to a screen I have created a drawer.
Following is my piece of code:
// FUNCTION CONTAINING LEFT SIDE MENU ITEMS
_drawerList() {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'John Doe',
),
],
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/menu_bg.png'),
fit: BoxFit.cover,
),
),
),
ListTile(
// Some Code
),
],
),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
// Some Code
drawer: Drawer(
child: _drawerList(),
),
// Some Code
}
}
Is there any way I can fix "DrawerHeader" so that it doesn't move with the drawer and list view.
P.S. I don't want to hold ListView. I just want to hold or fix "DrawerHeader".
Yes, move it out of the ListView widget and use Column to hold both DrawerHeader and ListView.
With items scrolling enabled
_drawerList() {
return Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DrawerHeader(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'John Doe',
),
],
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/menu_bg.png'),
fit: BoxFit.cover,
),
),
),
ListView(
padding: EdgeInsets.zero,
children: <Widget>[
ListTile(
// Some Code
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
],
),
],
),
);
}
With items scrolling disabled
_drawerList() {
return Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DrawerHeader(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'John Doe',
),
],
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/menu_bg.png'),
fit: BoxFit.cover,
),
),
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
ListTile(
// Some Code
),
],
),
);
}
Instead of wrapping inside ListView you can wrap it inside column and then add other widget inside that. Also if you want to divide header and other part in any ratio you can use Expanded widget.
_drawerList() {
return Drawer(
child: Container(
child: Column(
children: <Widget>[
Expanded(
flex: 1,
child: DrawerHeader(
padding: EdgeInsets.all(0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'John Doe',
),
],
),
),
),
Expanded(
flex: 2,
child: ListView(
scrollDirection: Axis.vertical,
children: <Widget>[
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
ListTile(
title: Text("Ses"),
// Some Code
),
],
),
)
],
),
),
);
}
I use this code to pin DrawerHeader on top with fixed height and make list to fill rest of space below.
final drawer = Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
height: 200,
child: DrawerHeader(
decoration: BoxDecoration(color: Colors.blue),
child: Text('Right Drawer Header',
style: TextStyle(color: Colors.white, fontSize: 24)))),
Expanded(
child: ListView(padding: EdgeInsets.zero, children: [
ListTile(leading: Icon(Icons.message), title: Text('Message')),
ListTile(
leading: Icon(Icons.account_circle), title: Text('Profile')),
ListTile(leading: Icon(Icons.settings), title: Text('Settings')),
]))
]));

Text wrap in row widgets

I have nested rows using this code:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'the text in the first row',
),
],
),
Row(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'the text in the second row',
),
],
),
],
)
When there is space, I want the rows to be side by side (current behavior):
Currently, when it overflows, the text gets cut off like this:
Is there a way to force the second row onto a new line when there's no space, so it looks like this?
Try this! It worked for me.
new Flexible(child: new Text('Auto wrap'))
Something on these lines will work:
Wrap(
direction: Axis.horizontal,
children: <Widget>[
Wrap(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'the text ',
),
],
),
Wrap(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'more the text in the first row',
),
],
),
Wrap(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'the text in the second row',
),
],
),
Wrap(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'more text in the second row',
),
],
),
Wrap(
children: <Widget>[
Icon(Icons.fiber_manual_record),
Text(
'the text in the third row',
),
],
),
],
)
Row(
children: [
Checkbox(
onChanged: (bool value) {},
value: true,
),
Flexible(
child: RichText(
strutStyle: StrutStyle(height: 1.4),
softWrap: true,
text: TextSpan(style: TextStyle(fontSize: 12, color: ColorUtil.hexToColor("#999999")), children: <InlineSpan>[
TextSpan(text: "ฉันได้อ่านและยอมรับ "),
TextSpan(text: "ฉันได้อ่านและยอมรับ "),
TextSpan(
text: "สัญญาการให้บริการ & ข้อตกลงความเป็นส่วนตัว",
style: TextStyle(color: ColorUtil.hexToColor("#666666")),
recognizer: TapGestureRecognizer()
..onTap = () {
Navigator.pushNamed(context, "/profile/terms_policy");
}),
]),
),
)
],
),
this work for me. Wrap with Flexible
If you wrapped Text widget with Padding adding Flexible around Padding do the trick.
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Icons.check,
color: Colors.green,
),
SizedBox(
width: 16,
),
Flexible(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
child: Text(
'Some text',
style: TextStyle(
fontSize: 18, color: Colors.white),
),
),
),
],
),

Flutter align button to bottom of Drawer

I'm trying to have a Widget align to the bottom of my NavDrawer while still keeping a DrawerHeader and a list at the top of the Drawer. Here's what I'm trying:
drawer: new Drawer(
child: new Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
new Text('Top'),
new Align(
alignment: FractionalOffset.bottomCenter,
child: new Text('Bottom'),
),
],
),
),
The bottom text should be aligned to the bottom of the drawer, but It isn't!
You need to wrap your Align widget in Expanded.
drawer: Drawer(
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Text('Top'),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Text('Bottom'),
),
),
],
),
),
Edit:
Years on and there's a much easier solution:
return Drawer(
child: Column(
children: [
ListView(), // <-- Whatever actual content you want goes here
Spacer(), // <-- This will fill up any free-space
// Everything from here down is bottom aligned in the drawer
Divider(),
ListTile(
title: Text('Settings'),
leading: Icon(Icons.settings),
),
ListTile(
title: Text('Help and Feedback'),
leading: Icon(Icons.help),
),
]
);
A little late to the party, but here's my solution to this problem:
#override
Widget build(BuildContext context) {
return Drawer(
// column holds all the widgets in the drawer
child: Column(
children: <Widget>[
Expanded(
// ListView contains a group of widgets that scroll inside the drawer
child: ListView(
children: <Widget>[
UserAccountsDrawerHeader(),
Text('In list view'),
Text('In list view too'),
],
),
),
// This container holds the align
Container(
// This align moves the children to the bottom
child: Align(
alignment: FractionalOffset.bottomCenter,
// This container holds all the children that will be aligned
// on the bottom and should not scroll with the above ListView
child: Container(
child: Column(
children: <Widget>[
Divider(),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings')),
ListTile(
leading: Icon(Icons.help),
title: Text('Help and Feedback'))
],
)
)
)
)
],
),
);
}
This produces the below output where the UserAccountDrawerHeader and the text items can be scrolled around inside the drawer but the Divider and the two ListTiles stay static on the bottom of the drawer.
look whats the problem with your code you have added a Column as a Child to the Drawer so whatever you add in it are vertically placed and The height of Column is by default shrunk to its children's height and it gets larger as the child gets, so there's no point in adding an Align inside a Column
The Simpler Solution Would be to use an Expanded Widget that takes the remaining Space Look I have used a Column and added A widget above and below the Expanded Widget.
Drawer(
elevation: 1.5,
child: Column(children: <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.redAccent,
)),
Expanded(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
ListTile(
title: Text('My Cart'),
leading: Icon(Icons.shopping_cart),
onTap: () {},
),
ListTile(
title: Text('My Orders'),
leading: Icon(Icons.add_shopping_cart),
onTap: () {},
),
ListTile(
title: Text('Logout'),
leading: Icon(Icons.exit_to_app),
onTap: () {})
],
)),
Container(
color: Colors.black,
width: double.infinity,
height: 0.1,
),
Container(
padding: EdgeInsets.all(10),
height: 100,
child: Text("V1.0.0",style: TextStyle(fontWeight: FontWeight.bold),)),
])),
A simple approach would be to use Spacer() like:
Scaffold(
drawer: Drawer(
child: Column(
children: <Widget>[
Text('Top'),
Spacer(), // use this
Text('Bottom'),
],
),
)
)
here is my solution of a vertical Row with icons in the end of the drawer.
#override
Widget build(BuildContext context) {
return Drawer(
child: Column(
children: <Widget>[
Expanded(
child: ListView(
children: <Widget>[
DrawerHeader(
padding: const EdgeInsets.all(7),
decoration: BoxDecoration(
color: AppColors.menuHeaderColor,
),
child: buildHeader(),
),
AccountDrawerRow(),
ListTile(
leading: Icon(Icons.directions_car),
title: Text(translations.button.vehicles),
),
ListTile(
leading: Icon(Icons.calendar_today),
title: Text(translations.button.appointments,),
),
],
),
),
Container(
child: Align(
alignment: FractionalOffset.bottomCenter,
child: Container(
padding: EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
InkWell(
onTap: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SettingsPage())),
child: Icon(Icons.settings)),
Icon(Icons.help),
Icon(Icons.info),
],
),
),
),
),
],
),
);
}
I'd put it in a row and align all the stuff to bottom using crossAxisAlignment: CrossAxisAlignment.baseline
Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.baseline,
children: <Widget>[
Text(
'12.00',
style: Theme.of(context).textTheme.headline2,
textAlign: TextAlign.start,
),
Text(
'USD',
style: Theme.of(context).textTheme.bodyText2,
textAlign: TextAlign.start,
),
]),
Using Expanded widget to align widget to bottom of column parent widget
Column(
children: [
..other children
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: Text(
'Button',
style: TextStyle(
decoration: TextDecoration.underline,
fontSize: 18,
color: Colors.black),
),
),
),
],
),

Resources