I am trying to reduce the spaces around an expanded in my flutter project as it is taking a lot of space in all directions.
I have 2 expanded with texts in them and 2 Forms with input from users. They are taking almost 3 lines of wasted white space. I tried to reduce the spacing as much as possible by aligning to the left but it is still showing the same.
I initially tried to have them in a table but did not work because I have builder inside.
Here is the simplified code:
Builder(builder: (context) {
return Container(
width: double
.infinity, // Set the width of the container to be as wide as possible
child: SingleChildScrollView(
child: Column(
children: [
Card(
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text('No.'),
],
),
],
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text('No.'),
],
),
],
),
),
Expanded(
child: Column(
children: const [
Text('New Log'),
],
crossAxisAlignment: CrossAxisAlignment.start,
),
),
],
),
),
Card(
child: Row(
children: [
Expanded(
child: Column(
children: [
Text('1'),
],
),
),
Expanded(
child: Column(
children: [
Text('12'),
],
),
),
Form(
child: Expanded(
child: Column(
children: [
TextFormField(),
TextFormField(),
OutlinedButton(
onPressed: () async {},
child: _selectedButtons.contains(1)
? const Icon(FluentSystemIcons
.ic_fluent_checkmark_circle_filled)
: const Icon(FluentSystemIcons
.ic_fluent_checkmark_circle_regular),
),
],
),
),
),
],
),
),
],
),
),
);
});
Here is the current outcome:
Here is the required outcome:
My question: how can I reduce the space in the expanded to make all on the same line.
2
Answers
You need to use
Row
instead ofColumn
on forTextFiled
.And there are top level nested widgets like
Row>Expanded>Column
for single item can be remove.You have used so many nested Rows and Columns which are redundant. Check below code for your desired result with screenshot.