Mokhtar Ghaleb
Mokhtar Ghaleb

Reputation: 463

how to solve Flutter RenderConstrainedBox object was given an infinite size during layout

I am working with Flutter and I am trying to show Admob Banner at the top of body before GridView Widget The problem is when advertisement is loaded it make the following issue

======== Exception caught by rendering library ===================================================== The following assertion was thrown during performLayout(): RenderConstrainedBox object was given an infinite size during layout.

I am sure it's only UI issue because if I run the app with only widget (admob or gridview) it works perfectly but when add both I have the issue

here is my code

 return SafeArea(
                  child: Column(
                children: [
                  _isBannerAdReady
                      ? AdWidget(ad: _bannerAd)
                      : Text("no Ads"),
                  Expanded(
                    child: GridView.builder(
                        itemCount: examsList.length,
                        gridDelegate:
                            SliverGridDelegateWithFixedCrossAxisCount(
                          crossAxisCount: 2,
                          crossAxisSpacing: 5.0,
                          mainAxisSpacing: 5.0,
                        ),
                        itemBuilder: (ctx, index) {
                          return Card(
                            child: Column(
                              children: [
                                Expanded(
                                  flex: 1,
                                  child: Image.network(
                                    examsList[index].image!!,
                                    width: 150,
                                    height: 150,
                                  ),
                                ),
                                Expanded(
                                    flex: 1,
                                    child: Text(examsList[index].name!!))
                              ],
                            ),
                          );
                        }),
                  )
                ],
              ));

Upvotes: 0

Views: 381

Answers (1)

Z-Soroush
Z-Soroush

Reputation: 344

I think it's because adWidget(ad:...) has no width and height. try to wrap it with a Container(width: double.infinity,height:50)

Upvotes: 1

Related Questions