首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在颤动中的ButtonBar中添加TextField

在颤动中的ButtonBar中添加TextField
EN

Stack Overflow用户
提问于 2021-07-08 19:24:19
回答 3查看 54关注 0票数 0

我使用ButtonBarColumn中将按钮排列成一行。

在ButtonBar中,我放入了一个TextField:

代码语言:javascript
复制
              ButtonBar
              (
                mainAxisSize: MainAxisSize.min,
                children: <Widget>
                [
                  Expanded(
                      child: TextField(
                         maxLines: 8,
                         decoration: InputDecoration.collapsed(hintText: "Enter your text here"),
                      ),
                  ),
                ],
              ),

此ButtonBar位于列中。我能够以这种方式显示正常的按钮和文本。只有这个TextField在制造问题:

代码语言:javascript
复制
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderRepaintBoundary#3888e NEEDS-LAYOUT NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'

The relevant error-causing widget was
TextField
lib/main.dart:138`
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2021-07-08 19:39:24

您可以像这样使用

代码语言:javascript
复制
SizedBox(
      height: 40,
      width: MediaQuery.of(context).size.width,
      child: TextField(
        decoration: InputDecoration(),
      ),
    );
票数 1
EN

Stack Overflow用户

发布于 2021-07-08 19:55:57

您可以将TextField包装在ConstrainedBox中,如下所示:

代码语言:javascript
复制
ConstrainedBox(
      constraints: BoxConstraints(
         maxHeight: 40 ,
         maxWidth: MediaQuery.of(context).size.width,
         ),
      width: MediaQuery.of(context).size.width,
      child: TextField(
        decoration: InputDecoration(),
      ),
    );
票数 1
EN

Stack Overflow用户

发布于 2021-07-08 19:58:20

请使用put Textfield in Container,并像这样给它们提供宽度和高度:

代码语言:javascript
复制
ButtonBar(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Container(
                  height: 60,
                  width: 200,
                  child: TextField(
                    maxLines: 8,
                    decoration: InputDecoration.collapsed(
                        hintText: "Enter your text here"),
                  ),
                ),
              ],
            ),
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68300715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档