Commit dfb36f0
authored
Make CupertinoSheetRoute usable with Cupertino(Sliver)NavigationBar (flutter#162181)
Working on the cupertino nav bars recently gave me some context on those
widgets, so when I saw this
[comment](flutter#157568 (comment))
I was inspired to add a fix :)
Thanks @MaherSafadii for [starting the
exploration](flutter#157568 (comment))
and also for the very helpful
[screenshots](flutter#162021 (comment)).
Removes the following when
CupertinoNavigationBar/CupertinoSliverNavigationBar is used in a
CupertinoSheetRoute:
- Unneeded back button
- Superfluous top padding in CupertinoNavigationBar
- Full page route transitions
## Before:
https://github.com/user-attachments/assets/a6da3957-0cff-4491-9380-bbc676ac799d
## After:
https://github.com/user-attachments/assets/37cd1628-a47e-44aa-85c7-abceda6e7944
<details>
<summary>Sample code</summary>
```dart
// 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 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'),
),
],
),
),
),
],
),
);
}
}
```
</details>
Fixes [Cupertino navbars apply too much top padding within a
sheet](flutter#162021).
## 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.
- [x] All existing and new tests are passing.1 parent d3c96c6 commit dfb36f0
File tree
3 files changed
+111
-6
lines changed- packages/flutter
- lib/src/cupertino
- test/cupertino
3 files changed
+111
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
215 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
216 | 219 | | |
217 | 220 | | |
218 | 221 | | |
| |||
1571 | 1574 | | |
1572 | 1575 | | |
1573 | 1576 | | |
1574 | | - | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
1575 | 1581 | | |
1576 | 1582 | | |
1577 | 1583 | | |
| |||
1591 | 1597 | | |
1592 | 1598 | | |
1593 | 1599 | | |
1594 | | - | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
1595 | 1605 | | |
1596 | 1606 | | |
1597 | 1607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
461 | 461 | | |
462 | 462 | | |
463 | 463 | | |
464 | | - | |
465 | | - | |
466 | 464 | | |
467 | 465 | | |
468 | 466 | | |
| |||
475 | 473 | | |
476 | 474 | | |
477 | 475 | | |
478 | | - | |
479 | 476 | | |
480 | 477 | | |
481 | 478 | | |
| |||
797 | 794 | | |
798 | 795 | | |
799 | 796 | | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
800 | 848 | | |
801 | 849 | | |
802 | 850 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
346 | 393 | | |
347 | 394 | | |
348 | 395 | | |
| |||
0 commit comments