首页 > 解决方案 > 在 Flutter 的 ButtonBar 中添加 TextField

问题描述

我曾经ButtonBarColumn.

在 ButtonBar 我放了一个 TextField:

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

此 ButtonBar 位于列中。我能够以这种方式显示普通按钮和文本。只有这个 TextField 会产生问题:

════════════════════════════════════════════════════════════════════════════════

════════ 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`

标签: flutterdart

解决方案


你可以这样使用

SizedBox(
      height: 40,
      width: MediaQuery.of(context).size.width,
      child: TextField(
        decoration: InputDecoration(),
      ),
    );

推荐阅读