多个水平可滚动的' TextFormField '



下面将多行TextFormField换行。

TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
)

然而,我试图避免包装,而让它水平滚动。因此,我在TextFormField周围添加了一个SingleChildScrollView:

SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
),
)

这个收益率

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
Assertion failed:
file:///..../flutter/lib/src/material/input_decorator.dart:948:7
layoutConstraints.maxWidth < double.infinity
"An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.nThis
happens when the parent widget does not provide a finite width constraint. For example, if the
InputDecorator is contained by a Row, then its width must be constrained. An Expanded widget or a
SizedBox can be used to constrain the width of the InputDecorator or the TextField that contains
it."

// Use ConstrainedBox as a Child of SingleChildScrollView with width and height constraint so you TextFormFeild can become horizontally scrollable . 
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: ConstrainedBox(
constraints: BoxConstraints.expand(width: 2000,height: 200),
child: TextFormField(
maxLines: null,

),
),
)

最新更新