我试图将两个文本字段放在一行中,以便它们排成一行,但我似乎遇到了以下错误,我似乎无法理解我在这里做错了什么。感谢帮助。
导入“package:flutter/material.dart”;
void main(){
runApp(
MaterialApp(
title: 'Planet',
home:Home()
)
);
}
class Home extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return HomeState();
}
}
class HomeState extends State<Home>{
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text(
'Weight on Planet x',
),
centerTitle: true,
),
body:Container(
alignment: Alignment.topCenter,
child: ListView(
padding: const EdgeInsets.all(2.5),
children: <Widget>[
Image.asset('images/planet.png',height: 133.0,width: 200.0,),
Container(
margin: const EdgeInsets.all(3.0),
child: Row(
children: <Widget>[
TextField(
controller: null,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Your weight on Earth',
hintText: 'In Pounds',
icon: Icon(Icons.person_outline)
),
),
TextField(
controller: null,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Your weight on Earth',
hintText: 'In Pounds',
icon: Icon(Icons.person_outline)
),
)
],
),
)
],
),
)
);
}
出现以下错误
抛出另一个异常:RenderBox 未布局:_RenderDecoration#3373c relayoutBoundary=up10 NEEDS-PAINT
最佳答案
尝试为 TextField
父 Container
提供一些有限的 width
。默认情况下,TextFields
占据其父级可用的整个空间,在本例中是无限的。
或者,如果您希望每个 TextField
具有自定义宽度,您可以使用单独的 Containers
。
关于dart - 为什么将 TextField 放在 In Row 中时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55297768/