I am trying to have bannerAds displayed between every 3 posts. However, I am getting renderig error:
Exception caught by rendering library ===================================================== The following assertion was thrown during performLayout(): 'package:flutter/src/rendering/object.dart': Failed assertion: line 1706 pos 12: '!_debugDoingThisLayout': is not true.
Either the assertion indicates an error in the framework itself, or we
should provide substantially more information in this error message to help
you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The line the error throws is the ListView.seperated().
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
child: StreamBuilder(
stream: postRef
.where("bookmarks",
arrayContains: FirebaseAuth.instance.currentUser.uid)
.orderBy('timestamp', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.separated(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
internetChecker(context);
Review posts =
Review.fromJson(snapshot.data.docs[index].data());
return Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Posts(post: posts),
);},
separatorBuilder: (context, index) {
return Column(
children: [
if (index % 2 == 0 && index != 0)
AdWidget(ad: ad)
],);});
} else if (snapshot.hasError) {
return Center(
child: Text(Languages.of(context).errorOcc),
);
} else {
return Container();}},))],);//)]);
}
It also stopped displaying posts after 3 posts. How do i fix that? Thank you!
EDIT Edited the whole class. Now no logs and still no bannerAds. I followed all the instructions.
class SavedPageState extends State with MainPageStateMixin { final GlobalKey scaffoldKey = GlobalKey();
Map<String, BannerAd> ads = <String, BannerAd>{};
BannerAd myBanner1, myBanner2, myBanner3;
BannerAdListener adListener;
bool isAdLoaded = false;
List<String> testDeviceIds = ["@@@@@@@@@@@@@@@@@@@@@@"];
@override
void initState() {
new RequestConfiguration(testDeviceIds: testDeviceIds);
myBanner1 = BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
size: AdSize.banner,
request: AdRequest(),
listener: BannerAdListener(
onAdLoaded: (_) {
setState(() {
isAdLoaded = true;
});
},
onAdFailedToLoad: (myBanner1, err) {
print('Failed to load a banner ad: ${err.message}');
isAdLoaded = false;
}));
final AdWidget adWidget1 = AdWidget(ad: myBanner1);
adWidget1.createElement();
myBanner1.load();
myBanner2 = BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
size: AdSize.banner,
request: AdRequest(),
listener: BannerAdListener(
onAdLoaded: (_) {
setState(() {
isAdLoaded = true;
});
},
onAdFailedToLoad: (myBanner2, err) {
print('Failed to load a banner ad: ${err.message}');
isAdLoaded = false;
}));
final AdWidget adWidget2 = AdWidget(ad: myBanner2);
adWidget2.createElement();
myBanner2.load();
myBanner3 = BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
size: AdSize.banner,
request: AdRequest(),
listener: BannerAdListener(
onAdLoaded: (_) {
setState(() {
isAdLoaded = true;
});
},
onAdFailedToLoad: (myBanner3, err) {
print('Failed to load a banner ad: ${err.message}');
isAdLoaded = false;
}));
final AdWidget adWidget3 = AdWidget(ad: myBanner3);
adWidget3.createElement();
myBanner3.load();
super.initState();
}
@override
void onPageVisible() {
MainScreen.of(context).params = AppBarParams(
actions: <Widget>[
Icon(
Icons.bookmarks,
color: Colors.white,
),
],
backgroundColor: Colors.red,
);
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
child: StreamBuilder(
stream: postRef
.where("bookmarks",
arrayContains: FirebaseAuth.instance.currentUser.uid)
.orderBy('timestamp', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.separated(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
internetChecker(context);
Review posts =
Review.fromJson(snapshot.data.docs[index].data());
return Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Posts(post: posts),
);},
separatorBuilder: (context, index) {
(index %3 ==0 && index != 0) ?
Container(
child: AdWidget(ad: ads['myBanner$index']),
constraints: BoxConstraints(
maxHeight: 100,
maxWidth: MediaQuery.of(context).size.width,
minHeight: 50,
minWidth: MediaQuery.of(context).size.width,
),
) :
Container();
return Container();
});
} else if (snapshot.hasError) {
return Center(
child: Text(Languages.of(context).errorOcc),
);
} else {
return Container();}},))],);//)]);
}
@override
void dispose() {
myBanner1.dispose();
myBanner2.dispose();
myBanner3.dispose();
super.dispose();
}
Help needed desperately! This is the only issue that is holding us back. Thanks!