Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] flutter – Using ListView in SingleChildScrollView

Posted on November 11, 2022 By

Solution 1 :

I found the solution. With SingleChildScollView() widget, I do not need to use Expanded widget. Moreover, I need to give my ListView() fixed height by wrapping it either in Container() widget or SizedBox() widget.

class SchemaPage extends StatelessWidget {
  final String text;

  SchemaPage({Key? key, required this.text}) : super(key: key);

  Widget build(BuildContext context) => SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(height: 110, child: AppBar()),
            Container(
              padding: EdgeInsets.all(36),
              child: Text(
                'Schema',
                style: TextStyle(
                    fontFamily: 'Roboto',
                    fontSize: 24,
                    fontWeight: FontWeight.w700,
                    color: Colors.black),
              ),
            ),
            Container(
              padding: EdgeInsets.only(left: 36),
              child: Text(
                'Person',
                style: TextStyle(
                    fontFamily: 'Roboto',
                    fontSize: 20,
                    fontWeight: FontWeight.w700,
                    color: Colors.black),
              ),
            ),
            Container(
              padding: EdgeInsets.only(left: 36),
              width: 264,
              height: 300,
              child: ListView(
                //physics: ClampingScrollPhysics(),
                shrinkWrap: true,
                children: [
                  SizedBox(
                    height: 10,
                  ),
                  PersonWidget(),
                  SizedBox(
                    height: 10,
                  ),
                  PersonWidget(),
                  SizedBox(
                    height: 10,
                  ),
                  PersonWidget(),
                  SizedBox(
                    height: 10,
                  ),
                 PersonWidget(),
                ],
              ),
            ),

            SizedBox(
              height: 5,
            ),
            Container(
              padding: EdgeInsets.only(left: 36),
              child: InkWell(
                child: Text('More',
                    style: TextStyle(
                        fontFamily: 'Roboto',
                        fontSize: 14,
                        fontWeight: FontWeight.w700)),
                onTap: () {},
              ),
            ),
            SizedBox(height: 30,),
            Container(
              padding: EdgeInsets.only(left: 36),
              child: Text(
                'Plans',
                style: TextStyle(
                    fontFamily: 'Roboto',
                    fontSize: 20,
                    fontWeight: FontWeight.w700,
                    color: Colors.black),
              ),
            ),
            SizedBox(height: 30,),
          ],
        ),
      );
}

Problem :

I am working on a web design where I need to create several ListViews in one page. Now, I also want that my whole page will also be scrollable like a webpage. What happening is that with SingleChildScrollView ListViews stop scrolling. I am using Expanded and tried several ways but unable to find a solution. Anybody, knows how to solve this? Thank you very much in advance.

class SchemaPage extends StatelessWidget {
  final String text;

  SchemaPage({Key? key, required this.text}) : super(key: key);

  //If I use SingleChildScrollView here, My list views stop scrolling but If I remove ListView, it works fine. 
  Widget build(BuildContext context) => Scaffold(
        body: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              AppBar(), //Custom App Bar
              SizedBox(
                height: 15,),
                Expanded(
                  flex: 2,
                  child: Container(
                    width: 264,
                    padding: EdgeInsets.all(36),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          'Scheme',
                          style: TextStyle(
                              fontFamily: 'Roboto',
                              fontSize: 24,
                              fontWeight: FontWeight.w700,
                              color: Colors.black),
                        ),
                        SizedBox(
                          height: 10,
                        ),
                        Text(
                          'Person',
                          style: TextStyle(
                              fontFamily: 'Roboto',
                              fontSize: 20,
                              fontWeight: FontWeight.w700,
                              color: Colors.black),
                        ),
                        SizedBox(
                          height: 20,
                        ),
                        Expanded(
                          flex:4,
                          child: Container(
                            child: ListView(
                              shrinkWrap: true,
                              children: [
                                SizedBox(
                                  height: 10,
                                ),
                                PersonWidget(),
                       
                                SizedBox(
                                  height: 10,
                                ),
                                                                                                      
                                PersonWidget(),
                                SizedBox(
                                  height: 10,
                                ),
                                PersonWidget(),
                              ],
                            ),
                          ),
                        ),
                        SizedBox(
                          height: 5,
                        ),
                        InkWell(
                          child: Text('more',
                              style: TextStyle(
                                  fontFamily: 'Roboto',
                                  fontSize: 14,
                                  fontWeight: FontWeight.w700)),
                          onTap: () {},
                        ),
                        SizedBox(height: 30,),
                        Text(
                          'Person',
                          style: TextStyle(
                              fontFamily: 'Roboto',
                              fontSize: 20,
                              fontWeight: FontWeight.w700,
                              color: Colors.black),
                        ),
                        SizedBox(height: 30,),
                       //Here I wanted to use another ListView but I need to make page scrollable
                      ],
                    ),
                  ),
                ),
            ],
          ),
        ),
      );
}

Comments

Comment posted by minimal-reproducible-example

Can you provide

READ  [FIXED] java - ScrollView doesn't stay to a certain part of the screen and takes whole screen
Powered by Inline Related Posts

Comment posted by WasimSafdar

@YeasinSheikh Code added

Comment posted by Yeasin Sheikh

This widget doesnt reproduce any issue

Comment posted by WasimSafdar

@YeasinSheikh Instead of Scaffold, if you use SingleChildScrollView, then it will not make page scrollable because of ListViews.

Comment posted by stackoverflow.com/questions/60579335/…

try this

Android Tags:android-studio, flutter, flutter-animation, flutter-layout, flutter-web

Post navigation

Previous Post: [FIXED] android – Please help, after flutter update, (The name ‘MenuItem’ is defined in the libraries) in visual studio
Next Post: [FIXED] react-native: How to remove underline while typing text in TextInput Component on android device?

Related Posts

[FIXED] android – How to expand second TextView if the first is too long in ConstraintLayout Android
[FIXED] python – p4a Cannot Import Module _ctypes Android
[FIXED] android – Is it possible for iOS triggering onNewIntent() in aos? Android
[FIXED] android – Back inactive flutter webveiw Android
[FIXED] java – What is R.id in Android Studio? Android
[FIXED] android studio – Can I update my Mutablelist over the internet? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme