我正在扑朔迷离地为我的新闻项目编写代码。我已从一个教程中复制了此代码。但是我的代码中有异常和错误。有人请帮助我解决问题。我的代码是:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(97),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 32),
decoration: BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(
width: 0.5,
color: Colors.white,
))),
child: AppBar(
title: Text(
'News',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 30,
),
),
),
// height: 100,
)
]),
),
body: ListView.builder(
itemBuilder: (context, index) {
return _listItem(index);
},
itemCount: _newsInApp.length,
));
}
我的控制台输出是:
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Running Xcode build...
Xcode build done. 22.9s
Syncing files to device iPhone 11 Pro Max...
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performLayout():
flutter: RenderFlex children have non-zero flex but incoming width constraints are unbounded.
答案 0 :(得分:1)
将您的listItem
小部件方法替换为:
_listItem(index) {
return Padding(
padding: const EdgeInsets.only(left: 15, top: 1, right: 1, bottom: 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 15),
child: Text(
_newsInApp[index].title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),
IconButton(
iconSize: 16,
color: Colors.black26,
icon: Icon(Icons.arrow_forward_ios),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {},
),
),
),
],
),
);
}