flutter - 在 Flutter 的 ButtonBar 中添加 TextField
问题描述
我曾经ButtonBar
在Column
.
在 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`
解决方案
你可以这样使用
SizedBox(
height: 40,
width: MediaQuery.of(context).size.width,
child: TextField(
decoration: InputDecoration(),
),
);
推荐阅读
- android - 模拟器:模拟器:错误:x86_64 仿真当前需要硬件加速
- django - uwsgi 处理请求的时间不能超过一分钟
- ansible - Ansible 循环/条件
- elasticsearch - 使用logstash从json中提取数字并发送到elasticsearch
- c# - Birds Eye View Bing Maps 不适用于 WPF 应用程序 C#
- aws-lambda - 基于 cookie 的两个源之间的 Lambda@Edge 路由
- php - 如何在 WordPress 中的作者存档页面下列出帖子?
- c# - RestSharp - 您的浏览器当前设置为阻止 cookie
- c# - 为什么在调用 lambda 表达式中的委托函数时保留参数 i?
- maven - 由于缺少执行数据文件,在具有模块且没有单元测试的项目中跳过 JaCoCo 执行