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

Why are there gaps between Column's Text and TextField children? (How to remove the gaps?)

This is how the gaps look like
awkward gaps

I want to remove the gaps.
The image I attached is from a pop-up modal, and here’s how the content look like:

Container(
        height: MediaQuery.of(context).size.height * 0.67,
        width: MediaQuery.of(context).size.width * 0.50,
        child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const Expanded(
                    child: Text("Kode Indikator",style: TextStyle(fontSize: 12),),
                  ),
                  SizedBox(
                    width: MediaQuery.of(context).size.width * 0.25,
                    height:40,
                    child: TextField(
                      readOnly: true,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderRadius:
                          BorderRadius.all(Radius.circular(5)),
                        ),
                        labelText: dataList[index].xxtsmkKode,
                      ),
                    ),
                  ),
                  const Expanded(
                    child: Text("Kriteria",style: TextStyle(fontSize: 12),),
                  ),
                  SizedBox(
                    width: MediaQuery.of(context).size.width * 0.25,
                    height:40,
                    child: TextField(
                      readOnly: true,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderRadius:
                          BorderRadius.all(Radius.circular(5)),
                        ),
                        labelText: dataList[index].xxtsmkKriteria,
                      ),
                    ),
                  ),
                  const Expanded(
                    child: Text("Grup Indikator",style: TextStyle(fontSize: 12),),
                  ),
                  SizedBox(
                    width: MediaQuery.of(context).size.width * 0.25,
                    height:40,
                    child: TextField(
                      readOnly: true,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderRadius:
                          BorderRadius.all(Radius.circular(5)),
                        ),
                        labelText: dataList[index].xxtsmiGroupIndikator,
                      ),
                    ),
                  ),
                  const Expanded(
                    child: Text("Indikator",style: TextStyle(fontSize: 12),),
                  ),
                  SizedBox(
                    width: MediaQuery.of(context).size.width * 0.25,
                    height:40,
                    child: TextField(
                      readOnly: true,
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                          borderRadius:
                          BorderRadius.all(Radius.circular(5)),
                        ),
                        labelText: dataList[index].xxtsmiIndikator,
                      ),
                    ),
                  ),

              ],),
              Column(
                children: const [

                  Expanded(
                    child: Text("Kode Indikator",style: TextStyle(fontSize: 12),),
                  )
              ],),


          ]
        )
        )

I’ll appreciate it if you can also help me on layouting tips, as I’m still new with Flutter and how to make this layout with the gaps between textfield-text instead of text-textfield right now. I think I’ve been using Expanded and Flexible wrongly but I don’t know exactly.

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

I tried using Stack widget, but ended up with the elements on top of each other.

EDIT:
Ok so after more trying, I figured out it’s because of the Expanded taking up as many space as possible. When I changed Expanded to SizedBox it finally looked like what I wanted.
But I still want to know if it’s possible to do it without SizedBox, as I hard-coded the height..

>Solution :

Please remove expanded Widget and remove gap.
Like this

Container(
      child: Row(mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [
    Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const Text(
          "Kode Indikator",
          style: TextStyle(fontSize: 12),
        ),
        SizedBox(
          width: MediaQuery.of(context).size.width * 0.25,
          height: 40,
          child: const TextField(
            readOnly: true,
            decoration: InputDecoration(
              border: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(5)),
              ),
              labelText: 'a',
            ),
          ),
        ),
        const Text(
          "Kriteria",
          style: TextStyle(fontSize: 12),
        ),
        SizedBox(
          width: MediaQuery.of(context).size.width * 0.25,
          height: 40,
          child: const TextField(
            readOnly: true,
            decoration: InputDecoration(
              border: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(5)),
              ),
              labelText: 'a',
            ),
          ),
        ),
        Text(
          "Grup Indikator",
          style: TextStyle(fontSize: 12),
        ),
        SizedBox(
          width: MediaQuery.of(context).size.width * 0.25,
          height: 40,
          child: const TextField(
            readOnly: true,
            decoration: InputDecoration(
              border: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(5)),
              ),
              labelText: 'b',
            ),
          ),
        ),
        Text(
          "Indikator",
          style: TextStyle(fontSize: 12),
        ),
        SizedBox(
          width: MediaQuery.of(context).size.width * 0.25,
          height: 40,
          child: const TextField(
            readOnly: true,
            decoration: InputDecoration(
              border: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(5)),
              ),
              labelText: 'c',
            ),
          ),
        ),
      ],
    ),
    const Column(
      children: [
        Text(
          "Kode Indikator",
          style: TextStyle(fontSize: 12),
        )
      ],
    ),
  ]))
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