Skip to content

Commit 91ef7b4

Browse files
fmt-Println-MKOnploi
authored andcommitted
[flutter_adaptive_scaffold] exchange BottomNavigationBar with NavigationBar (flutter#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.
1 parent 6840c16 commit 91ef7b4

5 files changed

Lines changed: 33 additions & 28 deletions

File tree

packages/flutter_adaptive_scaffold/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.4
2+
3+
* Use Material 3 NavigationBar instead of BottomNavigationBar
4+
15
## 0.1.3
26

37
* Fixes `groupAlignment` property not available in `standardNavigationRail` - [flutter/flutter#121994](https://github.com/flutter/flutter/issues/121994)

packages/flutter_adaptive_scaffold/example/test/adaptive_scaffold_demo_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void main() {
3333
expect(smallBody, findsOneWidget);
3434
expect(bnav, findsOneWidget);
3535
expect(tester.getTopLeft(smallBody), Offset.zero);
36-
expect(tester.getTopLeft(bnav), const Offset(0, 744));
36+
expect(tester.getTopLeft(bnav), const Offset(0, 720));
3737
expect(body, findsNothing);
3838
expect(largeBody, findsNothing);
3939
expect(pnav, findsNothing);
@@ -73,22 +73,22 @@ void main() {
7373

7474
expect(tester.getTopLeft(b), const Offset(17.6, 0));
7575
expect(tester.getBottomRight(b),
76-
offsetMoreOrLessEquals(const Offset(778.2, 755.2), epsilon: 1.0));
76+
offsetMoreOrLessEquals(const Offset(778.2, 736), epsilon: 1.0));
7777
expect(tester.getTopLeft(sBody),
7878
offsetMoreOrLessEquals(const Offset(778.2, 0), epsilon: 1.0));
7979
expect(tester.getBottomRight(sBody),
80-
offsetMoreOrLessEquals(const Offset(1178.2, 755.2), epsilon: 1.0));
80+
offsetMoreOrLessEquals(const Offset(1178.2, 736), epsilon: 1.0));
8181

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

8585
expect(tester.getTopLeft(b), const Offset(70.4, 0));
8686
expect(tester.getBottomRight(b),
87-
offsetMoreOrLessEquals(const Offset(416.0, 788.8), epsilon: 1.0));
87+
offsetMoreOrLessEquals(const Offset(416.0, 784), epsilon: 1.0));
8888
expect(tester.getTopLeft(sBody),
8989
offsetMoreOrLessEquals(const Offset(416, 0), epsilon: 1.0));
9090
expect(tester.getBottomRight(sBody),
91-
offsetMoreOrLessEquals(const Offset(816, 788.8), epsilon: 1.0));
91+
offsetMoreOrLessEquals(const Offset(816, 784), epsilon: 1.0));
9292

9393
await tester.pump();
9494
await tester.pump(const Duration(milliseconds: 200));

packages/flutter_adaptive_scaffold/lib/src/adaptive_scaffold.dart

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,24 @@ class AdaptiveScaffold extends StatefulWidget {
316316
ValueChanged<int>? onDestinationSelected,
317317
}) {
318318
return Builder(
319-
builder: (_) {
320-
return BottomNavigationBar(
321-
currentIndex: currentIndex ?? 0,
322-
iconSize: iconSize,
323-
items: destinations
324-
.map((NavigationDestination e) => _toBottomNavItem(e))
325-
.toList(),
326-
onTap: onDestinationSelected,
327-
);
319+
builder: (BuildContext context) {
320+
final NavigationBarThemeData currentNavBarTheme =
321+
NavigationBarTheme.of(context);
322+
return NavigationBarTheme(
323+
data: currentNavBarTheme.copyWith(
324+
iconTheme: MaterialStateProperty.resolveWith(
325+
(Set<MaterialState> states) {
326+
return currentNavBarTheme.iconTheme
327+
?.resolve(states)
328+
?.copyWith(size: iconSize) ??
329+
IconTheme.of(context).copyWith(size: iconSize);
330+
}),
331+
),
332+
child: NavigationBar(
333+
selectedIndex: currentIndex ?? 0,
334+
destinations: destinations,
335+
onDestinationSelected: onDestinationSelected,
336+
));
328337
},
329338
);
330339
}
@@ -644,14 +653,6 @@ class _AdaptiveScaffoldState extends State<AdaptiveScaffold> {
644653
}
645654
}
646655

647-
BottomNavigationBarItem _toBottomNavItem(NavigationDestination destination) {
648-
return BottomNavigationBarItem(
649-
label: destination.label,
650-
icon: destination.icon,
651-
activeIcon: destination.selectedIcon,
652-
);
653-
}
654-
655656
class _BrickLayout extends StatelessWidget {
656657
const _BrickLayout({
657658
this.columns = 1,

packages/flutter_adaptive_scaffold/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_adaptive_scaffold
22
description: Widgets to easily build adaptive layouts, including navigation elements.
3-
version: 0.1.3
3+
version: 0.1.4
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold
66

packages/flutter_adaptive_scaffold/test/adaptive_scaffold_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void main() {
3333

3434
expect(tester.getTopLeft(smallBody), Offset.zero);
3535
expect(tester.getTopLeft(smallSBody), const Offset(200, 0));
36-
expect(tester.getTopLeft(bottomNav), const Offset(0, 744));
36+
expect(tester.getTopLeft(bottomNav), const Offset(0, 720));
3737

3838
await tester.binding.setSurfaceSize(SimulatedLayout.medium.size);
3939
await tester.pumpWidget(SimulatedLayout.medium.app());
@@ -83,22 +83,22 @@ void main() {
8383

8484
expect(tester.getTopLeft(b), const Offset(17.6, 0));
8585
expect(tester.getBottomRight(b),
86-
offsetMoreOrLessEquals(const Offset(778.2, 755.2), epsilon: 1.0));
86+
offsetMoreOrLessEquals(const Offset(778.2, 736), epsilon: 1.0));
8787
expect(tester.getTopLeft(sBody),
8888
offsetMoreOrLessEquals(const Offset(778.2, 0), epsilon: 1.0));
8989
expect(tester.getBottomRight(sBody),
90-
offsetMoreOrLessEquals(const Offset(1178.2, 755.2), epsilon: 1.0));
90+
offsetMoreOrLessEquals(const Offset(1178.2, 736), epsilon: 1.0));
9191

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

9595
expect(tester.getTopLeft(b), const Offset(70.4, 0));
9696
expect(tester.getBottomRight(b),
97-
offsetMoreOrLessEquals(const Offset(416.0, 788.8), epsilon: 1.0));
97+
offsetMoreOrLessEquals(const Offset(416.0, 784), epsilon: 1.0));
9898
expect(tester.getTopLeft(sBody),
9999
offsetMoreOrLessEquals(const Offset(416, 0), epsilon: 1.0));
100100
expect(tester.getBottomRight(sBody),
101-
offsetMoreOrLessEquals(const Offset(816, 788.8), epsilon: 1.0));
101+
offsetMoreOrLessEquals(const Offset(816, 784), epsilon: 1.0));
102102

103103
await tester.pump();
104104
await tester.pump(const Duration(milliseconds: 200));

0 commit comments

Comments
 (0)