In the screenshot, I want to get the next and back buttons to the bottom of the screen.
The stepper has a parameter, controlsBuilder that allows you to build out the layout for the controls. If it's just a simple row, It's placed right underneath the content.
Apparently, the Stepper is a flexible wrapper. I'm not sure what that means. I think it means that the Stepper is considered a flex object because it contains a scrollable area (for the content). Having read the docs, if I'm understanding correctly, it says that I cannot use an Expanded or a Column with a max size in the mainAxis because the stepper is essentially a scrollable area, meaning any RenderBox inside it has unbounded constraints.
So, what are some ways the controls builder can be pushed down to the bottom?
Widget _createEventControlBuilder(BuildContext context, {VoidCallback onStepContinue, VoidCallback onStepCancel}) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
onPressed: onStepCancel,
child: const Text('BACK'),
),
FlatButton(
onPressed: onStepContinue,
child: const Text('NEXT'),
),
]
);
}
I did try wrapping the above row in a LayoutBuilder as well as another attempt using a SizedBox, setting the height to MediaQuery.of(context).size.height;. It does push it near to the bottom (not quite as much as I like), but the problem is that now there is space beneath controls, causing the screen to scroll down into empty space.
Full code:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Create an Event"),
),
body: Form(
key: _eventFormKey,
child: Stepper(
type: StepperType.horizontal,
currentStep: _currentStep,
controlsBuilder: _createEventControlBuilder,
onStepContinue: () {
if (_currentStep + 1 >= MAX_STEPS)
return;
setState(() {
_currentStep += 1;
});
},
onStepCancel: () {
if (_currentStep + 1 >= MAX_STEPS)
return;
setState(() {
_currentStep -= 1;
});
},
steps: <Step>[
Step(
title: Text("Name"),
isActive: 0 == _currentStep,
state: _getStepState(0),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 10.0),
child: Text(
"Give your event a cool name",
style: Theme.of(context).textTheme.title,
),
),
TextFormField(
maxLines: 1,
maxLength: 50,
maxLengthEnforced: true,
decoration: InputDecoration(
hintText: "e.g. Let's eat cheeseburgers!",
),
validator: (value) {
if (value.trim().isEmpty)
return "Event name required.";
},
)
],
)
),
Step(
title: Text("Type"),
isActive: 1 == _currentStep,
state: _getStepState(1),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 10.0),
child: Text(
"Select an event type",
style: Theme.of(context).textTheme.title,
),
),
Container(
margin: EdgeInsets.only(bottom: 10.0),
child: Row(
children: <Widget>[
Expanded(
child: DropdownButton<int>(
items: _stepTwoDropdownItems,
hint: Text("Select event type"),
isExpanded: true,
value: _eventTypeSelectedIndex,
onChanged: (selection) {
setState(() {
_eventTypeSelectedIndex = selection;
});
}),
)
],
)
)
],
)
),
]
),
),
);
}
I think you can create your own Stepper , or you can try this 'hack' :
Create two variables to store the callbacks:
VoidCallback _onStepContinue;
VoidCallback _onStepCancel;
Put your Form inside a Stack :
Stack(
children: <Widget>[
Form(
child: Stepper(
Change your createEventControlBuilder method:
Widget _createEventControlBuilder(BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) {
_onStepContinue = onStepContinue;
_onStepCancel = onStepCancel;
return SizedBox.shrink();
}
Add your custom buttoms :
Widget _bottomBar() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
onPressed: () => _onStepCancel(),
child: const Text('BACK'),
),
FlatButton(
onPressed: () => _onStepContinue(),
child: const Text('NEXT'),
),
]);
}
This is how your Stack will looks like :
Stack(
children: <Widget>[
Form(
child: Stepper(
....
), //Form
Align(
alignment: Alignment.bottomCenter,
child: _bottomBar(),
)
I know this is a little dirty, but you could try , otherwise I recommend you to create your own Widget.
You can also change the heights of the widgets in the contents of Steps to the same value, and make it a SingleChildScrollView if needed. e.g
Step(content: Container(
height: MediaQuery.of(context).size.height - 250, //IMPORTANT
child: SingleChildScrollView(
child: Column(children: <Widget>[
...
),
Related
I'm trying to build a Data Table variant so that the row can be expanded with extra information. I didn't found a way to do this with the DataTable class.
This is what I have:
class TestPanel extends StatefulWidget {
const TestPanel({Key? key}) : super(key: key);
#override
_TestPanelState createState() => _TestPanelState();
}
class _TestPanelState extends State<TestPanel> {
bool _customTileExpanded = false;
#override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: const <Widget>[
Expanded(
child: Text("Header 1"),
),
Expanded(
child: Text("Some Header 2"),
),
Expanded(
child: Text(""),
)
],
),
),
Expanded(
child: ListView.builder(
itemCount: 1,
itemBuilder: (BuildContext context, int index) {
return ExpansionPanelList(
animationDuration: Duration(milliseconds: 1000),
dividerColor: Colors.grey,
elevation: 1,
children: [
ExpansionPanel(
body: Container(
padding: EdgeInsets.all(10),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Some text here",
style: TextStyle(
color: Colors.grey[700],
fontSize: 15,
letterSpacing: 0.3,
height: 1.3),
),
],
),
),
headerBuilder: (BuildContext context, bool isExpanded) {
return Container(
padding: EdgeInsets.all(10),
child: Row(
children: const <Widget>[
Expanded(
child: Text("Value 1"),
),
Expanded(
child: Text("Some Value 2"),
),
],
),
);
},
isExpanded: _customTileExpanded,
)
],
expansionCallback: (int item, bool expanded) {
setState(() => _customTileExpanded = !expanded);
},
);
},
),
),
],
),
);
}
}
Now this results in:
As you can see the alignment with the headers is not correct. I have no idea how I can make sure that those are always aligned.
There's a tricky solution here by adding SizedBox with the same width of the ExpansionPanelList icon "including it's padding" at the end of the header row like following:
Row(
children: [
Expanded(
child: Row(
children: const <Widget>[
Expanded(
child: Text("Header 1"),
),
Expanded(
child: Text("Some Header 2"),
),
],
),
),
// If the Header text "Some Header 2" is longer than the Expansion Header "Some Value 2" you'll need to increase the Sizedbox width.
const SizedBox(
64, //ExpansionPanelList IconContainer size: end margin 8 + padding 16*2 + size 24
),
],
),
Also, I dont' know if this would work with your idea but you can have dynamic rows height with DataTable2 Package but first you need to copy the package code and paste it in your root directory of your current project to make some edits on it "To make the row's height dynamic":
For having Dynamic row height remove height: effectiveDataRowHeight and height: effectiveHeadingRowHeight from the new widget file.
You can add constraints: BoxConstraints(minHeight: effectiveHeadingRowHeight,) and constraints: BoxConstraints(minHeight: effectiveDataRowHeight,) instead of above and use dataRowHeight parameter as min Height and same for headingRowHeight.
To center all data in cells add defaultVerticalAlignment: TableCellVerticalAlignment.middle to var dataRows in the widget code.
Result:
Image
You can also do the same with the DataTable class but at step3, You need to add defaultVerticalAlignment: TableCellVerticalAlignment.middle to the Table child in the image: Image
I prefer using DataTable2 as it has more customization, you can find it here: DataTable2
After That, You can add Icon at the end of the row. If it's clicked you add new row with extra information.
I am having an issue with flutter forms.
Basically I have 3 simple rows added to a Stack. The last one contains a form. Below that there are 'Pinned' elements by Adobe XD, but the row containing the form is floating at the top of the screen... I would expect it to be arranged below the two first rows.
You can see the issue in the screenshot below. The form is on top of the image, but I want it to be above the 2 white lines which I want to replace by functional form fields.
Where am I going wrong? I have put the form in a separate Widget.
LoginPage.dart
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [
0.4,
1
],
colors: [
Colors.black,
Color(0xff7d060b),
])),
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.transparent,
body: SafeArea(
child: Stack(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
/* Image.asset(
'assets/images/Logo.png',
height: 100,
width: 250,
),*/
Image.asset(
'assets/images/fewturelogo.png',
height: 50,
),
Container(
padding: const EdgeInsets.only(left: 30.0),
child: IconButton(
color: Colors.white,
icon: const Icon(Icons.not_listed_location_rounded),
onPressed: () {
print('Hello');
showDialog(
context: context,
barrierDismissible: false,
// user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: Text('Was ist Rentalsplanet?'),
content: new SingleChildScrollView(
child: new ListBody(children: [
new Text(
'Hier erscheinen Informationen über Rentalsplanet')
]),
),
actions: [
new ElevatedButton(
child: Text('Alles klar!'),
onPressed: () {
Navigator.of(context).pop();
})
],
);
});
},
)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
margin: const EdgeInsets.only(top: 70.0),
child: Image.asset(
'assets/images/SplashImageLogin.png',
scale: 1.1,
),
),
],
),
Row(children: [
Container(
margin: const EdgeInsets.only(top: 70.0),
child: SizedBox(width: 100, child: LoginForm()),
)
]),
],
),
),
),
);
LoginForm.dart
Widget build(BuildContext context) {
// Build a Form widget using the _formKey created above.
return Form(
key: _formKey,
child: Column(
children: <Widget>[
new Flexible(
child: TextFormField(
// The validator receives the text that the user has entered.
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
),
ElevatedButton(
onPressed: () {
// Validate returns true if the form is valid, or false otherwise.
if (_formKey.currentState.validate()) {
// If the form is valid, display a snackbar. In the real world,
// you'd often call a server or save the information in a database.
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Processing Data')));
}
},
child: Text('Submit'),
),
// Add TextFormFields and ElevatedButton here.
],
),
);
}
because you are using stack... stack is not an easy thing to work with and in your case, if you don't have to use it replace it with Column and your problem will be fixed.
if not alignment in Stack or fractionaloffset or Transform.translate will help you
Transform.translate will fix your problem but it might cause some responsive issues
AnimatedContainer(
...
child: Container(
child: Column(
children: [
Row(
children: [
Container(
width:60,
height:50,
color: Colors.black,
),
],
),
Expanded(
child: GestureDetector(
onTap: () {
print('what');
},
child: Container(
height: 50,
child: Column(
children: [
Expanded(
child: Text('asdf'),
),
Expanded(
child: IconButton(
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
I have this AnimatedContainer widget here. My Text() widget and RaisedButton widget are hidden inside the box. They appear as the AnimatedContainer expand. However, my IconButton doesn't.
Also, Icon widget also stays like IconButton widget. How can I make it appear when the AnimatedContainer is stretched like the Text widget?
I've modified your code, hope this is what u want.
class _RowStructureState extends State<RowStructure> {
bool pressed = false;
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
pressed = !pressed;
});
print(pressed);
},
child: Column(children: <Widget>[
AnimatedContainer(
height: pressed ? 120 : 50,
color: Colors.green,
duration: Duration(seconds: 1),
child: Stack(
children: [
Container(
height: 50,
width: 50,
color: Colors.black,
),
Positioned(
bottom:0,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text('asd'),
IconButton(
padding: EdgeInsets.all(0),
icon: Icon(Icons.ac_unit,),
onPressed: pressed?(){}:null,
),
],
),
)
],
),
)
]),
);
}
}
I'm new to flutter and I want to delete the selected values from the
list,but I don't know how to delete selected Items,can anyone help?
I have taken icon button in Appbar and I tried to setState in it by
using the .removelast() command,but I want to select the Item then
delete it.
Code :
class DemoPage extends State<MyHomePage> {
TextEditingController Controller = TextEditingController();
List<String> msg = List();
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text('Demo_App'),
actions: <Widget>[
IconButton(icon: Icon(Icons.delete),
onPressed: (){
setState(() {
msg.removeLast();
});
}),
],
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
alignment: Alignment.topLeft,
margin: EdgeInsets.only(right: 150.0,top: 10.0,left: 8.0),
child:TextField(
controller: Controller,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'please enter your name',
),
),
),
Container(
alignment: Alignment.topRight,
margin: EdgeInsets.only(left: 250.0,right: 10.0),
child: RaisedButton(
onPressed: () {
setState(() {
msg.add(Controller.text);
Controller.clear();
});
},
child: Text('Add'),
),
),
Expanded(
flex: 2,
child: Container(
child: Card(
margin: EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: msg.length,
itemBuilder: (context, index){
if(index.isInfinite){
return Divider();
}
return ListTile(
title: Text(msg[index]),
);
},),
),
)),
],
),
);
}
}
I want to select the data and then delete it using the icon Button in
the AppBar.
Lets assume you want to select your items by a single click.
Take a separate a list indexList and each time you select an item, you store the clicked index into indexList.
Then upon clicking delete button run a loop on indexList and remove items from your itemList using the stored indexes.
clean indexList
update your state
class DemoPage extends State<MyHomePage> {
TextEditingController Controller = TextEditingController();
List<String> msg = List();
List<int> selectedItems = List();
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text('Demo_App'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
setState(() {
msg.removeLast();
});
}),
],
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
alignment: Alignment.topLeft,
margin: EdgeInsets.only(right: 150.0, top: 10.0, left: 8.0),
child: TextField(
controller: Controller,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'please enter your name',
),
),
),
Container(
alignment: Alignment.topRight,
margin: EdgeInsets.only(left: 250.0, right: 10.0),
child: RaisedButton(
onPressed: () {
setState(() {
msg.add(Controller.text);
Controller.clear();
});
},
child: Text('Add'),
),
),
Expanded(
flex: 2,
child: Container(
child: Card(
margin: EdgeInsets.all(8.0),
child: ListView.builder(
itemCount: msg.length,
itemBuilder: (context, index) {
return new GestureDetector(
onLongPress: () {
if(selectedItems.contains(index))
selectedItems.remove(index);
else
selectedItems.add(index);
},
onTap: () {
if(selectedItems.contains(index))
selectedItems.remove(index);
else
selectedItems.add(index);
},
child: index.isInfinite
? Divider()
: ListTile(
title: Text(msg[index]),
));
}),
),
)),
],
),
);
}
void _deleteItems(){ // call _deleteItems() on clicking delete button
setState(() {
//set your state
for (final index in selectedItems)
msg.removeAt(index);
selectedItems.clear();
});
}
}
I'm new to flutter. I'm trying to render a page whose body contains Listview with multiple widgets.
_buildOrderDetails widget in the listview is widget that is build with listview.builder() , remaining are normal widgets.
The problem is page is not being scrolled .
When the body Listview is changed to column and _buildOrderDetails is given as child to the Expanded, the listview is limited to some extent of the page height and being scrolled. But when input is focused the page is overflowed
Widget build(BuildContext context){
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {
return Scaffold(
appBar: AppBar(
title: Text('Order Details'),
actions: <Widget>[
IconButton(
onPressed: () {
model.addNewOrder();
},
icon: Icon(Icons.add),
),
BadgeIconButton(
itemCount: model.ordersCount,
badgeColor: Color.fromRGBO(37, 134, 16, 1.0),
badgeTextColor: Colors.white,
icon: Icon(Icons.shopping_cart, size: 30.0,),
onPressed: () {}
),
]
),
body: ListView(
children: [
Column(
children: [
_buildItemsTitle(),
Expanded(child: _buildOrderDetails(context, model)),
]
),
Card(
child: Column(
children:[
TextField(
decoration: InputDecoration(
labelText: 'Offer Code'
),
),
RaisedButton(
onPressed: (){},
child: Text('Apply'),
)
]
),
),
Card(child: _orderAmount(context, model),),
RaisedButton(
color: Theme.of(context).accentColor,
onPressed: (){},
child: Text('Checkout',
style: TextStyle(
fontSize: 20.0,
color: Colors.white
)
),
)
]
),);});}}
Maybe it can help someone in the future, but the trick seems to be: use ListView + LimitedBox(maxHeight) + Column ...
ListView(
padding: EdgeInsets.zero,
shrinkWrap: true,
children: [
FocusTraversalGroup(
child: Form(
key: _formKey,
child: LimitedBox(
maxHeight: MediaQuery.of(context).size.height,
child: Column(
// mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Spacer(flex: 30), // Or Expanded
// More Widgets...
Spacer(flex: 70), // Or Expanded
// ....
Try not to use expanded on growing items. If you want to cover a percentage/fractional height wrap the height with a fixed height or the full height with a container that includes box contstains, then proceed to have expanded or fixed height children. also helpful is the FracionalBox
In the example you showed there is no need for expanded, the children inside will give a content height and the SingleChildScrollView will automaticly handle scrolling based on children.
Widget build(BuildContext context) {
return ScopedModelDescendant<MainModel>(
builder: (BuildContext context, Widget child, MainModel model) {
return Scaffold(
appBar: AppBar(title: Text('Order Details'), actions: <Widget>[
IconButton(
onPressed: () {
model.addNewOrder();
},
icon: Icon(Icons.add),
),
BadgeIconButton(
itemCount: model.ordersCount,
badgeColor: Color.fromRGBO(37, 134, 16, 1.0),
badgeTextColor: Colors.white,
icon: Icon(
Icons.shopping_cart,
size: 30.0,
),
onPressed: () {}),
]),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Column(children: [
_buildItemsTitle(),
Container(child: _buildOrderDetails(context, model)),
]),
Card(
child: Column(children: [
TextField(
decoration: InputDecoration(labelText: 'Offer Code'),
),
RaisedButton(
onPressed: () {},
child: Text('Apply'),
)
]),
),
Card(
child: _orderAmount(context, model),
),
RaisedButton(
color: Theme.of(context).accentColor,
onPressed: () {},
child: Text('Checkout',
style: TextStyle(fontSize: 20.0, color: Colors.white)),
),
],
),
),
);
});
}