Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to align multiple Column inside Row which is inside SingleChildScrollView

Read the commented line to understand my problem

import 'package:flutter/material.dart';

class DemoTest extends StatefulWidget {
  const DemoTest({super.key});

  @override
  State<DemoTest> createState() => _DemoTestState();
}

class _DemoTestState extends State<DemoTest> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Row(
        children: [
          //this column sshould  start from top
          Column(
              children: List.generate(300, (index) {
            return Text(index.toString());
          })),
          //this column sshould  start from bottom

          Column(
              children: List.generate(100, (index) {
            return Text(index.toString());
          })),
          //this column again should be start from top
          Column(
              // mainAxisAlignment: MainAxisAlignment.end,
              children: List.generate(100, (index) {
            return Text(index.toString());
          }))
        ],
      ),
    );
  }
}
what   expecting is like:
Column 1        Column 2       Column 3
0                               0
1                               1
2                               2
3                               3
4                               .
5                               .
.
.
100                0            99
.                  1
.                  .
.                  .
299                99

SingleChildScrollview -> Row -> 3 COLUMNS (Every column has diffrent alignment). Align is not working, cant add expanded because of singleChildScrollView.
Hope i able to explain every thing

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can try this

class _DemoTestState extends State<DemoTest> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: IntrinsicHeight(
        child: Row(
          children: [
            Column(
                children: List.generate(300, (index) {
                  return Text(index.toString());
                })),
            Column(
              mainAxisAlignment: MainAxisAlignment.end,
                children: List.generate(100, (index) {
                  return Text(index.toString());
                })),
            Column(
                children: List.generate(100, (index) {
                  return Text(index.toString());
                }))
          ],
        ),
      ),
    );
  }
}

To give some explanation. By wrapping the Row in an IntrinsicHeight it makes it that all the Row‘s children will get the height of the heighest child instead of the children becoming as small as possible. This way, putting a mainAxisAlignment to end to the second column will get the desired result.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading