Open jb3rndt opened 7 months ago
Reproducible using the code sample provided above.
Have you tried setting https://api.flutter.dev/flutter/material/FloatingActionButtonLocation-class.html?
If I want the default FloatingActionButton (FloatingActionButtonLocation.endFloat) to not be covered by the navbar, I found no other possible FloatingActionButtonLocation (without using techniques discussed in the initial post). I compared how all the different FloatingActionButtonLocation behave when copying the Mediquery.padding as described vs not.
---------Default--------- | Copying Mediquery.padding | ---------Default--------- | Copying Mediquery.padding |
---|---|---|---|
centerDocked | centerDocked | centerFloat | centerFloat |
centerTop | centerTop | endContained | endContained |
endDocked | endDocked | endFloat | endFloat |
endTop | endTop | miniCenterDocked | miniCenterDocked |
miniCenterFloat | miniCenterFloat | miniCenterTop | miniCenterTop |
miniEndDocked | miniEndDocked | miniEndFloat | miniEndFloat |
miniEndTop | miniEndTop | miniStartDocked | miniStartDocked |
miniStartFloat | miniStartFloat | miniStartTop | miniStartTop |
startDocked | startDocked | startFloat | startFloat |
startTop | startTop |
Sorry - because I'm probably missing something obvious, but: don't you want FloatingActionButtonLocation.endFloat?
No problem, I'll try to rephrase the core of what this issue is about.
So this isnt about any FloatingActionButtonLocation in particular, but rather about offsets that are specified by MediaQuery
. The ListView
(by default) internally adds a bottom padding equal to MediaQuery.of(context).padding.bottom
to prevent its list children to be concealed by some system elements or a navigation bar. I would expect the FloatingActionButton to do the same because in the case of a nested scaffold (like in https://api.flutter.dev/flutter/material/NavigationBar-class.html#material.NavigationBar.3) a navigation bar would cover a FloatingActionButton that only exists in one of the tab's scaffold (if extendBody is true on the main scaffold, to be exact). Instead, the FloatingActionButton uses the MediaQuery.viewPadding, which is confusing / requires workarounds. I'm wondering why that is the case.
I'm unsure if that helps
Steps to reproduce
flutter create --sample=material.NavigationBar.3 mysample
extendBody: true
on the main ScaffoldExpected results
I expect the FAB to not be covered by the NavBar, but to be placed above it. Sure, one can solve it with a padding but there already exists a mechanism that the main Scaffold calculates the Navbar size and adds that size to
MediaQuery.padding
so that the ListView in the body has enough scroll space for all items to be visible. I found out that the FAB usesMediaQuery.viewPadding
instead, so copying theMediaQuery.padding
(which contains the calculated navbar size) of the main Scaffold body toMediaQuery.viewPadding
achieves the desired effect. So I'm wondering if that is even advisable and why the FAB doesnt useMediaQuery.padding
like theListView
does.Actual results
The FAB doesnt use
MediaQuery.padding
to prevent obscuration by the navbar.Code sample
Code sample
```dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; /// Flutter code sample for [NavigationBar] with nested [Navigator] destinations. /// `flutter create --sample=material.NavigationBar.3 mysample` void main() { WidgetsFlutterBinding.ensureInitialized(); // make navigation bar transparent SystemChrome.setSystemUIOverlayStyle( const SystemUiOverlayStyle( systemNavigationBarColor: Colors.transparent, ), ); // make flutter draw behind navigation bar SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge); runApp(const MaterialApp(home: Home())); } class Home extends StatefulWidget { const Home({super.key}); @override StateScreenshots or Video
Screenshots / Video demonstration
This is the base case (without copying any MediaQuery.padding) -> The FAB is hidden behind the Navbar while the ListView automatically has enough padding so that the last item (14) is visible above the navbar. Here, `MediaQuery.padding` of the main Scaffold body is copied to `MediaQuery.viewPadding`, so the FAB is correctly placed automatically.Logs
Logs
```console [Paste your logs here] ```Flutter Doctor output
Doctor output
```console [✓] Flutter (Channel stable, 3.19.2, on Microsoft Windows [Version 10.0.19045.4170], locale de-DE) • Flutter version 3.19.2 on channel stable at C:\src\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7482962148 (4 weeks ago), 2024-02-27 16:51:22 -0500 • Engine revision 04817c99c9 • Dart version 3.3.0 • DevTools version 2.31.1 [✓] Windows Version (Installed version of Windows is version 10 or higher) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\janni\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694) • All Android licenses accepted. [✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✗] Visual Studio - develop Windows apps ✗ Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [✓] Android Studio (version 2022.2) • 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 17.0.6+0-b2043.56-9586694) [✓] VS Code, 64-bit edition (version 1.87.2) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.84.0 [✓] Connected device (3 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 14 (API 34) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.4170] • Edge (web) • edge • web-javascript • Microsoft Edge 122.0.2365.92 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 2 categories. ```