Flutter: persistentFooterButtons with equally dynamic size widgets - flutter

I want to create a persistentFooterButtons with 3 FlatButton.icon
to equally take the whole width of the Screen, and customize itself with different screen sizes, i tried many approaches like Wrap,Expanded, i couldn't make it work, i even tried
final screenSize = MediaQuery.of(context).size;
Container(
width: screenSize.width /3 ,
child: FlatButton.icon(
onPressed: null,
icon: Icon(Icons.search),
label: Text("search")),
),
but the text always overflows on the right side of the screen.
So, Any ideas how this might go?
**Edit**
i found this approach which is very helpful
persistentFooterButtons: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton(
onPressed: () {},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Icon(Icons.lightbulb_outline),
new Text('Idea'),
],
),
),
FlatButton(
onPressed: () {},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Icon(Icons.lightbulb_outline),
new Text('Idea'),
],
),
),
FlatButton(
onPressed: () {},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Icon(Icons.lightbulb_outline),
new Text('Idea'),
],
),
),
],
),
],
The only problem is that mainAxisAlignment property doesn't make any changes, so the three buttons are sided together
See here
Any help?

For create a persistentFooterButtons you need to use bottomNavigationBar.
And For create 3 flatButton with equal size, you need to use flex attribute inside Expanded Widget.
Scaffold(
body: Container(
color: Colors.white,
child: Center(child: Text("Flutter"),),
),
bottomNavigationBar: new Container(
padding: EdgeInsets.all(0.0),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
flex: 1,
child: FlatButton.icon(
onPressed: () {
},
icon: Icon(Icons.search),
label: Text("Search"),
),
),
Expanded(
flex: 1,
child: FlatButton.icon(
onPressed: () {
},
icon: Icon(Icons.search),
label: Text("Search"),
),
),
Expanded(
flex: 1,
child: FlatButton.icon(
onPressed: () {
},
icon: Icon(Icons.search),
label: Text("Search"),
),
),
],
),
),
);

Related

How can I add shadow and frame to button

My button looks like this,
How can I convert it to this?
My Code:
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.bubble_chart_rounded),
),
const Text('Rear Camera')
],
),
This might be the most simplest way to achieve what you're trying to do here.
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card( // The widget that is providing that shadow with elevation perameter.
elevation: 8, // Controls the shadow you're wanting to get.
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(80), // To achieve the circular shape around your button.
),
child: Padding(
padding: EdgeInsets.all(10),
child: IconButton(
onPressed: () {},
icon: Icon(Icons.bubble_chart_rounded),
),
),
),
const Text('Rear Camera')
],
),

Why Third Row widget in the Column stack goes away?

I am building the app where my widget tree starts with Scaffold and as for body parameter, I assign the column widget. Within the column widget, I want the first 3 buttons sitting side by side, which work fine and next Expanded Widget which takes whole screen and third again 2 buttons sitting side by side. However, the thing is that, the third row widget is not visible on the screen of the phone. Can someone explain why it happens?
Scaffold(
appBar: AppBar(
title: const Text("My Work Timer"),
),
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Padding(padding: EdgeInsets.all(defaultPadding)),
Expanded(
child: ProductivityButton(
color: const Color(0xff009688),
text: "Work",
size: 3,
onPressed: () {}),
),
Padding(padding: EdgeInsets.all(defaultPadding)),
Expanded(
child: ProductivityButton(
color: const Color(0xff607D8B),
text: "Short Break",
size: 3,
onPressed: () {}),
),
Padding(padding: EdgeInsets.all(defaultPadding)),
Expanded(
child: ProductivityButton(
color: const Color(0xff455A64),
text: "Long Break",
size: 3,
onPressed: () {}),
),
Padding(padding: EdgeInsets.all(defaultPadding)),
],
),
Expanded(
child: Text("Hello"),
),
Row(
children: [
Padding(padding: EdgeInsets.all(defaultPadding)),
Expanded(
child: ProductivityButton(
color: const Color(0xff212121),
size: 2,
text: "Stop",
onPressed: () {},
)),
Padding(padding: EdgeInsets.all(defaultPadding)),
Expanded(
child: ProductivityButton(
color: const Color(0xff009688),
size: 2,
text: "Restart",
onPressed: () {},
)),
Padding(padding: EdgeInsets.all(defaultPadding)),
],
)
],
),
);
regards

IconButtons take too much space

I place thee IconButtons in the first Expanded. But they takes too much space around them. How to place them closer to each other?
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
iconSize: 10,
icon: FaIcon(FontAwesomeIcons.plus),
onPressed: null,
),
IconButton(
iconSize: 10,
icon: FaIcon(FontAwesomeIcons.asterisk),
onPressed: null,
),
IconButton(
iconSize: 10,
icon: FaIcon(FontAwesomeIcons.hashtag),
onPressed: null,
),
],
),
),
Expanded(...),
Expanded(...),
],
)
],
);
You could use RawMaterialButtons, then you use the BoxConstraints to set the size around it, look this aswer: https://stackoverflow.com/a/54963347/2831595
You can try this:
AspectRatio(
aspectRatio: 1,
child: IconButton(
icon: Icon(Icons.ac_unit),
onPressed: () {},
),
);

Space Multiple Images Horizontally (Flutter)

I'm trying to space 5 small images horizontally in flutter, but I can't seem to find a simple answer. Maybe I'm just stressed that I can't learn by asking questions... Here's what I have:
body: Center(
child: Row(
children: <Widget> [
Expanded(
child: FlatButton(
onPressed: null,
child: Image.asset('assets/button1.png'),
),
),
],
),
))));
Where would I place the next button code? Thank you for understanding!
Row(
children: <Widget> [
Expanded(
child: FImage.asset('assets/image1.png'),
),
Expanded(
child: Image.asset('assets/image2.png'),
),
Expanded(
child:Image.asset('assets/image3.png'),
Expanded(
child: Image.asset('assets/image4.png'),
),
Expanded(
child: Image.asset('assets/image5.png'),
),
]
That is one way to render 5 images horizontally. I don't know why you had these FlatButton() widgets there.
But remember that Row() widget in general puts widgets horizontally in a row.
There is also the Column() widget whereas it puts its' children widgets vertically, like being in a column.
I think this is what you are looking for
Row(
children: <Widget> [
Expanded(
child: FlatButton(
onPressed: null,
child: Image.asset('assets/button1.png'),
   ),
),
Expanded(
child: FlatButton(
onPressed: null,
child: Image.asset('assets/button1.png'),
   ),
),
Expanded(
child: FlatButton(
onPressed: null,
child: Image.asset('assets/button1.png'),
   ),
),
Expanded(
child: FlatButton(
onPressed: null,
child: Image.asset('assets/button1.png'),
   ),
),
Expanded(
child: FlatButton(
onPressed: null,
child: Image.asset('assets/button1.png'),
   ),
),
]

How can I display buttons side-by-side in Flutter?

I would like to display both of my buttons next to each other horizontally. So far I can only display them from top to bottom.
With the following code, what would I have to change ?
new Container(
child: new Column(
children: <Widget>[
new RaisedButton(
child: new Text("LogIn"),
color: Colors.blueAccent[600],
onPressed: null,
),
new RaisedButton(
child: new Text("SignUp"),
color: Colors.blueAccent[600],
onPressed: null,
),
],
),
),
Column is for items vertically arranged (hence a column), you are looking for Row. Just replace Column with Row, the rest of the code is fine. You can also use an Expanded if you want to fill all the available space.
Wrap(
children: <Widget>[
RaisedButton(
...
),
RaisedButton(
...
),
RaisedButton(
...
),
],
),
If you have a column with text in it, and you want two buttons below that text right next to eachother you can use ButtonTheme.bar
Below is some of Flutter's starting code with it. You could plug it in to the starter to see it in action:
Just paste this after the second new text (the one with $counter in it)
new ButtonTheme.bar(
child: new ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
new RaisedButton(
onPressed: _incrementCounter,
child: new Icon(Icons.add),
color: Colors.green,
),
new RaisedButton(
onPressed: _decrementCounter,
child: new Icon(Icons.remove),
color: Colors.red,
),
],
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Rahul Srivastava",
),
Text(
"Varanasi, India",
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
var player = AudioCache();
player.play('abc.mp3');
},
child: Text('Play')),
FlatButton(
onPressed: () {
var player = AudioCache();
player.play('abc.mp3');
},
child: Text('Pause')),
],
)
],
),
Do something like this
new Column(children: <Widget>[
new Button(
...
...
),
new Button(
...
...
)
])
Just replace Column with that Row in your code It will work.
Although I want to add some extra stuff here suppose that you have Column wrapped inside a row then how will you achieve that displaying of buttons side by side?
Simple just change Column to row n row to column as follows:
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: ...
),
child: ..
),
child: ..
)
],
),