【发布时间】:2021-09-29 22:51:36
【问题描述】:
我试图在每 3 个帖子之间显示一个横幅广告。但广告不显示。我认为该列表可能是空的,因为此列表是根据用户喜欢和保存的帖子构建的列表。
@override
Widget build(BuildContext context) {
return Expanded(
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 10.0),
children: [
StreamBuilderWrapper(
shrinkWrap: true,
stream: postRef
.where("bookmarks",
arrayContains: FirebaseAuth.instance.currentUser.uid)
.orderBy('timestamp', descending: true)
.snapshots(),
physics: NeverScrollableScrollPhysics(),
itemBuilder: (_, DocumentSnapshot snapshot) {
internetChecker(context);
Review posts = Review.fromJson(snapshot.data());
return Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Posts(post: posts),
);
},
),
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
return Column(
children: [
if (index % 3 == 0 && index != 0)
AdWidget(ad: ad)
],);})
]));
}
这是我第一次使用颤振,我是编码新手。我正在尝试显示横幅广告,但是,它们没有显示,也没有显示日志。这可能是由于我遇到的渲染错误:
The following _CastError was thrown during paint():
Null check operator used on a null value
The relevant error-causing widget was:
ListView
When the exception was thrown, this was the stack:
#0 RenderViewportBase._paintContents
(package:flutter/src/rendering/viewport.dart:653:25)
#1 RenderViewportBase.paint
(package:flutter/src/rendering/viewport.dart:645:7)
#2 RenderObject._paintWithContext
(package:flutter/src/rendering/object.dart:2317:7)
#3 PaintingContext._repaintCompositedChild
(package:flutter/src/rendering/object.dart:139:11)
#4 PaintingContext.repaintCompositedChild
(package:flutter/src/rendering/object.dart:100:5)
...
The following RenderObject was being processed when the exception was
fired:
RenderViewport#ae00e
... needs compositing
... parentData: <none> (can use size)
... constraints: BoxConstraints(w=360.0, h=507.0)
... layer: OffsetLayer#0dfc7 DETACHED
... engine layer: Null#007db
... offset: Offset(0.0, 0.0)
... size: Size(360.0, 507.0)
... axisDirection: down
... crossAxisDirection: right
... offset: ScrollPositionWithSingleContext#1c5d2(offset: 0.0, range:
null..null, viewport: 507.0, ScrollableState,
AlwaysScrollableScrollPhysics
-> ClampingScrollPhysics -> RangeMaintainingScrollPhysics,
IdleScrollActivity#40f4c, ScrollDirection.idle)
我对小部件和视图感到困惑。请帮帮我!谢谢!
【问题讨论】:
标签: firebase flutter flutter-futurebuilder banner-ads