0

I have SingleChildScrollView with short ListView inside Scaffold. As You see on video, SingleChildScrollView do not fill whole body of Scaffold. How to fix it? enter image description here

 import 'package:flutter/material.dart';


void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: MyWidget(),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
   return SingleChildScrollView(
        child:
            // return
            ListView(shrinkWrap: true, children: [
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      )
    ]));
  }
}
sosnus
  • 968
  • 10
  • 28

5 Answers5

0

Please try this solution:

SingleChildScrollView
   Column
     Container
        ListView(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                //...
                )
  • Make list view scroll disabled and shrinkWrap true that will help to expand list size based on content
Harsh Pipaliya
  • 2,260
  • 1
  • 14
  • 30
0

This is the default physics of SingleChildScrollView and if you want to prevent this you can change physics to ClampingScrollPhysics.and also change Listview to Column or if you want to use Listview, disable it's physics by NeverScrollableScrollPhysics().

try this:

SingleChildScrollView(
          physics: ClampingScrollPhysics(),
          child:
              // return
              Column(children: [
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            ),
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            ),
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            ),
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            ),
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            ),
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            ),
            const ListTile(
              title: Text("TEST"),
              subtitle: Text("________"),
            )
          ]))

Second way is remove SingleChildScrollView and listView's shrinkWrap property and just use listView's.

eamirho3ein
  • 16,619
  • 2
  • 12
  • 23
0

Try to remove the ScrollBar and that shrinkWrap property

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: MyWidget(),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(children: [
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      )
    ]);
  }
}
Nilesh Senta
  • 5,236
  • 2
  • 19
  • 27
0

Each item is taking certain height in the listview and the number of item heights can fill the whole screen. So if you just want to fill the whole body then Wrap Listview in Container and give whole height of the screen:

Container(
      height: MediaQuery.of(context).size.height,
      child: ListView(....)
)
HKN
  • 264
  • 1
  • 8
0

Correct answer as easier than I expect. I try every answer from this thread, but none work as I expect. After a lot of tries I solve this. Screen is still scrollable, but if I pull list down, items do not hide under half of screen like on question post.

Just ListView, without param shrinkWrap: true and without wrapping with SingleChildScrollView

Full code:

import 'package:flutter/material.dart';


void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: MyWidget(),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
// !!! Just `ListView`, without param `shrinkWrap: true` and without wrapping with `SingleChildScrollView`
   return  ListView(children: [
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      ),
      const ListTile(
        title: Text("TEST"),
        subtitle: Text("________"),
      )
    ]));
  }
}
sosnus
  • 968
  • 10
  • 28