Skip to content

Commit af9565f

Browse files
Leigha Jarettsfshaza2atsansone
authored and
Tony Sansone
committed
Adapting bottom navigation bar (#8541)
This adds to our platform adaptation documentation to add a section on tab bars. This fixes this issue: https://github.com/flutter/website/issues/8540. Builds on top of this PR: #8509 ## Presubmit checklist - [X] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [X] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [X] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/master/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: Shams Zakhour (ignore Sfshaza) <[email protected]> Co-authored-by: Anthony Sansone <[email protected]>
1 parent 7f34552 commit af9565f

File tree

3 files changed

+94
-9
lines changed

3 files changed

+94
-9
lines changed
Loading
Loading

src/resources/platform-adaptations.md

Lines changed: 94 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ Your feedback is welcomed on [issue #8427][].
568568
### Widgets with .adaptive() constructors
569569

570570
Several widgets support `.adaptive()` constructors.
571+
The following table lists these widgets.
571572
Adaptive constructors substitute the corresponding Cupertino components
572573
when the app is run on an iOS device.
573574

@@ -583,14 +584,13 @@ Therefore, we recommend that you follow platform conventions.
583584
|<img width=160 src="/assets/images/docs/platform-adaptations/m3-switch.png" class="figure-img img-fluid rounded" alt="Switch in Material 3" /><br/>`Switch`|<img src="/assets/images/docs/platform-adaptations/hig-switch.png" class="figure-img img-fluid rounded" alt="Switch in HIG" /><br/>`CupertinoSwitch`|[`Switch.adaptive()`][]|
584585
|<img src="/assets/images/docs/platform-adaptations/m3-slider.png" width =160 class="figure-img img-fluid rounded" alt="Slider in Material 3" /><br/>`Slider`|<img src="/assets/images/docs/platform-adaptations/hig-slider.png" width =160 class="figure-img img-fluid rounded" alt="Slider in HIG" /><br/>`CupertinoSlider`|[`Slider.adaptive()`][]|
585586
|<img src="/assets/images/docs/platform-adaptations/m3-progress.png" width = 100 class="figure-img img-fluid rounded" alt="Circular progress indicator in Material 3" /><br/>`CircularProgressIndicator`|<img src="/assets/images/docs/platform-adaptations/hig-progress.png" class="figure-img img-fluid rounded" alt="Activity indicator in HIG" /><br/>`CupertinoActivityIndicator`|[`CircularProgressIndicator.adaptive()`][]|
586-
<!-- Uncomment out these lines after the next stable -->
587-
<!-- | <img src="/assets/images/docs/platform-adaptations/m3-checkbox.png" class="figure-img img-fluid rounded" alt=" Checkbox in Material 3" /> <br/>`Checkbox`| <img src="/assets/images/docs/platform-adaptations/hig-checkbox.png" class="figure-img img-fluid rounded" alt="Checkbox in HIG" /> <br/> `CupertinoCheckbox`|[`Checkbox.adaptive()`][]|
588-
|<img src="/assets/images/docs/platform-adaptations/m3-radio.png" class="figure-img img-fluid rounded" alt="Radio in Material 3" /> <br/>`Radio`|<img src="/assets/images/docs/platform-adaptations/hig-radio.png" class="figure-img img-fluid rounded" alt="Radio in HIG" /><br/>`CupertinoRadio`|[`Radio.adaptive()`][]| -->
587+
| <img src="/assets/images/docs/platform-adaptations/m3-checkbox.png" class="figure-img img-fluid rounded" alt=" Checkbox in Material 3" /> <br/>`Checkbox`| <img src="/assets/images/docs/platform-adaptations/hig-checkbox.png" class="figure-img img-fluid rounded" alt="Checkbox in HIG" /> <br/> `CupertinoCheckbox`|[`Checkbox.adaptive()`][]|
588+
|<img src="/assets/images/docs/platform-adaptations/m3-radio.png" class="figure-img img-fluid rounded" alt="Radio in Material 3" /> <br/>`Radio`|<img src="/assets/images/docs/platform-adaptations/hig-radio.png" class="figure-img img-fluid rounded" alt="Radio in HIG" /><br/>`CupertinoRadio`|[`Radio.adaptive()`][]|
589589

590590
### Top app bar and navigation bar
591591

592592
Since Android 12, the default UI for top app
593-
bars follow the design guidelines defined in [Material 3][mat-appbar].
593+
bars follows the design guidelines defined in [Material 3][mat-appbar].
594594
On iOS, an equivalent component called "Navigation Bars"
595595
is defined in [Apple’s Human Interface Guidelines][hig-appbar] (HIG).
596596

@@ -656,7 +656,90 @@ AppBar(
656656
But, because app bars are displayed alongside
657657
other content in your page, it's only recommended to adapt the styling
658658
so long as its cohesive with the rest of your application. You can see
659-
additional code samples and a further explanation in [the GitHub discussion on app bar adaptations][appbar-post].
659+
additional code samples and a further explanation in
660+
[the GitHub discussion on app bar adaptations][appbar-post].
661+
662+
### Bottom navigation bars
663+
664+
Since Android 12, the default UI for bottom navigation
665+
bars follow the design guidelines defined in [Material 3][mat-navbar].
666+
On iOS, an equivalent component called "Tab Bars"
667+
is defined in [Apple’s Human Interface Guidelines][hig-tabbar] (HIG).
668+
669+
<div class="container">
670+
<div class="row">
671+
<div class="col-sm text-center">
672+
<figure class="figure">
673+
<img src="/assets/images/docs/platform-adaptations/mat-navbar.png"
674+
class="figure-img img-fluid rounded" alt="Bottom Navigation Bar in Material 3 " />
675+
<figcaption class="figure-caption">
676+
Bottom Navigation Bar in Material 3
677+
</figcaption>
678+
</figure>
679+
</div>
680+
<div class="col-sm">
681+
<figure class="figure text-center">
682+
<img src="/assets/images/docs/platform-adaptations/hig-tabbar.png"
683+
class="figure-img img-fluid rounded" alt="Tab Bar in Human Interface Guidelines" />
684+
<figcaption class="figure-caption">
685+
Tab Bar in Human Interface Guidelines
686+
</figcaption>
687+
</figure>
688+
</div>
689+
</div>
690+
</div>
691+
692+
Since tab bars are persistent across your app, they should match your
693+
own branding. However, if you choose to use Material's default
694+
styling on Android, you might consider adapting to the default iOS
695+
tab bars.
696+
697+
To implement platform-specific bottom navigation bars,
698+
you can use Flutter’s `NavigationBar` widget on Android
699+
and the `CupertinoTabBar` widget on iOS.
700+
Below is a code snippet you can
701+
adapt to show a platform-specific navigation bars.
702+
703+
```dart
704+
final Map<String, Icon> _navigationItems = {
705+
'Menu': Platform.isIOS ? Icon(CupertinoIcons.house_fill) : Icon(Icons.home),
706+
'Order': Icon(Icons.adaptive.share),
707+
};
708+
709+
...
710+
711+
Scaffold(
712+
body: _currentWidget,
713+
bottomNavigationBar: Platform.isIOS
714+
? CupertinoTabBar(
715+
currentIndex: _currentIndex,
716+
onTap: (index) {
717+
setState(() => _currentIndex = index);
718+
_loadScreen();
719+
},
720+
items: _navigationItems.entries
721+
.map<BottomNavigationBarItem>(
722+
(entry) => BottomNavigationBarItem(
723+
icon: entry.value,
724+
label: entry.key,
725+
))
726+
.toList(),
727+
)
728+
: NavigationBar(
729+
selectedIndex: _currentIndex,
730+
onDestinationSelected: (index) {
731+
setState(() => _currentIndex = index);
732+
_loadScreen();
733+
},
734+
destinations: _navigationItems.entries
735+
.map<Widget>((entry) => NavigationDestination(
736+
icon: entry.value,
737+
label: entry.key,
738+
))
739+
.toList(),
740+
));
741+
```
742+
660743

661744
### Alert dialog
662745

@@ -728,7 +811,7 @@ void _showAdaptiveDialog(
728811
}
729812
```
730813

731-
Further detail about adapting alert dialogs is available in
814+
To learn more about adapting alert dialogs, check out
732815
[the GitHub discussion on dialog adaptations][alert-post].
733816
You can leave feedback or ask questions in the discussion.
734817

@@ -756,9 +839,11 @@ You can leave feedback or ask questions in the discussion.
756839
[appbar-post]: {{site.repo.uxr}}/discussions/93
757840
[mat-appbar]: https://m3.material.io/components/top-app-bar/overview
758841
[hig-appbar]: https://developer.apple.com/design/human-interface-guidelines/components/navigation-and-search/navigation-bars/
759-
<!-- [`Checkbox.adaptive()`]: {{site.api}}/flutter/material/Checkbox/Checkbox.adaptive.html
760-
[`Radio.adaptive()`]: {{site.api}}/flutter/material/Radio/Radio.adaptive.html -->
842+
[`Checkbox.adaptive()`]: {{site.api}}/flutter/material/Checkbox/Checkbox.adaptive.html
843+
[`Radio.adaptive()`]: {{site.api}}/flutter/material/Radio/Radio.adaptive.html
761844
[`Switch.adaptive()`]: {{site.api}}/flutter/material/Switch/Switch.adaptive.html
762845
[`Slider.adaptive()`]: {{site.api}}/flutter/material/Slider/Slider.adaptive.html
763846
[`CircularProgressIndicator.adaptive()`]: {{site.api}}/flutter/material/CircularProgressIndicator/CircularProgressIndicator.adaptive.html
764-
[UI Component section]: {{site.api}}/resources/platform-adaptations/#ui-components
847+
[UI Component section]: {{site.api}}/resources/platform-adaptations/#ui-components
848+
[mat-navbar]: https://m3.material.io/components/navigation-bar/overview
849+
[hig-tabbar]: https://developer.apple.com/design/human-interface-guidelines/components/navigation-and-search/tab-bars/

0 commit comments

Comments
 (0)