How to make a large distance between widgets - flutter

Tell me how to correctly make a large indent between RedeemButton() and button ? I need to make such an indent as shown in the screenshot.
body
Column(childre: [
const RedeemButton(
textStyle: constants.Styles.smallBookTextStyleWhite,
buttonStyle: constants.Styles.smallMediumTextStyleWhite),
const Padding(
padding: EdgeInsets.only(bottom: 50),
child: Text(
'Hello',
style: TextStyle(
color: Colors.white,
),
),
),

As you are using a Column Widget, to separate your 2 children you can use the mainAxisAlignment set to spaceBetween, like this:
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [...
If you want a spacific distance number, you can set a SizedBox Widget between them, and set a height that fits your need in a height property

You can use Spacer widget if you want.

Related

Starting a Column from the center of its parent

I am trying to implement a Column within a parent, but the first child of the Column should be centered vertically within the Column's parent, by using MainAxisAlignment.center the whole Column will be centered and if I have more than one child in the Column, the first child won't be in the center.
Here is what i have tried.
child: CircleAvatar(
radius: 146,
backgroundColor: Colors.black87,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('11:06',
style: TextStyle(
fontSize: 70,
)),
Icon(Icons.restart_alt),
],
),
),
Here is what i got.enter image description here
As you see the text is not in the center because the icon pushes it up a bit.
You can wrap your column in another column containing an Expanded widget followed by your column, also wrapped in an Expanded widget.
You can use some padding. I am not aware of a way to get the size of the parent and do like 50% of it like in CSS so you have to keep that in mind. However you can make calculations relative to the viewport height with MediaQuery.of(context).size.height.
Use Align inside Stack (not perfect, still needs adjustment).
CircleAvatar(
...
child: Stack(
alignment: Alignment.center,
children: const [
Text('11:06', style: TextStyle(fontSize: 70)),
Align(
alignment: Alignment(0, 0.4),
child: Icon(Icons.restart_alt),
),
],
),
)

Flexible widget didn't work on text widget flutter

I'm trying to use flexible on my text cause it's overflow but for some reason expanded or neither flexible didn't work. But it work on other text widget on different screen. Anyone know why ? How can I fix this ?
return Row(
children: [
/// Ticket Details
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
/// Ticket Title
Flexible(
child: Text(
ticketData['title'],
style: primaryColor700Style.copyWith(
fontSize: fontSize18,
),
),
),
SizedBox(height: 8),
/// Date Created
Text(
'Created : ' +
DateFormat('d MMM y').format(
DateTime.parse(
ticketData['date_created'].toDate().toString(),
),
),
style: primaryColor400Style.copyWith(
fontSize: fontSize12,
),
),
],
),
/// Urgent Icon
if (ticketData['is_urgent'])
Icon(
Icons.warning_rounded,
size: 35,
color: warningColor,
),
],
);
Wrap the column with flexible
Row(
children: [
Flexible(
child: Column(
children:[
Text(),
]
)
)
]
)
Row takes infinite width, To get available width row for next children you can wrap Expanded/ Flexibile/ fixed width widget. You can check this doc more about.
You can find this from Layout algorithm on Row
Expanded, to indicate children that should take all the remaining room.
Flexible, to indicate children that should share the remaining room but that may by sized smaller (leaving some remaining room unused).

In Flutter, non-english language in Text Widget has strange margin value

I'm a developer who just started flutter.
While using the flutter to configure a screen, I visited to ask about something strange.
I set the crossAxisAlignment option to center in the Row widget and set one of the children to Text.
The code is here.
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: 22.0),
Text(
'Test',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal),
),
],
),
Then, I created the text in Korean.
The result is the same as the picture below, but as you can see, the upper and lower margins of the letters are slightly different (it is slightly skewed down).
If this is English, the top and bottom margins are the same as follows.
This issue is the same for all Widgets written in Korean, but does anyone know the solution to this?
It seems there might be a similar issue logged here.
The proposed solution (although there is no input from OP to indicate it worked), is to pass textAlign: TextAlign.center to your Text Widget. This might help as crossAxisAlignment is a property applied via Row and Column to their children, whereas TextAlign is applied to the Text widget directly. Perhaps in conjunction with crossAxisAlignment it might produce the desired result.
That or you might want to experiment with padding on the Text widget. You can do this by wrapping your Text widget in a Padding widget or in a Container widget. See below.
Padding
Padding(
padding: EdgeInsets.fromLTRB(20, 20, 20, 20),
child: Text('Padding Via Padding Widget',
style: TextStyle(fontSize: 22))),
)
Container
Container(
padding: EdgeInsets.fromLTRB(20, 20, 20, 20),
child: Text('Padding Via Container Widget',
style: TextStyle(fontSize: 22)),
)

Make Container fill TableCell in Flutter

I'm trying to make a Table with two cells of the same width and height, so that the height depends on the size of the content. However, the smaller TableCell always shrinks:
This is what I'm trying to implement:
Here's the code:
Table(
children: [
TableRow(
children: [
TableCell(
child: Container(
color: Colors.green,
child: Text(
'long text long text long text long text long text long text long text'),
),
),
TableCell(
child: Container(
color: Colors.orange,
child: Text('short text'),
),
),
],
)
],
),
P.S. I could solve it by adding verticalAlignment: TableCellVerticalAlignment.fill, to the smaller cell, but any cell can be the smaller one, depending on the content. When I add this line to both cells, the whole table disappears. The only bypass I could imagine is to calculate the length of the content and find the smaller cell, but I wonder if there is a way to implement this UI directly with Flutter.
Would appreciate any help.
1. Row with IntrinsicHeight
IntrinsicHeight limits the height of the Row to the content size, which however is considered a 'relatively expensive' approach and is not recommended.
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Container(
color: Colors.green,
child: Text(
'long text long text long text long text long text',
))),
Expanded(
child: Container(
color: Colors.orange,
child: Text(
'short text',
))),
],
),
),
2. Table with TableCellVerticalAlignment.fill
As mentioned in the question, the .fill option must not be used in the largest TableCell, because in this case the TableRow will have zero height. This is the preferred solution, because it doesn't have the 'expensiveness' issue of the previous one.
final texts = ['long text long text long text long text long text', 'short text'];
final colors = [Colors.green, Colors.orange];
// find the longest text and its index
final max = texts.asMap().entries.reduce(
(a, b) => (a.value.length > b.value.length) ? a : b,
);
return Table(children: [
TableRow(
children: texts
.asMap()
.entries
.map((e) => TableCell(
// use .fill in all cells except the largest
verticalAlignment: (e.key != max.key)
? TableCellVerticalAlignment.fill
: TableCellVerticalAlignment.top,
child: Container(
color: colors[e.key],
child: Text(e.value),
)))
.toList(),
),
]);

Flutter - Text overflow in Row when another widget in the same Row is flexible

I want to implement a Row having two Text widgets and a middle line like this:
The following code is my current implementation.
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Text',
overflow: TextOverflow.ellipsis
),
Expanded(
child: Container(
padding: EdgeInsets.only(left: 16, right: 16),
height: 1,
child: Container(
color: Colors.black
)
),
),
Text(
'Right Text'
)
]
)
The problem of this code is that the left text overflows if it is long like this:
The expected output is:
Wrapping the first Text widget with a Flexible can solve the overflow issue, but the output is not the same as the expected output because of the Expanded widget that fills the space between two Text widgets with a line.
How can I achieve this? Any help is highly appreciated!