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 position incorrect in landscape on some devices #99073

Closed
MarkBurvs opened this issue Feb 24, 2022 · 8 comments
Closed

Scrollbar position incorrect in landscape on some devices #99073

MarkBurvs opened this issue Feb 24, 2022 · 8 comments
Assignees
Labels
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 platform-android Android applications specifically platform-ios iOS applications specifically r: invalid Issue is closed as not valid

Comments

@MarkBurvs
Copy link

MarkBurvs commented Feb 24, 2022

Steps to Reproduce

Create a GridView or a ListView with a Scrollbar or CupertinoScrollbar widget.
View in landscape orientation on an iPhoneX or any later iPhone with a notch.
You'll see that the scrollbar floats over the content in the gridview rather than being aligned against the edge of it.
On older iPhones without the notch, the issue is not present.

Expected results:
Scrollbar should align with the left hand edge of the content as it correctly does when in portrait on any iPhone, or on landscape on iPhone 8.

iPhone8 landscape:

iphone8_landscape

iPhoneX portrait:
iphonex_portrait

Actual results:
Scrollbar floats over the content.
It's almost as if flutter is applying an offset to account for the safe area of the notch, even though the container with the gridview inside it is no-where near the notch.

iphonex_landscape

If the scrollbar is oriented to the left, the same indentation happens on the left hand side.
Is the same whether the device is rotated to the left or the right.

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          padding: const EdgeInsets.fromLTRB(100, 10, 100, 10),
          child: Container(
            decoration: BoxDecoration(
              color: Colors.grey[200],
              borderRadius: BorderRadius.circular(10),
              boxShadow: [
                BoxShadow(
                  color: Colors.grey[800]!,
                  blurRadius: 10,
                  offset: const Offset(5, 5), // Shadow position
                ),
              ],
            ),
            child: Scrollbar(
              thickness: 7,
              scrollbarOrientation: ScrollbarOrientation.right,
              // controller: _controllerOne,
              isAlwaysShown: true,
              child: GridView.count(
                crossAxisCount: 3,
                children: List.generate(
                  10,
                  (index) {
                    return Center(
                      child: Container(
                        color: Colors.redAccent[200],
                        margin: const EdgeInsets.all(5.0),
                      ),
                    );
                  },
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Logs
Logs were too long to paste here
[✓] Flutter (Channel stable, 2.10.1, on macOS 12.2.1 21D62 darwin-arm, locale en-GB)
    • Flutter version 2.10.1 at /Users/mark.burvill/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db747aa133 (2 weeks ago), 2022-02-09 13:57:35 -0600
    • Engine revision ab46186b24
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /Users/mark.burvill/Developer/Android/sdk
    • Platform android-32, build-tools 32.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Feb 25, 2022
@danagbemava-nc danagbemava-nc changed the title Scrollbar position on iPhoneX incorrect in landscape. Scrollbar position incorrect in landscape on some devices Feb 25, 2022
@danagbemava-nc
Copy link
Member

Reproducible on stable and master.

code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          padding: const EdgeInsets.fromLTRB(100, 10, 100, 10),
          child: Container(
            decoration: BoxDecoration(
              color: Colors.grey[200],
              borderRadius: BorderRadius.circular(10),
              boxShadow: [
                BoxShadow(
                  color: Colors.grey[800]!,
                  blurRadius: 10,
                  offset: const Offset(5, 5), // Shadow position
                ),
              ],
            ),
            child: Scrollbar(
              thickness: 7,
              scrollbarOrientation: ScrollbarOrientation.right,
              // controller: _controllerOne,
              isAlwaysShown: true, // use this on stable
              // thumbVisibility: true, // use this on master
              child: GridView.count(
                crossAxisCount: 3,
                children: List.generate(
                  10,
                  (index) {
                    return Center(
                      child: Container(
                        color: Colors.redAccent[200],
                        margin: const EdgeInsets.all(5.0),
                      ),
                    );
                  },
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
screenshots
android (Pixel 4a Emulator) ios (iPhone SE 2 simulator) ios (iPhone 13 Simulator)
Screenshot_1645789420 Screenshot 2022-02-25 at 10 58 31 Simulator Screen Shot - iPhone 13 - 2022-02-25 at 10 56 23
flutter doctor -v
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.2 21D49 darwin-arm, locale en-GB)
    • Flutter version 2.10.2 at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 097d3313d8 (6 days ago), 2022-02-18 19:33:08 -0600
    • Engine revision a83ed0e5e3
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.11+0-b60-7772763)

[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
    • #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
      #1      Utf8Decoder.convert (dart:convert/utf.dart:351:42)
      #2      InputStream.readString (package:archive/src/util/input_stream.dart:207:30)
      #3      new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
      #4      ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
      #5      ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
      #6      IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
      #7      IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
      #8      IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
      #9      IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
      #10     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
      #11     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:109:18)
      #12     _rootRun (dart:async/zone.dart:1426:13)
      #13     _CustomZone.run (dart:async/zone.dart:1328:19)
      #14     _runZoned (dart:async/zone.dart:1861:10)
      #15     runZonedGuarded (dart:async/zone.dart:1849:12)
      #16     runZoned (dart:async/zone.dart:1780:12)
      #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
      #18     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:205:9)
      #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:309:47)
      #20     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:50:48)
      #21     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1320:12)
      <asynchronous suspension>
      #22     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
      <asynchronous suspension>
      #23     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
      <asynchronous suspension>
      #25     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
      <asynchronous suspension>
      #26     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #27     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
      <asynchronous suspension>
      #28     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
      <asynchronous suspension>
      #29     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #30     main (package:flutter_tools/executable.dart:94:3)
      <asynchronous suspension>


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

[✓] Connected device (5 available)
    • M2007J20CG (mobile)         • 5dd3be00                  • android-arm64  • Android 11 (API 30)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 12 (API 31) (emulator)
    • Nexus (mobile)              • 00008020-001875E83A38002E • ios            • iOS 15.3 19D50
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 12.2 21D49 darwin-arm
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 98.0.4758.109

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

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 2.11.0-0.0.pre.681, on macOS 12.2 21D49 darwin-arm, locale en-GB)
    • Flutter version 2.11.0-0.0.pre.681 at /Users/nexus/dev/sdks/flutters
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a288bd5e3f (2 hours ago), 2022-02-24 23:06:19 -0600
    • Engine revision 1012ac4b5a
    • Dart version 2.17.0 (build 2.17.0-141.0.dev)
    • DevTools version 2.11.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2021.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 213.5744.122

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

[✓] Connected device (5 available)
    • M2007J20CG (mobile)         • 5dd3be00                  • android-arm64  • Android 11 (API 30)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 12 (API 31) (emulator)
    • Nexus (mobile)              • 00008020-001875E83A38002E • ios            • iOS 15.3 19D50
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 12.2 21D49 darwin-arm
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 98.0.4758.109

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

• No issues found!

@danagbemava-nc danagbemava-nc added 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 platform-android Android applications specifically platform-ios iOS applications specifically and removed in triage Presently being triaged by the triage team labels Feb 25, 2022
@xu-baolin xu-baolin self-assigned this Feb 28, 2022
@xu-baolin
Copy link
Member

xu-baolin commented Feb 28, 2022

@MarkBurvs Hi, thanks for filing this.
This is working as intended to adapt for the notches screen.
Here is a workarround,

            child: Builder(
              builder: (context) => MediaQuery.removePadding(
                removeRight: true,
                context: context,
                child: Scrollbar(

@xu-baolin xu-baolin removed their assignment Feb 28, 2022
@MarkBurvs
Copy link
Author

MarkBurvs commented Feb 28, 2022

Thanks - that does fix it.
Seems far from obvious though!

@Piinks Piinks self-assigned this Feb 28, 2022
@Piinks
Copy link
Contributor

Piinks commented Feb 28, 2022

Glad there is a workaround, but I think we can make this work automatically. There was a similar bug in FAB a while back. Thanks for reporting!

@Piinks
Copy link
Contributor

Piinks commented Feb 28, 2022

I have also noticed that using a SafeArea widget resolves this.

@Piinks
Copy link
Contributor

Piinks commented Feb 28, 2022

I think using a SafeArea may be the right way to go here. I've checked this out this morning, and found that while I can safely assume the right positioning in some cases here, I can't always make that assumption based on the code above.

While the code above has added padding manually to have the scrolling content avoid the notches, the way it is done does not impart that extra manual padding to the scrollbar. There isn't a way for the scrollbar to know about the additional padding in this case, so adding a SafeArea ensures all of the padding is reconciled.

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);
  final ScrollController controller = ScrollController();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Container(
            padding: const EdgeInsets.fromLTRB(100, 100, 100, 100),
            child: Container(
              decoration: BoxDecoration(
                color: Colors.grey[200],
                borderRadius: BorderRadius.circular(10),
                boxShadow: [
                  BoxShadow(
                    color: Colors.grey[800]!,
                    blurRadius: 10,
                    offset: const Offset(5, 5), // Shadow position
                  ),
                ],
              ),
              child: Scrollbar(
                thickness: 7,
                scrollbarOrientation: ScrollbarOrientation.right,
                controller: controller,
                thumbVisibility: true,
                child: GridView.count(
                  controller: controller,
                  // scrollDirection: Axis.horizontal,
                  crossAxisCount: 3,
                  children: List.generate(
                    50,
                    (index) {
                      return Center(
                        child: Container(
                          color: Colors.redAccent[200],
                          margin: const EdgeInsets.all(5.0),
                        ),
                      );
                    },
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

@Piinks
Copy link
Contributor

Piinks commented Feb 28, 2022

I am going to close this since it does not appear to be a bug after all, but if you feel it is, please add more info and we can take another look! Thanks!

@Piinks Piinks closed this as completed Feb 28, 2022
@danagbemava-nc danagbemava-nc added the r: invalid Issue is closed as not valid label Mar 1, 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 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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 platform-android Android applications specifically platform-ios iOS applications specifically r: invalid Issue is closed as not valid
Projects
None yet
Development

No branches or pull requests

4 participants