TextField inside of Row causes layout exception: Unable to calculate size

后端 未结 8 1588
后悔当初
后悔当初 2020-11-28 04:08

I’m getting a rendering exception that I don’t understand how to fix. I’m attempting to create a column that has 3 rows.

Row [Image]

Row [TextField ]

<
相关标签:
8条回答
  • 2020-11-28 05:05

    As @Asif Shiraz mentioned I had same issue and solved this by Wrapping Column in a Flexible, here like this,,

    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
            title: 'Flutter Demo',
            theme: new ThemeData(
              primarySwatch: Colors.blue,
            ),
            home: new Scaffold(
              body: Row(
                children: <Widget>[
                  Flexible(
                      child: Column(
                    children: <Widget>[
                      Container(
                        child: TextField(),
                      )
                      //container
                    ],
                  ))
                ],
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
              ),
            ));
      }
    }
    
    0 讨论(0)
  • 2020-11-28 05:06

    (I assume you're using a Row because you want to put other widgets beside the TextField in the future.)

    The Row widget wants to determine the intrinsic size of its non-flexible children so it knows how much space that it has left for the flexible ones. However, TextField doesn't have an intrinsic width; it only knows how to size itself to the full width of its parent container. Try wrapping it in a Flexible or Expanded to tell the Row that you're expecting the TextField to take up the remaining space:

          new Row(
            children: <Widget>[
              new Flexible(
                child: new TextField(
                  decoration: const InputDecoration(helperText: "Enter App ID"),
                  style: Theme.of(context).textTheme.body1,
                ),
              ),
            ],
          ),
    
    0 讨论(0)
提交回复
热议问题