Home > database >  Flutter : 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1895 pos 1
Flutter : 'package:flutter/src/rendering/viewport.dart': Failed assertion: line 1895 pos 1

Time:01-21

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

Thanks a lot.

CodePudding user response:

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: ...
),
  • Related