0

I'm going to ask a question about flutter.

Looking at the capture, I want the height of the left and right containers to match the height of the longer one.

Since we have to fit a longer height, we want to implement it in a way that does not declare a height.

I hope someone can help me solve this.

Thank you.

this is a capture

this is a my code

import 'package:flutter/material.dart';

class RowTest extends StatefulWidget {
  @override
  _RowTestState createState() => _RowTestState();
}

class _RowTestState extends State<RowTest> {
  @override
  Widget build(BuildContext context) {
    final Size size = MediaQuery.of(context).size;

    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: const Text('simple Page'),
            ),
            body: ListView(
              shrinkWrap: true,
              children: <Widget>[
                Container(
                  color: Colors.blue,
                  child: Column(
                    children: <Widget>[
                      Container(
                          child: Column(
                        children: <Widget>[
                          for (int i = 0; i < 5; i++)
                            Row(
                              children: <Widget>[
                                Container(
                                  width: 141,
                                  margin: EdgeInsets.fromLTRB(size.width * 0.1,
                                      8, size.width * 0.05, 8),
                                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                                  decoration: BoxDecoration(
                                    border: Border.all(
                                      color: Color(0xff939393),
                                    ),
                                    color: Colors.red,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5)),
                                  ),
                                  child: Center(
                                    child: Text(
                                      'testededed',
                                      textAlign: TextAlign.center,
                                      textScaleFactor: 1.0,
                                      style: TextStyle(
                                          fontSize: 16,
                                          height: 1.5,
                                          color: Colors.white),
                                    ),
                                  ),
                                ),
                                Container(
                                  width: 141,
                                  margin: EdgeInsets.fromLTRB(size.width * 0.05,
                                      8, size.width * 0.1, 8),
                                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                                  decoration: BoxDecoration(
                                    border: Border.all(
                                      color: Color(0xff939393),
                                    ),
                                    color: Colors.red,
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(5)),
                                  ),
                                  child: Center(
                                    child: Text(
                                      'testesttaaaaaaaaaaaaest',
                                      textAlign: TextAlign.center,
                                      textScaleFactor: 1.0,
                                      style: TextStyle(
                                          fontSize: 16,
                                          height: 1.5,
                                          color: Colors.white),
                                    ),
                                  ),
                                ),
                              ],
                            )
                        ],
                      )),
                    ],
                  ),
                )
              ],
            )));
  }
}
5
  • i would sugget checking out gridView, this question is a good place to start: stackoverflow.com/questions/48405123/… Commented Mar 13, 2020 at 2:12
  • @steve kim, did you try GridView? Commented Mar 13, 2020 at 5:04
  • @Darish Yes. I tried with gridview. The height was kept constant, but it was too long. I am looking for a way to keep the height as text. Commented Mar 13, 2020 at 5:10
  • could you please post a screen shot of the gridview? what you mean by 'too long'?? could you explain it a little more Commented Mar 13, 2020 at 5:13
  • @Darish, Yes. This is the captured image link link If you check the image, 'too long' means that the height is too long compared to the length of the input text. I am looking for a way to change this height to fit the text height. Commented Mar 13, 2020 at 5:52

3 Answers 3

2

If you use: Row (with mainAxisSize max) > Expanded > Container, the container will fit the entire row

If you use: Column > Expanded > Container, the container will fit the entire column

If you use: Column > Row (with mainAxisSize max) > Expanded > Container, Container, Container, the 3 containers will fit the entire row with the same width

If you use: Scaffold > Stack (with fit> StackFit.expand) > Expanded > Container, the stack will try to fit the entire scaffold and the container will fit the stack

Sign up to request clarification or add additional context in comments.

Comments

0

Use crossAxisAlignment: CrossAxisAlignment.start to your Root Column of Tree

     Column(
              crossAxisAlignment: CrossAxisAlignment.start,

Comments

0

I'm sorry for the delay in the response because I had several things overlapped.

I solved it using IntrinsicHeight.

Thanks to everyone who helped with the comments.


class RowTest extends StatefulWidget {
  @override
  _RowTestState createState() => _RowTestState();
}

class _RowTestState extends State<RowTest> {
  @override
  Widget build(BuildContext context) {
    final Size size = MediaQuery.of(context).size;

    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: const Text('simple Page'),
            ),
            body: ListView(
              shrinkWrap: true,
              children: <Widget>[
                Container(
                  color: Colors.blue,
                  child: Column(
                    children: <Widget>[
                      Container(
                          child: Column(
                        children: <Widget>[
                          for (int i = 0; i < 5; i++)
                            IntrinsicHeight(
                              child: Row(
                                children: <Widget>[
                                  Container(
                                    width: 141,
                                    margin: EdgeInsets.fromLTRB(
                                        size.width * 0.1,
                                        8,
                                        size.width * 0.05,
                                        8),
                                    padding:
                                        EdgeInsets.fromLTRB(10, 10, 10, 10),
                                    decoration: BoxDecoration(
                                      border: Border.all(
                                        color: Color(0xff939393),
                                      ),
                                      color: Colors.red,
                                      borderRadius:
                                          BorderRadius.all(Radius.circular(5)),
                                    ),
                                    child: Center(
                                      child: Text(
                                        'testededed',
                                        textAlign: TextAlign.center,
                                        textScaleFactor: 1.0,
                                        style: TextStyle(
                                            fontSize: 16,
                                            height: 1.5,
                                            color: Colors.white),
                                      ),
                                    ),
                                  ),
                                  Container(
                                    width: 141,
                                    margin: EdgeInsets.fromLTRB(
                                        size.width * 0.05,
                                        8,
                                        size.width * 0.1,
                                        8),
                                    padding:
                                        EdgeInsets.fromLTRB(10, 10, 10, 10),
                                    decoration: BoxDecoration(
                                      border: Border.all(
                                        color: Color(0xff939393),
                                      ),
                                      color: Colors.red,
                                      borderRadius:
                                          BorderRadius.all(Radius.circular(5)),
                                    ),
                                    child: Center(
                                      child: Text(
                                        'testesttaaaaaaaaaaaaest',
                                        textAlign: TextAlign.center,
                                        textScaleFactor: 1.0,
                                        style: TextStyle(
                                            fontSize: 16,
                                            height: 1.5,
                                            color: Colors.white),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            )
                        ],
                      )),
                    ],
                  ),
                )
              ],
            )));
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.