Dart 如何设置文本字段宽度?

Dart 如何设置文本字段宽度?,dart,flutter,Dart,Flutter,我将TextField嵌套在一个宽度为10.0的容器中,但TextField仍然占据了整个设备的宽度 Widget _reviewBody() { return SliverToBoxAdapter( child: Container( width: 10.0, padding: EdgeInsets.only(bottom: 30.0), child: TextField( onChanged: (text

我将TextField嵌套在一个宽度为10.0的容器中,但TextField仍然占据了整个设备的宽度

Widget _reviewBody() {
    return SliverToBoxAdapter(
      child: Container(
        width: 10.0,
        padding: EdgeInsets.only(bottom: 30.0),
        child: TextField(
          onChanged: (text) {
            setState(() {
              reviewBody = text;
            });
          },
          keyboardType: TextInputType.multiline,
          maxLines: null,
          decoration: InputDecoration(
            hintText: 'Add your thoughts here',
            hintStyle: TextStyle(color: Burnt.hintTextColor),
            enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Burnt.lightGrey)),
            focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Burnt.primaryLight, width: 1.0)),
          ),
          textAlign: TextAlign.center,
        ),
      ),
    );
  }
如何设置文本字段宽度

编辑:原来SliveToboxAdapter很神奇,所以我使用媒体查询在容器上设置了一个填充。也许我不应该使用SliveToboxadatper,如果有人能解释正确的方法,那就太好了,谢谢


Edit2:事实上我想出了一个更好的主意,我只是把我的容器放在一行中,并把行放在我的100.0宽容器的中心

Container(
        margin: EdgeInsets.only(top: 30, left: 30, right: 30),
        width: MediaQuery.of(context).size.width,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
            TextField(
                decoration: InputDecoration(
                    hintText: "Inserisci la tua email",
                    hintStyle: TextStyle(fontSize: 20),
                    labelText: "Email",
                    labelStyle: TextStyle(
                        color: Utils.blackColor, fontSize: 20),
                    border: UnderlineInputBorder(
                        borderSide: BorderSide(color: Utils.greyColor)),
                    focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.grey,
                            style: BorderStyle.solid))),
                controller: nameController,
                style: TextStyle(fontSize: 23)),
            Padding(padding: EdgeInsets.only(top: 20)),
          ],
        ),
      ),
容器(
边距:仅限边集(顶部:30,左侧:30,右侧:30),
宽度:MediaQuery.of(context).size.width,
子:列(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
文本字段(
装饰:输入装饰(
hintText:“Inserisci la tua电子邮件”,
hintStyle:TextStyle(字体大小:20),
labelText:“电子邮件”,
标签样式:文本样式(
颜色:Utils.blackColor,字体大小:20),
边框:下划线输入边框(
borderSide:borderSide(颜色:Utils.greyColor)),
FocusedOrder:下划线输入边框(
边界边(
颜色:颜色。灰色,
样式:BorderStyle.solid),
控制器:名称控制器,
样式:TextStyle(fontSize:23)),
填充(填充:仅限边集(顶部:20)),
],
),
),

我试过这样的方法

Container(
        margin: EdgeInsets.only(top: 30, left: 30, right: 30),
        width: MediaQuery.of(context).size.width,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
            TextField(
                decoration: InputDecoration(
                    hintText: "Inserisci la tua email",
                    hintStyle: TextStyle(fontSize: 20),
                    labelText: "Email",
                    labelStyle: TextStyle(
                        color: Utils.blackColor, fontSize: 20),
                    border: UnderlineInputBorder(
                        borderSide: BorderSide(color: Utils.greyColor)),
                    focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            color: Colors.grey,
                            style: BorderStyle.solid))),
                controller: nameController,
                style: TextStyle(fontSize: 23)),
            Padding(padding: EdgeInsets.only(top: 20)),
          ],
        ),
      ),
容器(
边距:仅限边集(顶部:30,左侧:30,右侧:30),
宽度:MediaQuery.of(context).size.width,
子:列(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
文本字段(
装饰:输入装饰(
hintText:“Inserisci la tua电子邮件”,
hintStyle:TextStyle(字体大小:20),
labelText:“电子邮件”,
标签样式:文本样式(
颜色:Utils.blackColor,字体大小:20),
边框:下划线输入边框(
borderSide:borderSide(颜色:Utils.greyColor)),
FocusedOrder:下划线输入边框(
边界边(
颜色:颜色。灰色,
样式:BorderStyle.solid),
控制器:名称控制器,
样式:TextStyle(fontSize:23)),
填充(填充:仅限边集(顶部:20)),
],
),
),

pu textfield和列中的容器作为子对象,然后使用flexible widget包装子对象,将flexible属性作为子对象,将textfield和容器作为子对象包装到列中,然后使用flexible widget包装子对象,将flexible属性作为子对象,是否尝试使用SizedBox?是否尝试使用SizedBox?