Skip to content

Commit

Permalink
[flutter_adaptive_scaffold] exchange BottomNavigationBar with Navigat…
Browse files Browse the repository at this point in the history
…ionBar (#3746)

To have a common Material 3 Design, BottomNavigationBar was replaced with M3 NavigationBar as adaptive scaffold claims to be Material 3.

[fixes: #124984](flutter/flutter#124984)

* [x]  I read the [Contributor Guide](https://github.com/flutter/packages/blob/main/CONTRIBUTING.md) and followed the process outlined there for submitting PRs.
* [x]  I read the [Tree Hygiene](https://github.com/flutter/flutter/wiki/Tree-hygiene) wiki page, which explains my responsibilities.
* [x]  I read and followed the [relevant style guides](https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style) and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.)
* [x]  I signed the [CLA](https://cla.developers.google.com/).
* [x]  The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]`
* [x]  I listed at least one issue that this PR fixes in the description above.
* [x]  I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy](https://dart.dev/tools/pub/versioning), or this PR is [exempt from version changes](https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates).
* [x]  I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style](https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style).
* [x]  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](https://github.com/flutter/flutter/wiki/Tree-hygiene#tests).
* [x]  All existing and new tests are passing.
  • Loading branch information
fmt-Println-MKO authored May 17, 2023
1 parent a78a913 commit 9e52ec4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_adaptive_scaffold/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.4

* Use Material 3 NavigationBar instead of BottomNavigationBar

## 0.1.3

* Fixes `groupAlignment` property not available in `standardNavigationRail` - [flutter/flutter#121994](https://github.com/flutter/flutter/issues/121994)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
expect(smallBody, findsOneWidget);
expect(bnav, findsOneWidget);
expect(tester.getTopLeft(smallBody), Offset.zero);
expect(tester.getTopLeft(bnav), const Offset(0, 744));
expect(tester.getTopLeft(bnav), const Offset(0, 720));
expect(body, findsNothing);
expect(largeBody, findsNothing);
expect(pnav, findsNothing);
Expand Down Expand Up @@ -73,22 +73,22 @@ void main() {

expect(tester.getTopLeft(b), const Offset(17.6, 0));
expect(tester.getBottomRight(b),
offsetMoreOrLessEquals(const Offset(778.2, 755.2), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(778.2, 736), epsilon: 1.0));
expect(tester.getTopLeft(sBody),
offsetMoreOrLessEquals(const Offset(778.2, 0), epsilon: 1.0));
expect(tester.getBottomRight(sBody),
offsetMoreOrLessEquals(const Offset(1178.2, 755.2), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(1178.2, 736), epsilon: 1.0));

await tester.pump();
await tester.pump(const Duration(milliseconds: 600));

expect(tester.getTopLeft(b), const Offset(70.4, 0));
expect(tester.getBottomRight(b),
offsetMoreOrLessEquals(const Offset(416.0, 788.8), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(416.0, 784), epsilon: 1.0));
expect(tester.getTopLeft(sBody),
offsetMoreOrLessEquals(const Offset(416, 0), epsilon: 1.0));
expect(tester.getBottomRight(sBody),
offsetMoreOrLessEquals(const Offset(816, 788.8), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(816, 784), epsilon: 1.0));

await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
Expand Down
35 changes: 18 additions & 17 deletions packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,24 @@ class AdaptiveScaffold extends StatefulWidget {
ValueChanged<int>? onDestinationSelected,
}) {
return Builder(
builder: (_) {
return BottomNavigationBar(
currentIndex: currentIndex ?? 0,
iconSize: iconSize,
items: destinations
.map((NavigationDestination e) => _toBottomNavItem(e))
.toList(),
onTap: onDestinationSelected,
);
builder: (BuildContext context) {
final NavigationBarThemeData currentNavBarTheme =
NavigationBarTheme.of(context);
return NavigationBarTheme(
data: currentNavBarTheme.copyWith(
iconTheme: MaterialStateProperty.resolveWith(
(Set<MaterialState> states) {
return currentNavBarTheme.iconTheme
?.resolve(states)
?.copyWith(size: iconSize) ??
IconTheme.of(context).copyWith(size: iconSize);
}),
),
child: NavigationBar(
selectedIndex: currentIndex ?? 0,
destinations: destinations,
onDestinationSelected: onDestinationSelected,
));
},
);
}
Expand Down Expand Up @@ -644,14 +653,6 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
}
}

BottomNavigationBarItem _toBottomNavItem(NavigationDestination destination) {
return BottomNavigationBarItem(
label: destination.label,
icon: destination.icon,
activeIcon: destination.selectedIcon,
);
}

class _BrickLayout extends StatelessWidget {
const _BrickLayout({
this.columns = 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_adaptive_scaffold/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_adaptive_scaffold
description: Widgets to easily build adaptive layouts, including navigation elements.
version: 0.1.3
version: 0.1.4
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {

expect(tester.getTopLeft(smallBody), Offset.zero);
expect(tester.getTopLeft(smallSBody), const Offset(200, 0));
expect(tester.getTopLeft(bottomNav), const Offset(0, 744));
expect(tester.getTopLeft(bottomNav), const Offset(0, 720));

await tester.binding.setSurfaceSize(SimulatedLayout.medium.size);
await tester.pumpWidget(SimulatedLayout.medium.app());
Expand Down Expand Up @@ -83,22 +83,22 @@ void main() {

expect(tester.getTopLeft(b), const Offset(17.6, 0));
expect(tester.getBottomRight(b),
offsetMoreOrLessEquals(const Offset(778.2, 755.2), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(778.2, 736), epsilon: 1.0));
expect(tester.getTopLeft(sBody),
offsetMoreOrLessEquals(const Offset(778.2, 0), epsilon: 1.0));
expect(tester.getBottomRight(sBody),
offsetMoreOrLessEquals(const Offset(1178.2, 755.2), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(1178.2, 736), epsilon: 1.0));

await tester.pump();
await tester.pump(const Duration(milliseconds: 600));

expect(tester.getTopLeft(b), const Offset(70.4, 0));
expect(tester.getBottomRight(b),
offsetMoreOrLessEquals(const Offset(416.0, 788.8), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(416.0, 784), epsilon: 1.0));
expect(tester.getTopLeft(sBody),
offsetMoreOrLessEquals(const Offset(416, 0), epsilon: 1.0));
expect(tester.getBottomRight(sBody),
offsetMoreOrLessEquals(const Offset(816, 788.8), epsilon: 1.0));
offsetMoreOrLessEquals(const Offset(816, 784), epsilon: 1.0));

await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
Expand Down

0 comments on commit 9e52ec4

Please sign in to comment.