I need to align bottom input field by top input field. Like:
Here is my code:
class CustomerInput extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: TextField(),
),
RaisedButton(
child: Icon(Icons.search),
onPressed: () {},
),
],
// ),
),
TextField(
enabled: false,
)
],
);
}
}
How to do it?
Following code will give exact view as you need. In second raw you will add only one TextFormField/TextField for edittext/textview.
Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 3,
child: TextFormField(
),
),
Expanded(
flex: 1,
child: RaisedButton(
child: Icon(Icons.search),
onPressed: () {},
),
),
],
// ),
),
Row(
children: <Widget>[
Expanded(
child: TextFormField(
),
)
],
)
],
));
in this code flex property of TextField is 3 and RaisedButton is 1
"sum equality of these is 4"
TextField will expand by 3/4 or 75% and RaisedButton by 1/4 or 25%
by this concept i created new Row and putted in it
TextField its flex is equal to top one .
Container its flex is equal to Raisedbutton's flex .
and the edited code is :
`
Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 3,
child: TextField(),
),
Expanded(
flex: 1,
child: RaisedButton(
child: Icon(Icons.search),
onPressed: () {},
),
),
],
// ),
),
Row(
children: <Widget>[
Expanded(
flex: 3,
child: TextField(
enabled: false,
),
),
Expanded(
child: Container(),
flex: 1,
)
],
)
],
))
`
Related
I want create this layout
layout
4 buttons align to left and Text and edit button align to center
so in web there will be some space
I tried flexible with FlexFit but did not get result as i want (text and edit buton in middle)
EDIT:
I manage to "hack" bad solution
expected layout
but this cause overflowed warning
Row(
children: [
Flexible(
flex: 2,
child: Row(
children: [
IconButton(
onPressed: () => Get.offAllNamed(Verifications.ENDPOINT),
icon: const Icon(Icons.arrow_back)),
...buildNavButtons(),
],
),
),
const Spacer(
flex: 99,
),
Row(
children: [
GetBuilder<VerificationState>(builder: (_) {
return Text(_.verifications[verificationId]!.name);
}),
IconButton(onPressed: () {}, icon: const Icon(Icons.edit)),
],
),
const Spacer(
flex: 99,
),
],
),
EDIT 2:
use Stack widget code example in answer
If I understand what you want correctly, you should use Expanded. It fills the remaining space in a Row/Column :
Row(
children: [
Button(),
Button(),
Button(),
Expanded(
child: Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(),
Button(),
]),
)
),
),
To create this layout you will require a row with 3 expanded widgets
Row(
children :[
Expanded(flex: 4, fit: FlexFit.tight,
child: Row(
//All 4 buttons here
)
),
Expanded(flex: 4, fit: FlexFit.tight,
child: Center(
//Text with icon here
)
),
Expanded(flex: 4, fit: FlexFit.tight,
child: Container()
),
]
)
we need to use Stack widget
Stack(
children: [
Row(
children: [
IconButton(
onPressed: () => Get.offAllNamed(Verifications.ENDPOINT),
icon: const Icon(Icons.arrow_back)),
...buildNavButtons(),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GetBuilder<VerificationState>(builder: (_) {
return Text(_.verifications[verificationId]!.name);
}),
IconButton(onPressed: () {}, icon: const Icon(Icons.edit)),
],
)
],
),
How can fix it?
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
fit: StackFit.loose,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
flex: 2,
child: buildSearch(),
),
Expanded(
flex: 2,
child: Container(color: Colors.green),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Frequitly Visited'),
TextButton(
onPressed: () {},
child: Text('Show More'),
),
],
),
Expanded(
flex: 6,
child: buildSites(size),
)
],
)
],
),
);
}
buildSearch() {
return Container(
child: FloatingSearchBar(
transitionCurve: Curves.easeInOutCubic,
transition: CircularFloatingSearchBarTransition(),
physics: const BouncingScrollPhysics(),
scrollPadding: EdgeInsets.zero,
builder: (context, _) => _history(),
),
);
}
Container buildSites(size) {
return Container(
color: Colors.black,
width: size.width,
);
}
Widget _history() {
List<String> listHistory = [
'Flutter',
'Python',
'Nodejs',
'Rails',
];
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Material(
child: Column(
children: listHistory
.map((e) => ListTile(
title: Text(e),
onTap: () {},
))
.toList(),
),
),
);
}
}
try to fixed the height of search & container, expanded only flexible part:
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 100,
child: buildSearch(),
),
Container(
height: 100,
child: Container(color: Colors.green),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Frequitly Visited'),
TextButton(
onPressed: () {},
child: Text('Show More'),
),
],
),
Expanded(
child: buildSites(size),
)
],
)
You can just remove the Expanded widget wrapped around your buildSearch() widget and give a desired padding or you can also your sizedbox with a desiredHeight below and above the buildSearch()
so basically change
...
Expanded(
flex: 2,
child: buildSearch(),
),
...
to
...
Padding(
padding:EdgeInsets.only(top:20,bottom:50), // adding a suitable padding should fix it
child:buildSearch(),
)
...
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'),
),
),
]
Basically I want to achieve the similar thing as this post Flutter: How to hide or show more text within certain length. However, I need to replace "show more" with an arrow and the arrow should be at the end of the last line of the collapsed text (not below it). I checked https://pub.dev/packages/expand_widget and https://pub.dev/packages/expandable these two packages, but they didn't seem to satisfy my requirements.
Could anyone help me with it? Thanks!
I think it should work for you!
Row(
children: [
Expanded(
child: Text("your text or widget"),
),
Icon(Icons.keyboard_arrow_down)
],
);
Just have an arrorw_down icon. When clicked change a boolean in setState(). In the widget tree just check if it's true, show something, else don't.
Switch between arrow_up/down depending on the boolean.
Expanded(
flex: 2,
child: InkWell(
onTap: () {
setState(() {
isBubbleExpanded = !isBubbleExpanded; // should expand?
});
},
child: Padding(
padding: EdgeInsets.all(3),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Center(
child: Icon(isBubbleExpanded
? Icons.keyboard_arrow_up
: Icons.keyboard_arrow_down),
),
],
),
],
),
),
),
));
}
Then somewhere else in the tree:
if (isBubbleExpanded)
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Expanded(
flex: 2,
child: Padding(
padding: EdgeInsets.all(2),
child: Center(),
),
),
Expanded(
flex: 2,
child: Center(
child: IconButton(
icon: const Icon(CupertinoIcons.info),
onPressed: () {
Navigator.of(context).pushNamed(
SomeScreen.routeName,
arguments: widget.document,
);
},
),
),
),
],
),
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"),
),
),
],
),
),
);