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

Persistent bottom sheet does not respect SafeArea #69676

Open
amitkot opened this issue Nov 3, 2020 · 8 comments
Open

Persistent bottom sheet does not respect SafeArea #69676

amitkot opened this issue Nov 3, 2020 · 8 comments
Labels
f: material design flutter/packages/flutter/material repository. found in release: 1.22 Found to occur in 1.22 found in release: 1.24 Found to occur in 1.24 framework flutter/packages/flutter repository. See also f: labels. team-design Owned by Design Languages team triaged-design Triaged by Design Languages team

Comments

@amitkot
Copy link

amitkot commented Nov 3, 2020

When showing a persistent bottom sheet SafeArea is ignored and does not provide bottom padding:

Screen Shot 2020-11-03 at 16 18 04

Code:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(home: MyHomePage());
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) => Scaffold(
        floatingActionButton: Builder(
          builder: (context) => FloatingActionButton(
            onPressed: () {
              showBottomSheet(
                  context: context,
                  builder: (context) => SafeArea(
                        child: Container(
                          height: 100,
                          width: 200,
                          color: Colors.red,
                        ),
                      ));
            },
          ),
        ),
      );
}
[✓] Flutter (Channel stable, 1.22.2, on Mac OS X 10.14.6 18G6032, locale en-IL)
    • Flutter version 1.22.2 at /Users/amit/fvm/versions/stable
    • Framework revision 84f3d28555 (3 weeks ago), 2020-10-15 16:26:19 -0700
    • Engine revision b8752bbfff
    • Dart version 2.10.2
@amitkot amitkot changed the title Persistent bottom sheet does not respect SafeArea Persistent bottom sheet does not respect SafeArea Nov 3, 2020
@HansMuller HansMuller added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Nov 3, 2020
@pedromassangocode
Copy link

pedromassangocode commented Nov 5, 2020

Reproducible on latest master as well.

flutter doctor -v
[✓] Flutter (Channel master, 1.24.0-8.0.pre.97, on Mac OS X 10.15.7 19H2 darwin-x64, locale en)
    • Flutter version 1.24.0-8.0.pre.97 at /Users/pedromassango/dev/SDKs/flutter_master
    • Framework revision 4c24eb10b8 (72 minutes ago), 2020-11-05 11:18:00 +0100
    • Engine revision e66a720137
    • Dart version 2.12.0 (build 2.12.0-21.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.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • 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 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-b3-6222593)

[✓] IntelliJ IDEA Community Edition (version 2020.2.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 50.0
    • Dart plugin version 202.7319.5

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

[✓] 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.7 19H2 darwin-x64
    • Web Server (web)            • web-server    • web-javascript • Flutter Tools
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 86.0.4240.183

• No issues found!

@zepfietje
Copy link

The same issue occurs when directly setting the bottomSheet property of Scaffold.

Scaffold(
  bottomSheet: SafeArea(
    // ...
  ),
)

@noelmansour
Copy link

noelmansour commented Aug 3, 2021

This top safe area is also not respected as outlined in this stackoverflow post.

The suggested answer is to copy the BottomSheet widget and update the build method to remove the MediaQuery.removePadding widget.

@tmaihoff
Copy link

tmaihoff commented Nov 6, 2021

Any updates here? Still having this issue

@Arenukvern
Copy link

Faced this issue too with top-notch.

Resolved using dart:ui.window.viewPadding.top / ui.window.devicePixelRatio

How it works:
The dart:ui.window.viewPadding is the number of physical pixels on each side of the display rectangle into which the view can render.
By dividing to ui.window.devicePixelRatio we should receive logic pixels.

So in summary code is

showModalBottomSheet<bool>(
      context: context,
      builder: (BuildContext context) => Container(
        height: MediaQuery.of(context).size.height,
        padding: EdgeInsets.only(
         top: ui.window.viewPadding.top / ui.window.devicePixelRatio,
        ),
      ),
    );

@n13
Copy link

n13 commented Feb 16, 2022

We are facing this issue as well.

We have a persistent bottom button on the bottom sheet, but it's too low down on iPhone - SafeArea is ignored.

Is there a different way to have a persistent bottom button?

@0xHristo
Copy link

0xHristo commented May 18, 2022

If you wrap the Scaffold in SafeArea it gets the work done, but if you want SafeArea's horizontal insets on the bottomSheet: you have to add some padding.

@StephenWithPH
Copy link

There is a workaround here: #50314 (comment)

Of note, that issue (#50314) seems to be the same basic issue as this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. found in release: 1.22 Found to occur in 1.22 found in release: 1.24 Found to occur in 1.24 framework flutter/packages/flutter repository. See also f: labels. team-design Owned by Design Languages team triaged-design Triaged by Design Languages team
Projects
None yet
Development

No branches or pull requests