Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter : 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1895 pos 16: 'constraints.hasBoundedHeight': is not true

SliverToBoxAdapter(
                  child: Column(
                    children: [
                      SizedBox(
                        child: StreamBuilder(
                            stream: data.snapshots(),
                            builder: (context, snapshot) {
                              if (snapshot.connectionState == ConnectionState.waiting) {
                                const Center(child: CircularProgressIndicator(color: Colors.blue));
                              }
                              if (snapshot.hasData) {
                                return ListView.builder(
                                  physics: const BouncingScrollPhysics(parent: BouncingScrollPhysics()),
                                  padding: EdgeInsets.zero,
                                  scrollDirection: Axis.horizontal,
                                  shrinkWrap: true,
                                  itemCount: snapshot.data?.docs.length,
                                  itemBuilder: (context, index) {
                                    final DocumentSnapshot records = snapshot.data!.docs[index];
                                    return Container();
                                  },
                                );
                              }
                              return Container();
                            }),
                      ),
                    ],
                  ),
                ),

Here is a flutter code as I execute in a listview.builder . It worked before I added the scrollDirection: Axis.horizontal property to the listview.builder .

I get an error 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1895 pos 16: 'constraints.hasBoundedHeight': is not true.

How can I fix this error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks a lot.

>Solution :

You should probably try providing a fixed height to the SizedBox widget. This should resolve the constraints.hasBoundedHeight error. You should also try adding a fixed width to your SizedBox widget, because your ListView has a horizontal scroll direction. This means that your ListView might take an unbounded width too.
You should try something like this:

SizedBox(
  height: <some_fixed_height> // you can probably use MediaQuery here
  width: <some_fixed_width>
  child: ...
),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading