Skip to content

Scrollbar throws due to recent assert changes #84735

@nt4f04uNd

Description

@nt4f04uNd

Steps to Reproduce

  1. PrimaryScrollController (or any other scroll controller that attaches both to scrollbar and view) ->
    PageTransitionSwitcher ->
    SharedAxisTransition ->
    Scrollbar ->
    View
  2. Animate the switcher

Related PR #81278

Code sample
import 'package:flutter/material.dart';
import 'package:animations/animations.dart';

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

class App extends StatefulWidget {
  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  late final views = [
    for (int i = 0; i < 5; i++)
      Scrollbar(
        interactive: true,
        key: ValueKey(i),
        child: ListView.builder(
          itemCount: 100,
          itemBuilder: (context, index) => Text(index.toString()),
        ),
      ),
  ];

  int index = 0;
  void _handleTap() {
    setState(() {
      index += 1;
      if (index == views.length) {
        index = 0;
      }
    });
  }

  final controller = ScrollController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'App',
      home: PrimaryScrollController(
        controller: controller,
        child: Scaffold(
          body: Column(
            children: [
              ElevatedButton(onPressed: _handleTap, child: Text('sample text')),
              Expanded(
                child: PageTransitionSwitcher(
                  duration: const Duration(milliseconds: 300),
                  transitionBuilder: (child, animation, secondaryAnimation) {
                    return SharedAxisTransition(
                      transitionType: SharedAxisTransitionType.horizontal,
                      animation: animation,
                      secondaryAnimation: secondaryAnimation,
                      fillColor: Colors.transparent,
                      child: child,
                    );
                  },
                  child: views[index],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
Logs
════════ Exception caught by scheduler library ═════════════════════════════════
The following assertion was thrown during a scheduler callback:
The PrimaryScrollController is currently attached to more than one ScrollPosition.

The Scrollbar requires a single ScrollPosition in order to be painted.

When the scrollbar is interactive, the associated Scrollable widgets must have unique ScrollControllers. The PrimaryScrollController is used by default for ScrollViews with an Axis.vertical ScrollDirection, unless the ScrollView has been provided its own ScrollController. More than one Scrollable may have tried to use the PrimaryScrollController of the current context.

When the exception was thrown, this was the stack
#0      RawScrollbarState._checkForValidScrollPosition.<anonymous closure>
package:flutter/…/widgets/scrollbar.dart:1101
#1      RawScrollbarState._checkForValidScrollPosition
package:flutter/…/widgets/scrollbar.dart:1125
#2      RawScrollbarState._maybeTriggerScrollbar.<anonymous closure>
package:flutter/…/widgets/scrollbar.dart:1042
#3      SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1143
#4      SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1088
#5      SchedulerBinding._handleDrawFrame
package:flutter/…/scheduler/binding.dart:996
#9      _invoke (dart:ui/hooks.dart:163:10)
#10     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:259:5)
#11     _drawFrame (dart:ui/hooks.dart:126:31)
(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════

[✓] Flutter (Channel master, 2.3.0-17.0.pre.375, on Microsoft Windows [Version 10.0.19041.1052], locale ru-RU)
    • Flutter version 2.3.0-17.0.pre.375 at C:\dev\src\flutter
    • Upstream repository git@github.com:nt4f04und/flutter.git
    • Framework revision 57a565c706 (19 hours ago), 2021-06-15 18:44:02 -0700
    • Engine revision e0011fa561
    • Dart version 2.14.0 (build 2.14.0-211.0.dev)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] IntelliJ IDEA Community Edition (version 2020.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.57.0)
    • VS Code at C:\Users\danya\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.23.0

[✓] Connected device (4 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19041.1052]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 91.0.4472.101
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 91.0.864.41

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

a: error messageError messages from the Flutter frameworkf: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions