如何在Flutter中将两个TextFormField属性彼此对齐

问题描述 投票:1回答:1

我需要帮助在Flutter中将两个TextFormFields彼此对齐而不是一个在另一个之上

我尝试过使用填充但它不起作用。

             new TextFormField(
              autovalidate: true,
              keyboardType: TextInputType.numberWithOptions(),
              controller: today,
              //Reminder to write an if statement calling the controller
              //The validator receives the text that the user has entered.
              decoration: new InputDecoration(
                fillColor: Colors.white,
                border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(5.0),
                    borderSide: new BorderSide()
                ),
                labelText: 'Today', //Label is used so that the text can either float or remain in place
                labelStyle: TextStyle(
                  fontFamily: 'Lato',
                  fontWeight: FontWeight.normal,
                  fontSize: 14.0,
                  color: Colors.grey,
                ),
              ),
              inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
            ),

            SizedBox(height: 15.0),



            new TextFormField(
              autovalidate: true,
              keyboardType: TextInputType.numberWithOptions(),
              controller: tomorrow,

              //Reminder to write an if statement calling the controller
              //The validator receives the text that the user has entered.
              decoration: new InputDecoration(
                fillColor: Colors.white,
                border: new OutlineInputBorder(
                    borderRadius: new BorderRadius.circular(5.0),
                    borderSide: new BorderSide()
                ),
                labelText: 'Tomorrow', //Label is used so that the text can either float or remain in place
                labelStyle: TextStyle(
                  fontFamily: 'Lato',
                  fontWeight: FontWeight.normal,
                  fontSize: 14.0,
                  color: Colors.grey,
                ),
              ),
              inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
            ),

我希望表单的大小更小并且彼此对齐,以便它们可以适合屏幕。

flutter flutter-layout
1个回答
1
投票

尝试使用Row而不是Column

        Row(children: [
                Expanded(
                  child: TextField(
                    decoration: InputDecoration(hintText: "TextField 1"),
                  ),
                ),
                SizedBox(
                  width: 20,
                ),
                Expanded(
                  child: TextField(
                    decoration: InputDecoration(hintText: "TextField 2"),
                  ),
                )
              ])

更多信息:https://medium.com/flutter-community/breaking-layouts-in-rows-and-columns-in-flutter-8ea1ce4c1316

© www.soinside.com 2019 - 2024. All rights reserved.