Flutter The Scrollbar's ScrollController has no ScrollPosition attached

541

Remove the scrollController entirely and that should fix the problem. that is how I fixed my code so your code should look something like this

class CustomScrollBar extends StatelessWidget {


 final Widget child;

  const CustomScrollBar({
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    return RawScrollbar(
      thumbColor: AppColors.gray,
      radius: Radius.circular(8),
      thickness: 4,
      isAlwaysShown: true,
      child: child,
    );
  }
}

and the second part should be like this

child: CustomScrollBar(
              child: SingleChildScrollView(
                child: Padding(
                  padding: EdgeInsets.all(7.0.scaled),
                  child: Container(
                    width: double.infinity,
                    child: Text(
                      'any text bla bla bla \n\n\n this is a lot of \n text \n .'
                    ),
                  ),
                ),
              ),
            ),
Share:
541
Chris
Author by

Chris

Updated on December 06, 2022

Comments

  • Chris
    Chris over 1 year

    I get this error when using the AppBar:

    The Scrollbar's ScrollController has no ScrollPosition attached.

    This is my CustomScrollBar:

    class CustomScrollBar extends StatelessWidget {
      final Widget child;
      final ScrollController scrollController;
    
      const CustomScrollBar({
        required this.scrollController,
        required this.child,
      });
    
      @override
      Widget build(BuildContext context) {
        return RawScrollbar(
          thumbColor: AppColors.gray,
          radius: Radius.circular(8),
          thickness: 4,
          isAlwaysShown: true,
          controller: scrollController,
          child: child,
        );
      }
    }
    

    I should be always visible. And this is how I use it:

    child: CustomScrollBar(
                  scrollController: _scrollControllerForScrollBar,
                  child: SingleChildScrollView(
                    controller: _scrollControllerForScrollBar,
                    child: Padding(
                      padding: EdgeInsets.all(7.0.scaled),
                      child: Container(
                        width: double.infinity,
                        child: Text(
                          'any text bla bla bla \n\n\n this is a lot of \n text \n .'
                        ),
                      ),
                    ),
                  ),
                ),
    

    As you can see both the ScrollBar and the SingleChildScrollView use the same ScrollController. I have no idea why this error occurs. Any idea what I am missing here?