Column isn't expanding - flutter

I'm trying to make a widget on the very bottom of the screen (above the bottomnavbar).
I added MainAxisAlignment.spaceBetween to the column, but it seems like the Column in the SingleChildScrollView is shrinking to fit. How can I make _BottomOne all the way on the bottom?
Column(children: [
_StayOnTopWidget(),
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_FirstOne(),
_BottomOne(),
],
),
),
)
]),

Expanded widget should be the parent of _BottomOne, which will take remaining space will align itself at the bottom
Column(children: [
_StayOnTopWidget(),
SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_FirstOne(),
Expanded(
child:
_BottomOne(),
),
],
),
)
]),

Related

flutter place widget on bottom of screen in expanded

like the title says is there a way to place a widget on bottom of screen in expanded
Expanded -> SingleChildScrollView() -> column(children: [ -> Container() -> ElevatedButton() ])
i want the ElevatedButton to be placed on the bottom of screen also i don't want to place it away of the Expanded widget, is there a way to do that ?
Expanded(
child: Column(
children: [
Container(),
//use Spacer(),
Spacer(),
ElevatedButton()
],
),
)
try use spacer inside column
SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height - APPBAR_SIZE,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(child: CHILD),
ElevatedButton(),
],
),
),
)
UPDATE:
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: MediaQuery.of(context).size.height - APPBAR_SIZE - ElevatedButtonHeight,
child: SingleChildScrollView(
child: Container(child: CHILD),
),
),
ElevatedButton(),
],
),

Proper text wrapping for right sided widget in a row

I have a layout as follows:
Widget1 is aligned to the left, Widget2 and the text widget - to the right.
How can I wrap the text with an ellipsis for example in case it doesn't fit into the row, as follows?
you can wrap 'Text with property...' inside ExpandedWidget.
Row(
children: [
WidgetA(),
WidgetB(),
Expanded(
child: Text("...."),
)
],
)
add your Text widget inside Expanded
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text('Atras'),
),
Expanded(
child: Text('Filtros offertos'),
),
Expanded(
child: Text('title'),
),
Expanded(
child: Text('titleasdas'),
),
Expanded(
child: Text('title'),
),
Expanded(
child: Text('titlesfsfsdf'),
),
],
),
Your result screen->

How to center only one element in a column of 5 elements in flutter

I have 5 elements in a Column, and I make them cross in start,
and I need to add another element 'Text' in the center of the column,
So How do I make my Text centered in the entire Column, and the rest elements to the right start?
In column one element wrap with Align widget
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('in start'),
Align(alignment: Alignment.center, child: Row(children: [ Icon(), Text() ] )),
Align(alignment: Alignment.center, child: Text("test")),
Text("test"),
Text("test"),
Text("test"),
],
),
Ouput:
Result
Code
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("start"),
ElevatedButton(onPressed: () {}, child: Text("ink")),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.ac_unit),
Text("Center"),
],
),
Text("text "),
],
),

BoxConstraints Error when stretching a row widget

I have a Card widget in a ListView widget and the card has the following code structure to it:
return Card(
child: Row(
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image(
image: AssetImage('assets/images/my-img.jpg'),
width: 150,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, // THIS HAS NO EFFECT
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(content.title),
Text(content.description),
],
),
Row(
// crossAxisAlignment: CrossAxisAlignment.baseline,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.accessibility),
Text('cool')
],
),
Text('something else'),
],
)
],
),
),
],
),
);
I'm trying to make the column in the row have a spaceBetween alignment since right now it the column is vertically centered. I tried adding a CrossAxisAlignment.stretch to the Row widget, but I get an error:
BoxConstraints forces an infinite height
You could add a SizedBox between the Column and Row.
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(content.title),
Text(content.description),
],
),
//Sized Box
SizedBox(height: //whatever double),
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(Icons.accessibility),
Text('cool')
],
),
Text('something else'),
],
)
Columns take all the available height. Consider wrapping the Column inside Expanded with a Container of fixed height.
To make a Column take as much space as possible, set mainAxisSize: MainAxisSize.min. However all the widgets are packed up and all Alignments will have no effect.
So probably what you are looking for is to set the height of the Row with the the maximum height of its children widgets. This can be achieved by wrapping the Row with IntrinsicHeight.
Card(
child: IntrinsicHeight(
child: Row(
// ...
),
),
),

How to center only one element in a row of 2 elements in flutter

In my layout I have two Widgets in a row, one text and the an icon.
As shown below, assume that * refers to the icon, and using "-" to represent the row:
----------------------------
Text *
----------------------------
How do I make my text centered in the entire row, and the icon to the right end ?
The main thing you need to notice is that if you don't want to use Stack you should provide same width-consuming widgets both on left and right.
I would do this with either Expanded and Padding
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 32.0),
child: Text(
"Text",
textAlign: TextAlign.center,
),
),
),
Icon(Icons.add, size: 32.0,)
],
)
or with Row's mainAxisAlignment and a SizedBox
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
const SizedBox(width: 32.0),
Text("Text"),
Icon(Icons.add, size: 32.0)
],
)
or with Expanded and a SizedBox on the left instead of the padding :). The padding or extra container on the left is so that the textAlign will truly center the text in the row taking into account the space taken up by the Icon.
Simply use Expanded and Spacer widgets on left/right side and put your widget inside the Expanded:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Spacer(),
Text('Text'),
Expanded(
child: Text('*'),
),
),
],
),
Result:
1. Using Row (not very flexible though)
Row(
children: <Widget>[
Expanded(child: Center(child: Text('Center'))),
Text("#"),
],
)
2. Using Stack (flexible)
IntrinsicHeight(
child: Stack(
children: [
Align(child: Text('Center')),
Positioned(right: 0, child: Text('#')),
],
),
)
I found it necessary to use a Stack to get Text to be truly centered:
Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Stack(
alignment: Alignment.center,
children: [
Align(
alignment: Alignment.center,
child: Text('Text'),
),
Align(
alignment: Alignment.centerRight,
child: Text('*'),
)
],
),
],
);
For flexibility reasons I recommend to use Expanded widgets:
Row(
children: [
Expanded(flex: 1, child: Container()),
Expanded(
flex: 8,
child: Text('Your Text',
textAlign: TextAlign.center,
),
),
Expanded(flex: 1, child: IconButton(...))
],
)
For my case, I solved my centering problem by adjusting the flex property of the Spacer widget -
Row(children: [
Spacer(flex: 3),//3 was for my case, It might be changed for your widgets
Text('Center'),
Spacer(flex: 1),//1 was also for my case, It might be changed on for your widgets
Text("*")]);
Add another icon in the start and set the opacity to zero.
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CloseButton(
onPressed: () => Navigator.of(context).pop(),
),
Text('text',),
Opacity(
opacity: 0,
child: Icon(Icons.close),
),
],
)
This worked for me without Stack. But it is the other way around. "Text" goes to left "*" goes to center:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Text("text",
style: Theme.of(context).textTheme.caption),
),
Text("*"),
Spacer(),
],
)