标签:textfield dart flutter android
我在制作一个Flutter应用程序时,其中有一个文本,并且可以正常工作,但是之后,当我添加文本字段时,我运行了该应用程序,发现该应用程序为空.
这是我的代码:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatelessWidget {
@override
Scaffold c = Scaffold(
body: Padding(
padding: const EdgeInsets.only(top:30.0),
child: new Row(
children: <Widget>[
new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Please enter a search term'
),
),
new Text(
'Text',
style: TextStyle(
fontSize: 20.0
),
),
],
),
),
);
@override
Widget build(BuildContext context) {
return c;
}
}
解决方法:
那是因为行容器不知道您的TextField小部件的大小
这是您得到的错误:
following function, which probably computed the invalid constraints in question:
flutter: _RenderDecoration._layout.layoutLineBox
(package:flutter/src/material/input_decorator.dart:808:11)
flutter: The offending constraints were:
flutter: BoxConstraints(w=Infinity, 0.0<=h<=379.0)
为了解决该问题,请在您的Textfield的父容器中为其设置一个宽度,如下所示:
Container(
width: 200.0,
child: new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Please enter a search term'),
),
),
但是它在屏幕上看起来很奇怪,因此您可以使用Flexible作为TextField和Text的父级进行改进
Scaffold c = Scaffold(
body: Padding(
padding: const EdgeInsets.only(top:30.0),
child: new Row(
children: <Widget>[
Flexible(
flex: 1,
child: new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Please enter a search term'
),
),
),
Flexible(
flex: 1,
child: new Text(
'Text',
style: TextStyle(
fontSize: 20.0
),
),
),
],
),
),
);
标签:textfield,dart,flutter,android 来源: https://codeday.me/bug/20191025/1925303.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。