flutter - 可水平滚动的 Multine `TextFormField`
问题描述
以下将多行TextFormField
换行长行。
TextFormField(
keyboardType: TextInputType.multiline,
maxLines: null,
)
但是,我试图避免换行,而是让它水平滚动。所以,我在SingleChildScrollView
周围添加了一个TextFormField
:
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,
),
),
)
推荐阅读
- android - Android - 无法解析符号“devbrackets”
- sql-server - SQL SERVER 的“SET ROWCOUNT”何时会停止影响 INSERT、DELETE 和 UPDATE 操作?
- kubernetes - 在部署新环境之前停止 gitlab CI 中先前部署的环境
- javascript - wdio/selenium-standalone-service 返回 getMacChromiumEdgeDriverArchitecture 错误
- java - Spring Security @RolesAllowed/@Secured 和 ROLE_ADMIN
- python - 如何在 PyQt5 中使用 QCamera 点击照片?
- powershell - 有效地找到最早的日期
- c++ - 使用提升精神表达
- amazon-web-services - 收到错误为 ERROR:连接期间出错:获取 http://docker:2375/v1.40/info: dial tcp: lookup docker on 172.31.0.2:53: no such host
- html - 页脚的正确 html 和 css 代码