How to set up a numerical input and not have body disappear in flutter?

0

So, I'm trying to get a numerical input for a price range set up. And yet no matter what I do from looking elsewhere, when I run it, the body is blank. Here's what I'm trying to get it to look like: price input range

And here's my code for it:

Align(
              alignment: Alignment.centerLeft,
              child: Container(
                color: Color(0xFFffffff),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    new Text(
                      '\$',
                    ),
                    TextField(
                      controller: _textFieldController,
                      keyboardType: TextInputType.number,
                    ),
                    new Text(
                      'To',
                    ),
                    new Text(
                      '\$',
                    ),
                    TextField(
                      controller: _textFieldController,
                      keyboardType: TextInputType.number,
                    ),
                  ],
                ),
              ),
            ),
flutter
asked on Stack Overflow Apr 27, 2020 by ladyc

1 Answer

0

You have to wrap your Textfield with Expanded widget in following way.

 Expanded(
                    child: TextField(
                      controller: _textFieldController,
                      keyboardType: TextInputType.number,
                    ),
                  ),

But if you want to limit your TextField widget's width then wrap TextField in following way.

  Container(
                    width: 50,
                    child: Row(
                      children: [
                        Expanded(
                          child: TextField(
                            controller: _textFieldController,
                            keyboardType: TextInputType.number,
                          ),
                        ),
                      ],
                    ),
                  ),

Note: Here you are using same controller for two TextField, which will not give you correct value of textfield, so have to provide different controllers.

answered on Stack Overflow Apr 27, 2020 by Viren V Varasadiya

User contributions licensed under CC BY-SA 3.0