Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollbar with ListView shows 2 scrollbars #99724

Closed
matthew-carroll opened this issue Mar 8, 2022 · 9 comments
Closed

Scrollbar with ListView shows 2 scrollbars #99724

matthew-carroll opened this issue Mar 8, 2022 · 9 comments
Labels
f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. found in release: 2.10 Found to occur in 2.10 found in release: 2.11 Found to occur in 2.11 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: solved Issue is closed as solved

Comments

@matthew-carroll
Copy link
Contributor

I have a Scrollbar as an ancestor to a ListView so that I can position the scrollbar a bit further away from the list of items.

There are now 2 scrollbars painted for the same list. Also, the scrollbar that's drawn by the Scrollbar widget doesn't scroll all the way down its height. Instead, the Scrollbar widget makes its own scroll track the same pixel height as the ListView, which isn't the expected behavior. The Scrollbar widget should scroll from its top to its bottom.

Screen.Recording.2022-03-07.at.4.13.00.PM.mov

I copied the code from the Scrollbar docs and adjusted the code to demonstrate the issue. This code can be copied and pasted into DartPad (Flutter 2.10.3 Dart SDK 2.16.1):

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const Center(
          child: MyStatefulWidget(),
        ),
      ),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  final ScrollController _firstController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
      return SizedBox(
              width: constraints.maxWidth / 2,
              // Only one scroll position can be attached to the
              // PrimaryScrollController if using Scrollbars. Providing a
              // unique scroll controller to this scroll view prevents it
              // from attaching to the PrimaryScrollController.
              child: Scrollbar(
                isAlwaysShown: true,
                controller: _firstController,
                child: Padding(
                  padding: const EdgeInsets.all(48.0),
                  child: ListView.builder(
                      controller: _firstController,
                      itemCount: 100,
                      itemBuilder: (BuildContext context, int index) {
                        return Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Text('Scrollable 1 : Index $index'),
                        );
                      }),
                ),
      ),);
    });
  }
}
@Packiaseelan
Copy link

Packiaseelan commented Mar 8, 2022

Hi @matthew-carroll

Can you try this to position scrollbar away from list ?

child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.only(right: 150),
            child: Column(children: [
              ...List.generate(100, (index) => Padding(
                padding: const EdgeInsets.all(20.0),
                child: Text('Scrollable 1 : Index $index'),
              )).toList()
            ]),
          ),
        ),

instead of Scrollbar and list view combination.

@matthew-carroll
Copy link
Contributor Author

No, I can't use that. I have a header that doesn't scroll and what you have there wouldn't support the header. Additionally, your approach makes it impossible to utilize the ListView.builder() modality.

Regardless, I believe that I'm using the widgets as intended. If that's the case, then this is a bug and should be fixed.

@Packiaseelan
Copy link

this can make the header fixed.
child: Column( children: [ Text('Header Widget'), Expanded( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.only(right: 150), child: Column(children: [ ...List.generate(100, (index) => Padding( padding: const EdgeInsets.all(20.0), child: Text('Scrollable 1 : Index $index'), )).toList() ]), ), ), ), ], ),

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Mar 8, 2022
@darshankawar
Copy link
Member

Thanks for the report and code sample @matthew-carroll. Using latest master and stable, I see the same behavior:

Screenshot 2022-03-09 at 10 47 53 AM

stable, master flutter doctor -v

[✓] Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 2.10.3 at /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7e9793dee1 (11 hours ago), 2022-03-02 11:23:12 -0600
    • Engine revision bd539267b4
    • Dart version 2.16.1
    • DevTools version 2.9.2

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.


[✓] Flutter (Channel master, 2.11.0-0.0.pre.831, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 2.11.0-0.0.pre.831 at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3172065fba (3 hours ago), 2022-03-08 19:35:20 -0600
    • Engine revision 5c760759fe
    • Dart version 2.17.0 (build 2.17.0-182.0.dev)
    • DevTools version 2.11.1

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.


@darshankawar darshankawar added f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. found in release: 2.10 Found to occur in 2.10 found in release: 2.11 Found to occur in 2.11 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on and removed in triage Presently being triaged by the triage team labels Mar 9, 2022
@darshankawar
Copy link
Member

/cc @Piinks

@Piinks
Copy link
Contributor

Piinks commented Mar 9, 2022

Is the second scrollbar you are seeing the one that is automatically added when running on desktop (+ web on desktop)?

This guide explains where they come from and how to configure or disable:
https://docs.flutter.dev/release/breaking-changes/default-desktop-scrollbars

@Piinks Piinks added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 9, 2022
@matthew-carroll
Copy link
Contributor Author

Adding a ScrollConfiguration widget around the ListView and then copying an ancestor ScrollBehavior and disabling the scrollbar successfully removes the scrollbar from the ListView.

If this is the intended behavior, you can close this issue.

Updated code:

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const Center(
          child: MyStatefulWidget(),
        ),
      ),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({Key? key}) : super(key: key);

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  final ScrollController _firstController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
      return SizedBox(
              width: constraints.maxWidth / 2,
              // Only one scroll position can be attached to the
              // PrimaryScrollController if using Scrollbars. Providing a
              // unique scroll controller to this scroll view prevents it
              // from attaching to the PrimaryScrollController.
              child: Scrollbar(
                isAlwaysShown: true,
                controller: _firstController,
                child: Padding(
                  padding: const EdgeInsets.all(48.0),
                  // Here's the ScrollConfiguration
                  child: ScrollConfiguration(
                    behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
                    child: ListView.builder(
                        controller: _firstController,
                        itemCount: 100,
                        itemBuilder: (BuildContext context, int index) {
                          return Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Text('Scrollable 1 : Index $index'),
                          );
                        }),
                  ),
                ),
      ),);
    });
  }
}

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 9, 2022
@Piinks
Copy link
Contributor

Piinks commented Mar 9, 2022

Nice! Thanks for updating! I will close this then as WAI.

@Piinks Piinks closed this as completed Mar 9, 2022
@darshankawar darshankawar added the r: solved Issue is closed as solved label Mar 10, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. found in release: 2.10 Found to occur in 2.10 found in release: 2.11 Found to occur in 2.11 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on r: solved Issue is closed as solved
Projects
None yet
Development

No branches or pull requests

4 participants