Home Android ListView disable scrolling with touchscreen

ListView disable scrolling with touchscreen

0
ListView disable scrolling with touchscreen

Halo sobat Flutter! Pada artikel kali ini saya ingin membahas tentang “ListView disable scrolling with touchscreen”.

ListView secara garis besar merupakan sebuah user interface pada Android yang menampilkan item-item dari setiap kumpulan daftar yang tersusun berbaris ke bawah atau ke samping dengan tampilan yang dapat scroll. ListView juga menampilkan item-item dari suatu Array atau List yang dijadikan data model sebagai item dari ListView.

Nah bagaimana jadinya listview yang defaultnya dengan tampilan yang dapat di scroll bisa dinonaktifkan scrollingnya?

Pertama tama kita buat dulu tampilan list view yang diinginkan


class ListMateri extends StatefulWidget {


  @override
  _ListMateriState createState() => _ListMateriState();
}

class _ListMateriState extends State<ListMateri> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      backgroundColor: Colors.white,
      appBar: AppBar(
        elevation: 0.500,
        brightness: Brightness.light,
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios),
          color: Color(0xff13A89E),
          onPressed: () {},
        ),
        title: Text(
          "List Materi",
          style: TextStyle(
              color: Colors.black, fontSize: 20, fontFamily: 'Poppins'),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.only(top: 10, left: 20, right: 20),
          child: Column(
            children: [
              Container(
                height: 140,
                width: double.infinity,
                child: ListView.builder(
                
                    itemCount: 2,
                    itemBuilder: (context, index) {
                      return Container(
                        margin: EdgeInsets.only(top: 10),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10),
                          border:
                              Border.all(color: Color(0XFFF2F2F2), width: 2),
                          boxShadow: [
                            BoxShadow(color: Colors.white, spreadRadius: 1)
                          ],
                        ),
                        child: ListTile(
                          title: Text(
                            '0.${index + 3}  Fashahatul Lisan',
                            style: TextStyle(
                                fontSize: 14, color: Color(0xffBDBDBD)),
                          ),
                          trailing: Icon(Icons.lock, color: Color(0xffBDBDBD)),
                        ),
                      );
                    }),
              ),
              SizedBox(
                height: 10,
              ),
              Container(
                child: Padding(
                  padding: const EdgeInsets.only(
                    left: 10,
                    right: 15,
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Text(
                            "05. Fashahatul Lisan",
                            style: TextStyle(
                                fontSize: 14, color: Color(0xffBDBDBD)),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          Icon(
                            Icons.lock,
                            color: Color(0xffBDBDBD),
                            size: 25,
                          )
                        ],
                      ),
                    ],
                  ),
                ),
                height: 50,
                width: double.infinity,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  border: Border.all(color: Color(0XFFF2F2F2), width: 2),
                  boxShadow: [BoxShadow(color: Colors.white, spreadRadius: 1)],
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 30),
                child: Container(
                  height: 350,
                  width: double.infinity,
                  child: ListView.builder(
                     
                      itemCount: 5,
                      itemBuilder: (context, index) {
                        return Container(
                          margin: EdgeInsets.only(top: 10),
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10),
                            border:
                                Border.all(color: Color(0XFFF2F2F2), width: 2),
                            boxShadow: [
                              BoxShadow(color: Colors.white, spreadRadius: 1)
                            ],
                          ),
                          child: ListTile(
                            title: Text(
                              'a.${index + 3}  Fashahatul Lisan',
                              style: TextStyle(
                                  fontSize: 14, color: Color(0xffBDBDBD)),
                            ),
                            trailing:
                                Icon(Icons.lock, color: Color(0xffBDBDBD)),
                          ),
                        );
                      }),
                ),
              ),
              Container(
                height: 140,
                width: double.infinity,
                child: ListView.builder(
               
                    itemCount: 2,
                    itemBuilder: (context, index) {
                      return Container(
                        margin: EdgeInsets.only(top: 10),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10),
                          border:
                              Border.all(color: Color(0XFFF2F2F2), width: 2),
                          boxShadow: [
                            BoxShadow(color: Colors.white, spreadRadius: 1)
                          ],
                        ),
                        child: ListTile(
                          title: Text(
                            '0.${index + 6}  Fashahatul Lisan',
                            style: TextStyle(
                                fontSize: 14, color: Color(0xffBDBDBD)),
                          ),
                          trailing: Icon(Icons.lock, color: Color(0xffBDBDBD)),
                        ),
                      );
                    }),
              ),
             
            ],
          ),
        ),
      ),
    );
  }
}

Kemudian tambahkan codingan berikut dibawah ListView.builder

physics: const NeverScrollableScrollPhysics(),
   child: ListView.builder(
                      physics: const NeverScrollableScrollPhysics(), // for disable scrolling
                      itemCount: 5,
                      itemBuilder: (context, index) {
                        return Container(

Setelah selesai menambahkan codingan tersebut, widget List View tidak bisa melakukan scrolling lagi.

Selamat Mencoba sobat Flutter 🙂