Skip to content

The Scrollbar widget incorrectly renders scrollbars for all descendant widgets #66444

Closed

Description

@denis-evteev

When a scrollable widget with a scrollbar contains another scrollable widget with a scrollbar, the inner scrollbar is rendered incorrectly.

If the inner scrollbar is set implicitly (i.e. the inner scrollable widget is not wrapped into a Scrollbar widget), then the primary scrollbar is replaced with the inner scrollbar (which is kind of expected behaviour), but it always appears at the top of the screen regardless of the actual position of the inner scrollable widget.

Edit: An inner scrollbar of a non-immediate ancestor of the Scrollbar widget being set implicitly is actually not an expected behaviour.

If the inner scrollbar is set explicitly (i.e. the inner scrollable widget is wrapped into a Scrollbar widget), then the inner scrollbar does appear inside the inner widget, as expected, but the primary scrollbar still gets replaced with the inner scrollbar at the top of the screen and both scrollbars are displayed simultaneously.

I observed this behaviour both in iOS and in Android.

Here’s a sample code to reproduce the issue:

import 'package:flutter/material.dart';

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

class SampleWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Scrollbar(
            child: ListView(
              children: [
                SizedBox(height: 100.0),
                TextField(
                  minLines: 3,
                  maxLines: 5,
                ),
                SizedBox(height: 100.0),
                Scrollbar(
                  child: TextField(
                    minLines: 3,
                    maxLines: 5,
                  ),
                ),
                SizedBox(height: 1000.0),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 1.20.4, on Mac OS X 10.15.6 19G2021, locale en-UK)
    • Flutter version 1.20.4 at /Users/denis/Projects/src/flutter
    • Framework revision fba99f6cf9 (9 days ago), 2020-09-14 15:32:52 -0700
    • Engine revision d1bc06f032
    • Dart version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/denis/Library/Android/sdk
• Platform android-30, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0, Build version 12A7209
• CocoaPods version 1.10.0.beta.2

[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 48.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.2.2)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 49.0.4
• Dart plugin version 202.7319.5

[✓] Connected device (2 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• iPhone 11 Pro Max (mobile) • 1AE78A39-B65D-44FE-94D4-9358DAB8039E • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-1 (simulator)

• No issues found!

Activity

  1. pedromassangocode commented on Sep 23, 2020

    @pedromassangocode

    I was able to reproduce this with the latest master version of Flutter.

    flutter doctor -v
    [✓] Flutter (Channel master, 1.22.0-10.0.pre.317, on Mac OS X 10.15.6 19G2021 x86_64, locale en)
        • Flutter version 1.22.0-10.0.pre.317 at /Users/pedromassango/dev/SDKs/flutter_master
        • Framework revision 10febea877 (7 hours ago), 2020-09-23 07:22:10 +0200
        • Engine revision 57ee3d4b32
        • Dart version 2.10.0 (build 2.10.0-156.0.dev)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
        • Android SDK at /Users/pedromassango/Library/Android/sdk
        • Platform android-30, build-tools 30.0.1
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 12.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.0, Build version 12A7209
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [!] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [✓] IntelliJ IDEA Community Edition (version 2020.2.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 49.0.4
        • Dart plugin version 202.7319.5
    
    [✓] VS Code (version 1.48.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.14.1
    
    [✓] Connected device (4 available)
        • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
        • macOS (desktop)             • macos         • darwin-x64     • Mac OS X 10.15.6 19G2021 x86_64
        • Web Server (web)            • web-server    • web-javascript • Flutter Tools
        • Chrome (web)                • chrome        • web-javascript • Google Chrome 85.0.4183.121
    
    ! Doctor found issues in 1 category.
    Process finished with exit code 0
    
  2. added
    f: scrolling
    found in release: 1.22
    framework
    has reproducible steps
    platform-web
    on Sep 23, 2020
  3. denis-evteev commented on Sep 23, 2020

    @denis-evteev
    Author

    It seems that the Scrollbar widget shows scrollbars for all nested scrollable widgets and there seems to be no way to alter that (incorrect) behaviour.

    Because of that, in the following sample app a horizontal scrollbar appears not only for a ListView, but also for all nested PageViews:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(SampleWidget());
    }
    
    class SampleWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: Scrollbar(
              child: ListView(
                children: List.generate(
                  10,
                  (index) => index % 2 == 0
                      ? Container(
                          height: 100.0,
                          color: Colors.amber,
                          child: Text('Empty container'),
                        )
                      : Container(
                          height: 200.0,
                          color: Colors.orangeAccent,
                          child: PageView(
                            children: [
                              Text('Page 1'),
                              Text('Page 2'),
                              Text('Page 3'),
                            ],
                          ),
                        ),
                ),
              ),
            ),
          ),
        );
      }
    }
    

    The Scrollbar widget should display scrollbars for its direct child widget only.

  4. changed the title [-]Nested scrollbar render issue[/-] [+]The `Scrollbar` widget incorrectly renders scrollbars for all descendant widgets[/+] on Sep 23, 2020
  5. added
    p: material_ui
    on Sep 24, 2020
  6. HansMuller commented on Sep 24, 2020

    @HansMuller
    Contributor
  7. yjbanov commented on Sep 24, 2020

    @yjbanov
    Contributor

    This does not look web-specific. Removing the platform-web label, but feel free to put it back if this is indeed web-specific.

  8. removed
    platform-web
    on Sep 24, 2020
  9. added
    P2
    on Sep 29, 2020
  10. Piinks commented on Dec 8, 2020

    @Piinks
    Contributor

    I think this is a duplicate of #36474
    @xu-baolin is also working on solving this/both in #71843

    I am going to close this as a dupe, follow the other issue for the latest updates - it looks like there has been more discussion there. If you feel this issue is different from #36474, let us know and we will re-open! :)

  11. github-actions commented on Aug 9, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2f: scrollingfound in release: 1.22frameworkhas reproducible stepsp: material_ui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions