PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] How can I make my ListView in flutter scrollable?

 September 12, 2022     android, cross-platform, flutter, ios, listview     No comments   

Issue

I am new to flutter. I am trying to build a card app and I have a ListView for the suites of each card. I just realized that when I flip the screen to landscape mode, I get a overflow error. I figured it would be fine because I have a ListView. But nope. So I flipped it back to portrait and added some HUGE text to see if that would scroll and to my suprise it did not.

I did some research and added physics: const AlwaysScrollableScrollPhysics(), but still not working. All help is appreciated!

ListView(
  scrollDirection: Axis.vertical,
  physics: const AlwaysScrollableScrollPhysics(),
  shrinkWrap: true,
  children: [
    for (var item in suites)
      Text('test', style: TextStyle(fontSize: 100.0),),
    for (var item in suites)
      FlatButton(
        onPressed: () {
          var suiteId = item.suiteId;
          var suite = item.suite;
          var suiteImage = item.suiteImage;
          var suiteColor = item.suiteColor;

          print(suiteColor);

          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => SuiteScreen(
                suiteId: suiteId,
                suite: suite,
                suiteImage: suiteImage,
                suiteColor: suiteColor,
              ),
            ),
          );
        },
        child: ListTile(
          leading: Icon(Icons.deck),
          title: Text(
            item.suite,
            style: TextStyle(
              fontSize: 30.0,
            ),
          ),
        ),
      ),
  ],
);

Solution

just wrap your listview with the SingleChildScrollView widget and it'll work fine after that. You can copy paste the below code.

SingleChildScrollView(
  child: ListView(
  scrollDirection: Axis.vertical,
  physics: const AlwaysScrollableScrollPhysics(),
  shrinkWrap: true,
  children: [
    for (var item in suites)
      Text('test', style: TextStyle(fontSize: 100.0),),
    for (var item in suites)
      FlatButton(
        onPressed: () {
          var suiteId = item.suiteId;
          var suite = item.suite;
          var suiteImage = item.suiteImage;
          var suiteColor = item.suiteColor;

          print(suiteColor);

          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => SuiteScreen(
                suiteId: suiteId,
                suite: suite,
                suiteImage: suiteImage,
                suiteColor: suiteColor,
              ),
            ),
          );
        },
        child: ListTile(
          leading: Icon(Icons.deck),
          title: Text(
            item.suite,
            style: TextStyle(
              fontSize: 30.0,
            ),
          ),
        ),
      ),
    ],
  )
);


Answered By - Avinash
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing