Flutter: How to align on start and center in Flutter Row - flutter

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)),
],
)
],
),

Related

Flutter how to right align last column

In Flutter, how do I make the third column fill the width? I'm trying to right-align the edit icon.
Row(
children: [
Column(
children: [ SizedBox(width: 10) ]
),
Column(
children: [ Text("example") ]
),
Column(
children: [ IconButton(icon: Icon(Icons.edit)) ],
),
],
);
All of the things I've tried such as putting it in Expanded() or IntrinsicWidth() or Column(..., crossAxisAlignment: CrossAxisAlignment.stretch) have resulted in "Cannot hit test a render box that has never been laid out."
Place Spacer() before last Column.
wrap your column with Align and then Expanded and then set Alignment:Alignment.centerRight
. this will give you the flexibility to place your widget any place you want.
see Align from Flutter Docs.
Row(
children: [
Column(children: [SizedBox(width: 10)]),
Column(children: [Text("example")]),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Column(
children: [
IconButton(
icon: Icon(Icons.edit),
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'),
   ),
),
]

Flutter - Put the expand arrow at the end of the last line of the text

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,
);
},
),
),
),
],
),

How to fill contents inside wrap widget?

I want to move widgets to the new line automatically if it's overflow and Wrap widget is a good way for this.
so I have some wrap widgets which have width based on text length and some icons like:
Current actual:
I want to align 2 icons on the left and right side of the parent.
but as you can see the red-colored area of Row, I don't know how to make Row width match to the parent when Text widget has longer than Row (in the above case of the attached image, something?)
This is what I expect:
and my current code is:
Wrap(
direction: Axis.horizontal,
crossAxisAlignment: WrapCrossAlignment.start,
children: [
Container(
child: Column(
children: [
Text(
"hoge",
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.edit),
Icon(Icons.more_vert),
],
)
],
),
),
Container(
child: Column(
children: [
Text(
"too long text...............",
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Icon(Icons.edit),
Icon(Icons.more_vert),
],
)
],
),
),
Container(
child: Column(
children: [
Text(
"hoge",
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.edit),
Icon(Icons.more_vert),
],
)
],
),
),
],
),
How to achieve this?
IntrinsicWidth(
child: Column(
children: [
Text(
"too long text...............",
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Icon(Icons.edit),
Icon(Icons.more_vert),
],
)
],
),
),
Wrap your long text Column with IntrinsicWidth instead of normal Container Widget.moreover, remove the mainAxisSize constraint on the Row widget to make it's width same as Text widget.
https://api.flutter.dev/flutter/widgets/IntrinsicWidth-class.html
I think this is what you're looking for List of Containers side by side
I made it dynamic so that you can add new items if you want base on the list of Item.
class Item {
String text;
IconData icon1;
IconData icon2;
Color color;
Item({ this.text, this.icon1, this.icon2,this.color,});
}
We can make this dynamic by creating a List of Item
final List<Item> item = [
Item(
text: 'Item 3',
icon1: Icons.edit,
icon2: Icons.more_vert,
color: Colors.blue,
),
Item(
text: 'Item 2 This text is too long for the screen width..... screen width.....screen width.....screen width.....',
icon1: Icons.edit,
icon2: Icons.more_vert,
color: Colors.greenAccent,
),
Item(
text: 'Item 3',
icon1: Icons.edit,
icon2: Icons.more_vert,
color: Colors.amberAccent[100],
),
];
You might also want to look at Wrap Class
Wrap(
spacing: 8.0, // gap between adjacent chips
runSpacing: 4.0, // gap between lines
children: item.map((Item) {
return GestureDetector(
child: Container(
decoration: BoxDecoration(
color: Item.color,
),
margin: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(Item.text),
Wrap(
children: <Widget>[
Icon(Item.icon1),
Icon(Item.icon2),
],
)
],
),
),
onTap: () => {},
);
}).toList(),
),

How to align buttom TextField by top TextField?

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,
)
],
)
],
))
`