Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a Non scrollable listview inside a SingleChildScrollView

Tags:

flutter

dart

Im trying to implement a non scrollable ListView builder here but can't seem to find how to do it. Reason is because i want everything to be scrollable and i dont want to have a Scrollable widget inside a scrollable parent.

class _DashboardState extends State<Dashboard> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('App Bar Here')),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Hello World'),
              Container(
                child: ListView.builder(
                  itemBuilder: (context, index) {
                    return Card(
                      child: Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                          children: <Widget>[
                            Container(
                                color: Color(0xffaaaaaa),
                                height: 20,
                                child: Text('Jss One')),
                            Text(
                              'English',
                              style: TextStyle(fontSize: 20),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                  itemCount: 50,
                ),
              ),],),));
  }}
like image 890
AbdLim Avatar asked Mar 10 '26 11:03

AbdLim


2 Answers

class _DashboardState extends State<Dashboard> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('App Bar Here')),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Hello World'),
              Container(
                child: ListView.builder(
                  physics: NeverScrollableScrollPhysics() //add this line,
                  itemBuilder: (context, index) {
                    return Card(
                      child: Padding(
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                          children: <Widget>[
                            Container(
                                color: Color(0xffaaaaaa),
                                height: 20,
                                child: Text('Jss One')),
                            Text(
                              'English',
                              style: TextStyle(fontSize: 20),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                  itemCount: 50,
                ),
              ),],),));
  }}

set physics property to NeverScrollablePhysics() in order to not scroll the lisview

like image 129
Balaji Avatar answered Mar 13 '26 07:03

Balaji


try using physics property of listview

physics: NeverScrollableScrollPhysics()

hope it helps..

like image 43
Jaydeep chatrola Avatar answered Mar 13 '26 07:03

Jaydeep chatrola