-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Make CupertinoSheetRoute usable with Cupertino(Sliver)NavigationBar #162181
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
Make CupertinoSheetRoute usable with Cupertino(Sliver)NavigationBar #162181
Conversation
…SliverNavigationBar
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
|
Thanks for the mention, its the least I can do, the result looks great, thanks for fixing it. |
|
I'm not sure if this is the correct approach. In my eyes, the root cause is more that the sheet doesn't remove the Also, the sheet's child doesn't seem to be sized correctly yet: #162215 |
Fixes #162215 and partially supports #162181. The Cupertino sheet had two issues layout: It still had MediaQuery padding at the top of the screen as if there was safe area content to avoid and some of the sheet was permanently offscreen. This caused a FloatingActionButton to be clipped, but if you put a scrolling widget in the sheet with text at the very bottom, it was impossible to scroll the text into view. This PR removes the top padding, and changes the bottom padding to equal the amount offscreen. Before: <img width="396" alt="Screenshot 2025-01-30 at 11 21 36 AM" src="https://github.com/user-attachments/assets/4e27db47-8d54-44c7-8cba-58790b88fef3" /> After: <img width="396" alt="Screenshot 2025-01-30 at 11 19 54 AM" src="https://github.com/user-attachments/assets/68f056f2-7731-4a56-8124-187d7efae020" /> ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
|
@victorsanni #162481 was merged which removes the top padding for CupertinoSheetRoute. |
MitchellGoodwin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| _kNavBarPersistentHeight + bottomHeight + MediaQuery.paddingOf(context).top; | ||
| _kNavBarPersistentHeight + | ||
| bottomHeight + | ||
| (CupertinoSheetRoute.hasParentSheet(context) ? 0.0 : MediaQuery.paddingOf(context).top); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still needed for CupertinoNavigationBar but not for CupertinoSliverNavigationBar. I updated the before video to show what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this out locally. Using your code sample, this doesn't seem to make a difference. Unless I missed something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops... I did change the sample code to manually insert MediaQuery.padding.top. Then it is reproducible.
Sample code
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
/// Flutter code sample for [CupertinoSheetRoute].
class CupertinoSheetApp extends StatelessWidget {
const CupertinoSheetApp({super.key});
@override
Widget build(BuildContext context) {
return const CupertinoApp(title: 'Cupertino Sheet', home: HomePage());
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(
middle: Text('Sheet Example'),
automaticBackgroundVisibility: false,
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CupertinoButton.filled(
onPressed: () {
Navigator.of(context).push(
CupertinoSheetRoute<void>(
builder: (BuildContext context) => const _SheetScaffold(),
),
);
},
child: const Text('Open Bottom Sheet'),
),
],
),
),
);
}
}
class _SheetScaffold extends StatelessWidget {
const _SheetScaffold();
@override
Widget build(BuildContext context) {
return MediaQuery(
data: MediaQueryData(padding: EdgeInsets.only(top: 100.0)),
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
backgroundColor: CupertinoColors.systemGrey.withOpacity(0.5),
middle: const Text('CupertinoNavigationBar Sample'),
automaticBackgroundVisibility: false,
),
child: Column(
children: <Widget>[
Container(height: 50, color: CupertinoColors.systemRed),
Container(height: 50, color: CupertinoColors.systemGreen),
Container(height: 50, color: CupertinoColors.systemBlue),
Container(height: 50, color: CupertinoColors.systemYellow),
Center(
child: CupertinoButton.filled(
onPressed: () {
Navigator.of(context).push(
CupertinoSheetRoute<void>(
builder: (BuildContext context) =>
const SliverNavBarExample(),
),
);
},
child: const Text('Open Bottom Sheet'),
),
)
],
),
));
}
}
class SliverNavBarExample extends StatelessWidget {
const SliverNavBarExample({super.key});
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: CustomScrollView(
slivers: <Widget>[
const CupertinoSliverNavigationBar(
leading: Icon(CupertinoIcons.person_2),
largeTitle: Text('Contacts'),
trailing: Icon(CupertinoIcons.add_circled),
),
SliverFillRemaining(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
const Text('Drag me up', textAlign: TextAlign.center),
CupertinoButton.filled(
onPressed: () {},
child: const Text('Bottom Automatic mode'),
),
CupertinoButton.filled(
onPressed: () {},
child: const Text('Bottom Always mode'),
),
],
),
),
),
],
),
);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to worry about the case where a MediaQuery padding is being added at the top of the sheet content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should. Since it doesn't make sense to manually add MediaQuery padding in a real app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think it's best to leave it out. If they do add padding there, it should be easy to debug.
Working on the cupertino nav bars recently gave me some context on those widgets, so when I saw this comment I was inspired to add a fix :)
Thanks @MaherSafadii for starting the exploration and also for the very helpful screenshots.
Removes the following when CupertinoNavigationBar/CupertinoSliverNavigationBar is used in a CupertinoSheetRoute:
Before:
Screen.Recording.2025-02-04.at.2.46.57.PM.mov
After:
cupertinosheetroute.+.nav.bars.mov
Sample code
Fixes Cupertino navbars apply too much top padding within a sheet.
Pre-launch Checklist
///).