How can I manage alignment with multiple rows and columns? - flutter

I'm trying to make a card with some elements.
However it is hard to locate elements in right place with multiple rows and columns.
I tried with mainAxisAlignment, crossAxisAlignment, SizedBox, Expanded and so on.
Especially using Expanded make my widget disappear unlike my expectation.
How can I locate element to right place?
What I did
What I want
child: Container(
padding: EdgeInsets.all(10),
child: Column(
children:[
Text('1'),
Container(
child: Row(
children:[
ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Container(
width: 70,
height: 70,
color: Color(0xffD9D9D9),
),
),
Column(
children:[
Row(
children:[
Text('2'),
Text('3'),
Text('4'),
],
),
Row(
children:[
Text('5'),
Text('6')
]
),
Row(
children:[
Text('7'),
Text('8'),
Text('9'),
Text('10'),
],
),
],
),
],
),
),
],
),
),

Here you go, this should be work as you wanted. i've tried to run it and yep it work
Container(
padding: const EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Text('1'),
Row(
children: [
Flexible(
child: ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Container(
width: 70,
height: 70,
color: const Color(0xffD9D9D9),
),
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
PaddingText(text: "2"),
PaddingText(text: "3")
],
),
Row(
children: [
PaddingText(text: "4"),
],
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
PaddingText(text: "5"),
PaddingText(text: "6")
],
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
PaddingText(text: "7"),
PaddingText(text: "8")
],
),
Row(
children: [
PaddingText(text: "9"),
PaddingText(text: "10")
],
),
],
),
],
),
),
],
),
],
),
),
and dont forget to add this to your project
class PaddingText extends StatelessWidget {
PaddingText({Key? key, required this.text}) : super(key: key);
String text;
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Text(text),
);
}
}

This must work
Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children:[
Text('1'),
Container(
child: Row(
children:[
ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Container(
width: 70,
height: 70,
color: Color(0xffD9D9D9),
),
),
Expanded(
child: Column(
children:[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children:[
Expanded(
child: Row(
children: [
Text('2'),
Text('3'),
],
),
),
Expanded(child: Row(
children: [
Text('4')
],
)),
],
),
Row(
children:[
Text('5'),
Text('6')
]
),
Row(
children:[
Expanded(child: Row(
children: [
Text('7'),
Text('8'),
],
)),
Expanded(child: Row(
children: [
Text('9'),
Text('10'),
],
))
],
),
],
),
),
],
),
),
],
),
)

Related

Flutter expand row inside of a column

I have the following layout:
Row ->
Column
Padding ->
Column ->
Row ->// this one is only taking as much space as it needs
Text
Image
Text
Row
I need the row in the second column to take the whole width of the column it is wrapped in.
No matter how much I look for the answer wrapping different widgets into Flexible and Expanded doesn't help.
here is the code:
Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
Column(
children: [
CircleAvatar(
radius: 25,
child: Image(
image: getCategoryImage(task.type),
),
)
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
// mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(task.title, style: Theme.of(context).textTheme.headlineMedium,),
const Image(
width: 20, image: AssetImage("assets/icons/task/tickbox.png"))
],
),
Text(generateBirdList(task.assignedBirds), style: Theme.of(context).textTheme.titleSmall,),
Row(
children: [
],
)
],
),
),
],
),
),
Container(
color: Colors.amber,
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
Container(
color: Colors.blueAccent,
child: CircleAvatar(
radius: 25,
child: Image.network(
"https://st.depositphotos.com/1909187/2297/i/950/depositphotos_22971972-stock-photo-blank-white-male-head-front.jpg",
),
),
),
Expanded(
child: Container(
color: Colors.green,
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
// mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"task.title",
style: Theme.of(context).textTheme.headlineMedium,
),
Image.network(
"https://st.depositphotos.com/1909187/2297/i/950/depositphotos_22971972-stock-photo-blank-white-male-head-front.jpg",
width: 20,
)
],
),
Text(
"Bla bla bla text",
style: Theme.of(context).textTheme.titleSmall,
),
Row(
children: [],
)
],
),
),
),
],
),
),

How to make a rectangles in this order?

How to make a rectangles in this order at flutter ?
Look here
Column(
children: [
Expanded(
child: Container(
color: Colors.blue,
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Container(
color: Colors.green,
),
),
Expanded(
child: Container(
color: Colors.red,
),
),
],
),
),
Expanded(
child: Row(
children: [
Expanded(
child: Container(
color: Colors.yellow,
),
),
Expanded(
child: Container(
color: Colors.purple,
),
),
],
),
),
],
);
The correct approach is to wrap a container and two rows in a column.
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Container(
color: Colors.blue,
),
),
Expanded(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
color: Colors.red
),
),
Expanded(
child: Container(
color: Colors.green
),
),
],
),
),
Expanded(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Container(
color: Colors.yellow
),
),
Expanded(
child: Container(
color: Colors.orange
),
),
],
),
),
],
)
It can be something like this:
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text('Top Rectangle'),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(child: Text('Row 1 - Col 1'),),
Expanded(child: Text('Row 1 - Col 2'),),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(child: Text('Row 2 - Col 1'),),
Expanded(child: Text('Row 2 - Col 2'),),
],
)
],
),
Or this:
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text('Top Rectangle'),
),
Container(
height: 400,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Text('Row 1 - Col 1'),
),
Expanded(
child: Text('Row 1 - Col 2'),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expanded(
child: Text('Row 2 - Col 1'),
),
Expanded(
child: Text('Row 2 - Col 2'),
),
],
)
],
),
),
],
),
It's not a good idea to have a bunch of Expanded widgets in a parent widget, you should have Containers or similar widgets and give them fixed or dynamically calculated heights, then you can have an Expanded which gets all remaining space

Flutter Row Column Layout not full width

I want to have "Priority" on the right side of my screen but I cant get the Column to be full width. MainAxisAlignment doesn't work to expand the field.
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.task_alt_sharp , size: 50.0),
SizedBox(width: 20.0),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children:[
Row(
mainAxisAlignment: MainAxisAlignment.end,
//crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(task.tag,style: const TextStyle(fontSize: 20, color: Colors.blue)),
Text(" Priority "),
Text(" Priority "),
],
),
SizedBox(height: 5.0),
Text(task.omschrijving),
]
),
)
]
),
you need to expand your container
Column(children: [
Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.transform, size: 50.0),
SizedBox(width: 20.0),
Expanded( // here changes need
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
//crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("P645",
style: const TextStyle(
fontSize: 20, color: Colors.blue)),
Text(" Priority "),
],
),
SizedBox(height: 5.0),
Text(task.omschrijving),
]),
),
)
],
),
],
))
])
Try below code hope its help to you. refer Row() class here refer layout here
Column(
children: [
Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(
Icons.task_alt_sharp,
size: 50.0,
),
SizedBox(width: 20.0),
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.blueAccent,
),
),
child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
//crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'task.tag',
style: const TextStyle(
fontSize: 20,
color: Colors.blue,
),
),
Text(" Priority "),
Text(" Priority "),
],
),
SizedBox(height: 5.0),
Text('task.omschrijving'),
],
),
),
],
),
],
),
),
],
),
Result Screen->

A RenderFlex overflowed by 260 pixels on the bottom. - ListTile

I'm trying to add column in ListTile trailing but it gives me render flow error, plus it not align to it's title.
here is my code
SizedBox(
height: MediaQuery.of(context).size.height * 0.55,
child: ListTile(
title: Padding(
padding: const EdgeInsets.only(left: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Date"),
SizedBox20(),
Text("Token no"),
SizedBox20(),
Text("Token Issuance Date"),
SizedBox20(),
Text("Token Issuance Time"),
SizedBox20(),
Text("Calling Place"),
SizedBox20(),
Text("Total Fee"),
SizedBox20(),
Text("Advance"),
SizedBox20(),
Text("Remaining"),
SizedBox20(),
Text("Status"),
SizedBox20(),
],
),
),
trailing: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text("5/11/2021"),
SizedBox20(),
Text("36"),
SizedBox20(),
Text("2/11/2021"),
SizedBox20(),
Text("12:15:00 PM"),
SizedBox20(),
Text("Desk 07"),
SizedBox20(),
Text("PKR. 1,000/-"),
SizedBox20(),
Text("PKR. 200/-"),
SizedBox20(),
Text("PKR. 800/-"),
SizedBox40(),
Text("Unattended"),
// SizedBox20(),
],
),
),
),
I want it like title Date and trailing 5/11/2021 should be align in one line, and same for all.
it should look like
here is my code output
please help how to fix it.
Try below code hope its helpful to you. used Column and Rows Widget instead of ListTile
SingleChildScrollView(
padding: EdgeInsets.all(10),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Date"),
Text("5/11/2021"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Token no"),
Text("36"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Token Issuance Date"),
Text("2/11/2021"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Token Issuance Time"),
Text("12:15:00 PM"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Calling Place"),
Text("Desk 07"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Total Fee"),
Text("PKR. 1,000/-"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Advance"),
Text("PKR. 200/-"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Remaining"),
Text("PKR. 800/-"),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Status"),
Text("Unattended"),
],
),
SizedBox(
height: 10,
),
],
),
);
Your result Screen ->

Flutter Flexible in Card

i'm having problems using flexible widget in card. I used Constrained Box but i'd like to use a widget without setting width. But if i use Flexible widget, card doesn't show up anymore.
My goal is to make text use all the available space without setting a constant width
Here is my code:
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:wemaind_mobile_app/pages/tasks/tasks_page.dart';
import 'package:wemaind_mobile_app/theme/colors.dart';
import 'board_entity.dart';
import 'task_counter.dart';
class BoardWidget extends StatelessWidget {
final BoardEntity board;
static const colors = WemaindColors();
BoardWidget(this.board);
#override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return ConstrainedBox(constraints: BoxConstraints(maxWidth: 500, minWidth: 280, minHeight: 300),
child:GestureDetector(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context)
{return TasksPage(board: board);
}));
},
child:
Container(
height: MediaQuery.of(context).size.height * 0.2,
child: Card(margin: EdgeInsets.only(top: 0, bottom: 16, left: 16, right: 16),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(crossAxisAlignment: CrossAxisAlignment.baseline, textBaseline: TextBaseline.alphabetic,
children: [
Flexible(
child: Text(board.name,
style: theme.textTheme.headline2,
)),
if (board.bookmarked) Icon(Icons.star, color: colors.orange),
],
),
Row(children:[
Flexible(
child: Text(board.role.toUpperCase(),style: theme.textTheme.headline4,overflow: TextOverflow.ellipsis,)),
]),
]),
Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start,children: [
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Text(board.tasks.all.toString(), style: theme.textTheme.headline1),
Icon(Icons.more_vert, color: colors.blue.shade800, size: 32),
]),
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Text('TASK'.toUpperCase(), style: theme.textTheme.headline5),
])
]),
]),
Table(
children: [
TableRow(children: [
TaskCounter('PRIORITARI', Icons.bolt, colors.orange, board.tasks.prioritized),
TaskCounter('IN SCADENZA', Icons.alarm, colors.red, board.tasks.expiring),
Container(),
]),
TableRow(children: [
TaskCounter('MIEI', Icons.person, theme.accentColor, board.tasks.owned),
TaskCounter('DEL TEAM', Icons.group, theme.accentColor, board.tasks.teamOwned),
TaskCounter('IN AVVIO', Icons.calendar_today, theme.accentColor, board.tasks.starting),
])
]
),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
),
),
),
)
)
);
}
}
Hope someone can help me :)
try to use the space smarter. this code will save you from your problems
class BoardWidget extends StatelessWidget {
// final BoardEntity board;
// static const colors = WemaindColors();
// BoardWidget(this.board);
#override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
body: SafeArea(
child: GestureDetector(
// onTap: () {
// Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context)
// {return TasksPage(board: board);
// }));
// },
child:
Container(
height: 300,
width: 400,
child: Card(margin: EdgeInsets.only(top: 0, bottom: 16, left: 16, right: 16),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Expanded(
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Expanded(
child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Row(crossAxisAlignment: CrossAxisAlignment.baseline, textBaseline: TextBaseline.alphabetic,
children: [
Expanded(
child: Text("board.name",
),
),
if (true) Icon(Icons.star, color: Colors.orange),
],
),
),
Expanded(
child: Row(children:[
Expanded(child: Text("board.role.toUpperCase()", overflow: TextOverflow.ellipsis,)),
]),
),
]),
),
Expanded(
child: Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start,children: [
Expanded(
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Expanded(child: Text("board.tasks.all.toString()")),
Icon(Icons.more_vert, color: Colors.blue.shade800, size: 32),
]),
),
Expanded(
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Text('TASK'.toUpperCase()),
]),
)
]),
),
]),
),
Table(
children: [
TableRow(children: [
Container(child: Icon(Icons.bolt)),
Container(child: Icon(Icons.alarm)),
Container(),
]),
TableRow(children: [
Container(child: Icon(Icons.person),),
Container(child: Icon(Icons.group),),
Container(child: Icon(Icons.calendar_today),),
])
]
),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
),
),
),
)
),
),
);
}
}