flutter 自定义控件不能放输入框
本人初学flutter ,今天要自定义一个输入框控件,结果遇到一个奇怪的问题,自定义的空间框里,不能放入输入框,放入就报错,代码如下,是不是哪里冲突里?
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SearchTextInput extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return Container(
height: 20,
decoration:
BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(5))),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
decoration: BoxDecoration(
border:
Border(right: BorderSide(color: Colors.black, width: 1))),
child: Row(
children: <Widget>[Text("北京"), Icon(Icons.arrow_drop_down)],
),
),
Padding(
padding: EdgeInsets.only(
left: 5,
),
// child: Text("---sssssssssssssssssssssssssssss"), //这行代码可以
child: TextField( ), //这行代码不行
),
],
),
);
}
}
直接只放一个输入框,没有问题,一旦放了布局控件,就报错,错误内容:
Performing hot reload...
Syncing files to device Android SDK built for x86...
I/flutter (15752): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (15752): The following assertion was thrown during performLayout():
I/flutter (15752): BoxConstraints forces an infinite width.
I/flutter (15752): These invalid constraints were provided to RenderRepaintBoundary's layout() function by the
I/flutter (15752): following function, which probably computed the invalid constraints in question:
I/flutter (15752): _RenderDecoration._layout.layoutLineBox (package:flutter/src/material/input_decorator.dart:815:11)
I/flutter (15752): The offending constraints were:
I/flutter (15752): BoxConstraints(w=Infinity, 0.0<=h<=120.0)
环境: window 10 家庭版,
代码位置: https://github.com/alvin19876...
希望有大神指点一下
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在TextField外面包一层Expanded
https://stackoverflow.com/que...
同样的问题。。。