1

I am creating a blogging app with blogs. I am using singlechildscrollview to implement scroll feature. But Scroll is not working. But there is no render overflow error.

This widget is useful when you have a single box that will normally be entirely visible, for example a clock face in a time picker, but you need to make sure it can be scrolled if the container gets too small in one axis (the scroll direction).

body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: <Widget>[
              SizedBox(height: 12),
              ListView.builder(
                scrollDirection: Axis.vertical,
                shrinkWrap: true,
                padding: const EdgeInsets.all(8),
                itemCount: blogs.length,
                itemBuilder: (BuildContext context, int index) {
                  return Container(
                    child: SingleChildScrollView(
                      child: Center(
                        child: Column(
                          children: <Widget>[
                            Container(
                              height: 350,
                              width: double.infinity,
                              decoration: BoxDecoration(
                                gradient: LinearGradient(
                                  begin: Alignment.topLeft,
                                  end: Alignment.bottomRight,
                                  colors: <Color>[
                                    Colors.orange,
                                    Colors.red,
                                  ],
                                ),
                                borderRadius: BorderRadius.circular(20),
                              ),
                              child: FlatButton(
                                onPressed: () {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                      builder: (context) => BlogExpanded(
                                        title: blogs[index].title,
                                        content: blogs[index].content,
                                        pic1: Image.asset('hoilogo.png'),
                                        pic2: Image.asset('hoilogo.png'),
                                      ),
                                    ),
                                  );
                                },
                                child: SingleChildScrollView(
                                  child: Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: <Widget>[
                                      Text(
                                        blogs[index].title,
                                        textAlign: TextAlign.center,
                                        style: kTitleHeadingBlogCard,
                                      ),
                                      SizedBox(height: 30),
                                      Image.asset('assets/images/hoilogo.png'),
                                    ],
                                  ),
                                ),
                              ),
                            ),
                            SizedBox(height: 20),
                          ],
                        ),
                      ),
                    ),
                  );
                },
              ),
            ],
          ),
        ),
      ),

I even tried to add container but it doesn't scroll

1
  • for what porpuse you are using SingleChildScrollView inside itemBuilder widgets? Commented Jun 30, 2020 at 7:03

2 Answers 2

2

Find below code that removed SingleChildScrollview & it required some static height, width for the Image widget.

Container(
        child:  ListView.builder(
          scrollDirection: Axis.vertical,
          shrinkWrap: true,
          padding: const EdgeInsets.all(8),
          itemCount: 5,
          itemBuilder: (BuildContext context, int index) {
            return Container(
              child: Center(
                child: Column(
                  children: <Widget>[
                    Container(
                      height: 350,
                      width: double.infinity,
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.topLeft,
                          end: Alignment.bottomRight,
                          colors: <Color>[
                            Colors.orange,
                            Colors.red,
                          ],
                        ),
                        borderRadius: BorderRadius.circular(20),
                      ),
                      child: FlatButton(
                        onPressed: () {
                        },
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: <Widget>[
                            Text(
                              "fjj ",
                              textAlign: TextAlign.center,
                            ),
                            SizedBox(height: 30),
                            Image.asset('assets/images/image.jpg', fit: BoxFit.cover,height: 300, width: 900,),
                          ],
                        ),
                      ),
                    ),
                    SizedBox(height: 20),
                  ],
                ),
              ),
            );
          },
        ),
      )
0

In your code you are nesting multiple scroll views with shrinkWrap: true. However using shrink wrap effects performance as mentioned in this video (must watch).

I would suggest to use a CustomScrollView instead with SliverList.

Not the answer you're looking for? Browse other questions tagged or ask your own question.