Placing Dynamic Width in a Container

Asked

Viewed 371 times

-1

Hello! I’m wanting to use this control to replace the Dropdown, but I realized that its width command 'does not work', maybe by the context external to it, I didn’t get it right. Because I want to actually make dynamic with double value that I have already prepared, but even putting in the fixed value there 200.0 does not obey:

inserir a descrição da imagem aqui

Flutter code:

SizedBox(
              height: 34.0,
              child: GridView(
                padding: EdgeInsets.symmetric(vertical: 4.0),
                scrollDirection: Axis.horizontal,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 1,
                    mainAxisSpacing: 8.0,
                    childAspectRatio: 0.5),
                children: todostimes.times.map((s) {
                  return GestureDetector(
                      onTap: () {
                        setState(() {
                          _timeSelecionado = s;
                        });
                      },
                      child: Align(
                        alignment: Alignment.topCenter,
                        child: Container(
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.all(Radius.circular(5.0)),
                              border: Border.all(
                                  color: s == _timeSelecionado
                                      ? Colors.deepPurple
                                      : Colors.grey[400],
                                  width: 2.0)
                          ),
                          width: 200.0, //valor fixo
                          //convertDouble(s['TimeNome'].toString()) ,
                          padding: EdgeInsets.all(2.0),
                          child: Text(s['TimeNome'],
                              style: new TextStyle(
                                fontSize: 15.0,
                              )
                          ),
                        ),
                      ));
                }).toList(),
              ),
            )

Github): https://github.com/danielgmrs/flutter_estudos/blob/master/disparar.dart

  • Provide complete executable code so we can test/run your problem. Facilitates analysis.

  • Complete code: https://github.com/danielgmrs/flutter_estudos/blob/master/disparar.dart

2 answers

-1

High-sounding!

nos Width and Height try to use: Mediaquery.of(context).size.

if used by percentage: Mediaquery.of(context).size.width * 0.5 to 50%

  • Thanks Alex! But unfortunately not changed... I debug and the width of this command there is more than 400.0 and has no effect

-1


Solved my problem, I just traded GRIDVIEW for LISTVIEW !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.