RenderBox 未布局,Flutter Listview Builder 未显示
Posted
技术标签:
【中文标题】RenderBox 未布局,Flutter Listview Builder 未显示【英文标题】:RenderBox was not laid out, Flutter Listview Builder not Displaying 【发布时间】:2021-06-03 04:05:15 【问题描述】:我是这个框架的新手,我无法显示 ListViewBuilder 项目。我在控制台中收到此错误
════════ 渲染库捕获的异常═══════════════════════════════ RenderBox 未布置:RenderRepaintBoundary#f28ee relayoutBoundary=up14 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': 断言失败:第 1785 行第 12 行:'hasSize'
class _ViewCartState extends State<ViewCart>
List<dynamic> cartData;
@override
void initState()
super.initState();
APIService apiService = new APIService();
apiService.apiCall().then((value) async
setState(()
cartData = value.data.result.cartData;
print(cartData);
);
);
@override
Widget build(BuildContext context)
loadData();
var veg;
return Scaffold(
appBar: AppBar(
iconTheme: IconThemeData(
color: kHintColor, //change your color here
),
title: Text("Cart Page", style: Theme.of(context).textTheme.bodyText1),
),
body: Stack(
children: <Widget>[
SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
// width: 500, //if this Height I'm Not giving Then List not Displaying.
padding: EdgeInsets.all(20.0),
color: Theme.of(context).cardColor,
child: Text("Your Cart Items",
style: Theme.of(context)
.textTheme
.headline6
.copyWith(
color: Color(0xff616161),
letterSpacing: 0.67)),
),
Divider(
color: Theme.of(context).cardColor,
thickness: 1.0,
),
Padding(
padding: const EdgeInsets.all(10),
child: ListView.builder(
itemCount: cartData.length,
itemBuilder: (context, index) => Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
cartItemListTile(context, cartData, index),
],
),
),
),
),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
BottomBar(
text: "go to next page"),
],
),
),
],
),
);
这是我的 ListView builder 返回函数
ListTile cartItemListTile(
BuildContext context, List<dynamic> cartData, int index)
int qty;
return ListTile(
title: Padding(
padding: EdgeInsets.only(top: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Image.network(
cartData[index].itemimage.image,
height: 40,
width: 40,
),
]),
),
);
请帮帮我。我无法设置容器高度,因为该列表中还有很多字段。
【问题讨论】:
【参考方案1】:在 Listview.builder 中 添加这两行..
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
【讨论】:
非常感谢以上是关于RenderBox 未布局,Flutter Listview Builder 未显示的主要内容,如果未能解决你的问题,请参考以下文章
溢出框 RenderBox 未布局:RenderRepaintBoundary#7796e 需要-布局需要-油漆
Flutter:RenderBox 未布置:RenderRepaintBoundary#58c65 relayoutBoundary=up1 NEEDS-PAINT
Flutter:未布置RenderBox:RenderRepaintBoundary#58c65 relayoutBoundary = up1 NEEDS-PAINT