gpt4 book ai didi

flutter - StackedIndex导致失败的断言错误

转载 作者:行者123 更新时间:2023-12-03 03:33:08 27 4
gpt4 key购买 nike

我正在尝试使用底部导航 View 创建应用程序。自从更改streamBuilder以来,我就更改了其中一个索引的StreamBuilder格式,但我一直收到一个奇怪的错误:

RenderBox was not laid out: RenderRepaintBoundary#eae01relayoutBoundary=up2 NEEDS-PAINT'package:flutter/src/rendering/box.dart': Failed assertion: line 1694pos 12: 'hasSize'


我也得到:

Failed assertion: line 1697 pos 12: '!_debugDoingThisLayout': is nottrue.


这是我认为导致问题的生成和初始化:
@override
void initState() {
super.initState();
// TODO: implement initState
_outerStream = Firestore.instance
.collection('posts/player/post')
.orderBy('time', descending: true)
.snapshots()
.take(2);

_innerStream =
Firestore.instance.collection('posts/player/post').snapshots();
}

@override
Widget build(BuildContext context) {
return new Container(
child: StreamBuilder<QuerySnapshot>(
stream: _outerStream,
builder: (context, snapshot) {
if (!snapshot.hasData) return Container(child: Text('Loading...'));
final int highLightCount = snapshot.data.documents.length;
return StreamBuilder<QuerySnapshot>(
stream: _innerStream,
builder: (context, snapshot) {
if (!snapshot.hasData)
return Container(child: Text('There are no current posts'));
return ListView(
physics: const AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: getPostItems(snapshot),
);
},
);
},
),
);
}
这段代码现在肯定是一团糟,但是这里使用了其他方法:
getPostItems(AsyncSnapshot<QuerySnapshot> snapshot) {
return snapshot.data.documents.map((doc) => getListItem(doc)).toList();
}

Widget getListItem(var doc) {
getProfUrl(doc);
getDownUrl(doc);

VideoPlayerController _videoPlayerController;
_videoPlayerController = VideoPlayerController.network(downUrl)
..initialize();
_videoPlayerController.setLooping(true);
_videoPlayerController.play();

if (doc["user"] != widget.auth.getUserId()) {
print("will show");
if (doc["type"] == "image") {
return new Column(
children: <Widget>[
new GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new playerViewProfilePageIndex(
widget.auth, doc["user"])),
);
},
child: new ListTile(
title: new Text(doc["title"]),
subtitle: new Text(doc["description"].toString()),
leading: new Container(
width: 44.0,
height: 44.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill, image: NetworkImage(profUrl)),
),
),
),
),
new Padding(
padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
child: new Center(
child: new AspectRatio(
aspectRatio: 1 / 1,
child: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.fill,
alignment: FractionalOffset.topCenter,
image: new NetworkImage(downUrl),
)),
),
),
),
),
],
);
} else {
return new Column(children: <Widget>[
new ListTile(
title: new Text(doc["title"]),
subtitle: new Text(doc["description"].toString()),
leading: new Container(
width: 44.0,
height: 44.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill, image: NetworkImage(profUrl)),
))),
new Padding(
padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
child: new Center(
child: new AspectRatio(
aspectRatio: 500 / 500,
child: VideoPlayer(_videoPlayerController),
),
),
),
]);
}
}
}

最佳答案

getListItem期望返回一个Widget,但是当doc["user"] != widget.auth.getUserId()为false时,它永远不会返回值,也许添加一个虚拟的SizedBox.shrink和else可能会有所帮助

Widget getListItem(var doc) {
getProfUrl(doc);
getDownUrl(doc);

VideoPlayerController _videoPlayerController;
_videoPlayerController = VideoPlayerController.network(downUrl)
..initialize();
_videoPlayerController.setLooping(true);
_videoPlayerController.play();

if (doc["user"] != widget.auth.getUserId()) {
print("will show");
if (doc["type"] == "image") {
return new Column(
children: <Widget>[
new GestureDetector(
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new playerViewProfilePageIndex(
widget.auth, doc["user"])),
);
},
child: new ListTile(
title: new Text(doc["title"]),
subtitle: new Text(doc["description"].toString()),
leading: new Container(
width: 44.0,
height: 44.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill, image: NetworkImage(profUrl)),
),
),
),
),
new Padding(
padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
child: new Center(
child: new AspectRatio(
aspectRatio: 1 / 1,
child: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.fill,
alignment: FractionalOffset.topCenter,
image: new NetworkImage(downUrl),
)),
),
),
),
),
],
);
} else {
return new Column(children: <Widget>[
new ListTile(
title: new Text(doc["title"]),
subtitle: new Text(doc["description"].toString()),
leading: new Container(
width: 44.0,
height: 44.0,
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill, image: NetworkImage(profUrl)),
))),
new Padding(
padding: EdgeInsets.fromLTRB(4, 4, 4, 4),
child: new Center(
child: new AspectRatio(
aspectRatio: 500 / 500,
child: VideoPlayer(_videoPlayerController),
),
),
),
]);
}
} else return const SizedBox.shrink(); //return a Widget when the if is false
}

关于flutter - StackedIndex导致失败的断言错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62630802/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com