【发布时间】:2021-02-22 18:14:18
【问题描述】:
这是我的 Flutter 应用 UI: before
在我从 Firebase 获取数据后,一切都消失了,只显示 appBar。 构建方法:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Recipes Menu'),
leading: Icon(Icons.menu),
),
backgroundColor: Colors.deepPurple[50],
body: ListView(
children: [
SizedBox(height: 16,),
search(),
SizedBox(height: 8,),
SizedBox(height:6),
// foodCard(),
const Divider(),
], ), ); }
这是我的代码:
Widget foodCard() {
return Padding(
padding: const EdgeInsets.all(10.0),
child: InkWell (
onTap: (){
Navigator.push(context,
MaterialPageRoute(builder: (context) => RecipeScreen()));},
child: Column(
mainAxisSize:MainAxisSize.min,
children: [
Expanded(
ListView.builder(itemCount: allRecipes.length,
itemBuilder: (BuildContext context, int index){
return Material(
color: Colors.white,
elevation: 8.0,
shadowColor: Colors.blueGrey,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0)),
child: ClipRRect(
borderRadius: BorderRadius.only(topLeft: Radius.circular(20.0)),
child: FittedBox(
child: Material(
color: Colors.white,
elevation: 8.0,
shadowColor: Colors.blueGrey,
child: Row(
children: [
Container(
width: 250,
height: 250,
child: FadeInImage.memoryNetwork(
placeholder: kTransparentImage, height: 200,
fit: BoxFit.fitHeight,
alignment: Alignment.topLeft,
image:
"https://images-gmi-pmc.edge-generalmills.com/087d17eb-500e-4b26-abd1-4f9ffa96a2c6.jpg")),
Container(
padding: const EdgeInsets.all(8.0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(children: [
Text(allRecipes[index].name,
style: TextStyle(color: Colors.black54),
),
Text(allRecipes[index].about,
softWrap: true,),
Divider(),
ButtonBar( alignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
child: Text('Like',
style: TextStyle(color: Colors.deepPurple)),
onPressed: () {},
),
FlatButton(
child: Text('Dislike',
style: TextStyle(color: Colors.deepPurple)), onPressed: () {}, ),
] ]),))],)))),);},), ],), ) );
}
我有这个很长的错误:
ListView
lib\screens\menuScreen.dart:47 ══════════════════════════════════════════════════ ══════════════════════════════ 引发了另一个异常:RenderBox 未布局:RenderSemanticsAnnotations#e62d4 relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
════════ 渲染库捕获的异常═══════════════════════════════ RenderBox 未布置:RenderSemanticsAnnotations#e62d4 relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': 断言失败:第 1702 行第 12 行:'hasSize' 相关的导致错误的小部件是 列表视图
错误信息:
RenderFlex#7f39a relayoutBoundary=up10 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE(creator: Column ← _PointerListener ← Listener ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← _RawMouseRegion ← MouseRegion ← Semantics ← _FocusMarker ← Focus ← _ActionsMarker ← ⋯, parentData: <none> (can use size), constraints: BoxConstraints(w=340.0, 0.0<=h<=Infinity), size: MISSING, direction: vertical, mainAxisAlignment: start, mainAxisSize: max, crossAxisAlignment: center, verticalDirection: down)
创建者信息设置为: 列 ← _PointerListener ← 监听器 ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← _RawMouseRegion ← MouseRegion ← 语义 ← _FocusMarker ← Focus ← _ActionsMarker ← ⋯ 另见:https://flutter.dev/layout/ 如果以上方法都不足以解决此问题,请不要犹豫提交错误: https://github.com/flutter/flutter/issues/new?template=BUG.md 相关的导致错误的小部件是: 专栏
报错信息过长,怎么办?
【问题讨论】:
-
对不起,为什么
ListView里面有ListView? -
在给定无限高度的情况下,垂直视口出现错误,所以我找到了这个解决方案,所以我尝试了一下。 @ikerfah
-
尝试将第一个
ListView替换为Column,然后将第二个ListView替换为Expanded,然后告诉我发生了什么。 -
我现在做了,但 UI 除了 appBar 之外什么都没有显示,我更新了问题,还有另一个错误 @ikerfah
-
将
mainAxisSize:MainAxisSize.min添加到Column。你现在可以更新代码吗?
标签: flutter