flutter - 如何在 Flutter 中将两个 TextFormField 属性并排对齐

标签 flutter flutter-layout

我需要帮助在 Flutter 中对齐两个 TextFormField,而不是一个在另一个之上

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

             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],
            ),

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

最佳答案

尝试使用 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

关于flutter - 如何在 Flutter 中将两个 TextFormField 属性并排对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55526228/

相关文章:

flutter - Flutter-如何在ListView构建器中列出forEach()值?

flutter - Flutter Dart HTTP POST请求主体在服务器端为空

flutter - 如何解决 "The argument type ' ImageProvider<Object >' can' t be assigned to the parameter type 'ImageProvider' ?"in flutter

flutter - 自定义 FlexibleSpaceBar 小部件

flutter - 在flutter中弹出屏幕后如何调用函数来更新值?

flutter - Tabbar抖动中的向后处理按钮

flutter - 为什么我的自建窗口小部件的命名参数在Flutter中不起作用?

flutter - 在 BLoC 中触发初始事件

当指针到达边缘时 flutter 滚动屏幕

dart - Flutter 页面 View 不显示两张幻灯片