Search code examples
flutterflutter-layoutflutter-web

Flutter Web showing error for ScrollPosition


I'm trying a simple dashboard using Flutter web. In this whole project, I have not used any ScrollController, but I'm getting the error for ScrollPosition whenever I'm using the scroll wheel.

════════ Exception caught by animation library ═════════════════════════════════
The provided ScrollController is currently attached to more than one ScrollPosition.
════════════════════════════════════════════════════════════════════════════════

but this is not causing any problem in the UI.
Any suggestions will be helpful, Thank you.


Solution

  • I found the solution. This was caused by the ListView. I was using 3 columns, out of 3 One was ListView inside Drawer. And another 2 ware inside a SingleChildView. This was causing the issue. I added a ScrollController to the ListView and it was solved.

    something like this

    return Drawer(
          child: ListView(
            controller: ScrollController(initialScrollOffset: 0),
            children: [
              DrawerListTile(
                title: "Dashboard",
                svgSrc: "assets/icons/menu_dashbord.svg",
                press: () {},
              ),
              DrawerListTile(
                title: "Transaction",
                svgSrc: "assets/icons/menu_tran.svg",
                press: () {},
              ),
              DrawerListTile(
                title: "Store",
                svgSrc: "assets/icons/menu_store.svg",
                press: () {},
              ),
              DrawerListTile(
                title: "Profile",
                svgSrc: "assets/icons/menu_profile.svg",
                press: () {},
              ),
              DrawerListTile(
                title: "Settings",
                svgSrc: "assets/icons/menu_setting.svg",
                press: () {},
              ),
            ],
          ),
        );
    

    The main reason for the error is have more than one ScrollView (so ListView, SingleChildScrollView, CustomScrollView, etc.) with the scrollDirection vertical and no scrollController in one route.

    https://github.com/flutter/flutter/issues/93862

    by making primary: false inside "SingleChildScrollView" also worked