StackedIndex 导致失败的断言错误
StackedIndex is causing a failed assertion error
我正在尝试创建一个带有底部导航视图的应用程序。我在其中一个索引上更改了我的 StreamBuilder 的格式,自从我更改了那个 streamBuilder 后,我一直收到一个奇怪的错误:
RenderBox was not laid out: RenderRepaintBoundary#eae01
relayoutBoundary=up2 NEEDS-PAINT
'package:flutter/src/rendering/box.dart': Failed assertion: line 1694
pos 12: 'hasSize'
我也得到:
Failed assertion: line 1697 pos 12: '!_debugDoingThisLayout': is not
true.
我认为这是导致问题的构建和初始化:
@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 期望 return 一个小部件,但是当 doc["user"] != widget.auth.getUserId()
为假时,它永远不会 return 是一个值,也许添加一个带有 else 的虚拟 SizedBox.shrink 可能会有所帮助
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
}
我正在尝试创建一个带有底部导航视图的应用程序。我在其中一个索引上更改了我的 StreamBuilder 的格式,自从我更改了那个 streamBuilder 后,我一直收到一个奇怪的错误:
RenderBox was not laid out: RenderRepaintBoundary#eae01 relayoutBoundary=up2 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1694 pos 12: 'hasSize'
我也得到:
Failed assertion: line 1697 pos 12: '!_debugDoingThisLayout': is not true.
我认为这是导致问题的构建和初始化:
@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 期望 return 一个小部件,但是当 doc["user"] != widget.auth.getUserId()
为假时,它永远不会 return 是一个值,也许添加一个带有 else 的虚拟 SizedBox.shrink 可能会有所帮助
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
}