首页 > 解决方案 > Flutter:带有 TextFormField 标题和副标题的 ListTile

问题描述

当我尝试使用包含 TextFormField 的标题创建 ListTile 时,我无法添加副标题,否则它会爆炸。

这是一个简单的例子:

ListTile(
  title: TextFormField(
    initialValue: 'foo',
  ),
  subtitle: const Text('bar'),
),

当我将此片段添加到我的代码并运行它时,我得到:

I/flutter (20366):   RenderParagraph#3f385 relayoutBoundary=up8 NEEDS-PAINT
I/flutter (20366): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (20366): Another exception was thrown: RenderBox was not laid out: _RenderListTile#76527 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (20366): Another exception was thrown: RenderBox was not laid out: RenderPadding#61d3e relayoutBoundary=up6 NEEDS-PAINT
I/flutter (20366): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#eaf9a relayoutBoundary=up5 NEEDS-PAINT
I/flutter (20366): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#479d1 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (20366): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#1419c relayoutBoundary=up3 NEEDS-PAINT
I/flutter (20366): Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 310 pos 12: 'child.hasSize': is not true.
I/flutter (20366): Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
D/        (20366): HostConnection::get() New Host Connection established 0xd0a0ab40, tid 20389
W/        (20366): Unrecognized GLES max version string in extensions:

这是一个错误还是这只是一个无效的请求?

我的最终目标是创建一个显示标签和单位的 TextFormField。例如,用户可以在其中键入以英尺为单位的测量距离值的字段。

标签: flutter

解决方案


推荐阅读