How to Disable Scroll on Scrollable Widgets in Flutter

In this example, you will learn how to disable scrolling in scrollable widgets like ListView, SingleChildScrollView, or any other Scroll view widget. You may need to disable scrolling on nested scrolling in your Flutter app.

SingleChildScrollView(
  physics: NeverScrollableScrollPhysics(),
)

To disable scroll on SingleChildScrollView(), pass NeverScrollableScrollPhysics() to the physics attribute.

ListView(
    physics: NeverScrollableScrollPhysics(),
)

In the same way, you can disable scrolling on other scrollable widgets.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget{
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar: AppBar( 
          title: Text("Disable Scroll"),
          backgroundColor: Colors.deepPurpleAccent,
      ),
      body: Container(
        padding: EdgeInsets.all(30),
        child: SingleChildScrollView(
          physics: NeverScrollableScrollPhysics(),
          child:Column(
            children: [
              for(int x = 0; x <= 20; x++)...[
                Container(
                     height: 50,
                     color: x%2 ==0?Colors.redAccent:Colors.blueAccent
                )
              ]
            ]
          ),
        )
      ),
    );
  }
}

In the output, there will be multiple widgets inside the SingleChildScrollView(), but you can't able to scroll because scrolling is disabled.

In this way, you can disable scroll on scrollable widgets in Flutter.

No any Comments on this Article


Please Wait...