Skip to content

Commit 9529b27

Browse files
fix: Navigation Bar Custom bugs
1 parent 3d66cad commit 9529b27

11 files changed

Lines changed: 59 additions & 346 deletions

File tree

.fvmrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ migrate_working_dir/
1818
*.iws
1919
.idea/
2020

21-
# The .vscode folder contains launch configuration and tasks you configure in
22-
# VS Code which you may wish to be included in version control, so this line
23-
# is commented out by default.
24-
#.vscode/
21+
.vscode/
2522

2623
# Flutter/Dart/Pub related
2724
**/doc/api/
@@ -47,12 +44,12 @@ app.*.map.json
4744
android/local.properties
4845
/android/local.properties
4946
pubspec.lock
50-
.vscode/launch.json
5147
example/ios/Podfile.lock
5248
macos/Podfile.lock
5349

54-
# FVM Version Cache
55-
.fvm/
56-
57-
ios/Flutter/flutter_export_environment.sh
58-
ios/Flutter/Generated.xcconfig
50+
# Flutter tool output (flutter pub get); nested example/*/.gitignore also lists these
51+
**/ios/Flutter/Generated.xcconfig
52+
**/ios/Flutter/flutter_export_environment.sh
53+
**/Runner/GeneratedPluginRegistrant.h
54+
**/Runner/GeneratedPluginRegistrant.m
55+
**/io/flutter/plugins/GeneratedPluginRegistrant.java

.vscode/settings.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

example/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java

Lines changed: 0 additions & 99 deletions
This file was deleted.

example/ios/Flutter/Generated.xcconfig

Lines changed: 0 additions & 14 deletions
This file was deleted.

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

example/ios/Runner/GeneratedPluginRegistrant.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

example/ios/Runner/GeneratedPluginRegistrant.m

Lines changed: 0 additions & 119 deletions
This file was deleted.

lib/src/framework/internal_widgets/bottom_navigation_bar/bottom_navigation_bar.dart

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,6 @@ class BottomNavigationBar extends StatefulWidget {
3939
}
4040

4141
class _BottomNavigationBarState extends State<BottomNavigationBar> {
42-
late int _selectedIndex;
43-
44-
@override
45-
void initState() {
46-
super.initState();
47-
_selectedIndex = widget.selectedIndex;
48-
}
49-
50-
@override
51-
void didUpdateWidget(BottomNavigationBar oldWidget) {
52-
if (widget.selectedIndex != oldWidget.selectedIndex) {
53-
_selectedIndex = widget.selectedIndex;
54-
}
55-
super.didUpdateWidget(oldWidget);
56-
}
57-
58-
void _handleDestinationSelected(int index) {
59-
_selectedIndex = index;
60-
if (widget.onDestinationSelected != null) {
61-
widget.onDestinationSelected!(index);
62-
}
63-
}
64-
6542
@override
6643
Widget build(BuildContext context) {
6744
return DecoratedBox(
@@ -72,8 +49,8 @@ class _BottomNavigationBarState extends State<BottomNavigationBar> {
7249
backgroundColor: widget.backgroundColor,
7350
animationDuration: widget.animationDuration,
7451
elevation: widget.elevation,
75-
selectedIndex: _selectedIndex,
76-
onDestinationSelected: _handleDestinationSelected,
52+
selectedIndex: widget.selectedIndex,
53+
onDestinationSelected: widget.onDestinationSelected,
7754
surfaceTintColor: widget.surfaceTintColor,
7855
indicatorColor: widget.indicatorColor,
7956
indicatorShape: widget.indicatorShape,

lib/src/framework/widgets/navigation_bar_custom.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@ class VWNavigationBarCustom
3434
) {
3535
if (index >= 0 && index < visibleChildren.length) {
3636
final selectedChild = visibleChildren[index];
37-
final onPageSelected = selectedChild.props.onSelect;
38-
final onPageSelectedAction = onPageSelected?['action'];
39-
if (onPageSelectedAction != null) {
40-
payload.executeAction(
41-
ActionFlow.fromJson(onPageSelectedAction),
42-
triggerType: 'onPageSelected',
43-
);
37+
final onSelect = selectedChild.props.onSelect;
38+
final type = onSelect?['type'] as String?;
39+
40+
if (type == 'action') {
41+
final action = onSelect?['action'];
42+
if (action != null) {
43+
payload.executeAction(
44+
ActionFlow.fromJson(action),
45+
triggerType: 'onNavBarItemSelected',
46+
);
47+
}
48+
// Action-type items execute their action but do not change the selected tab.
49+
return;
4450
}
4551
}
4652
onDestinationSelected?.call(index);
@@ -55,7 +61,11 @@ class VWNavigationBarCustom
5561
destinations.add(
5662
InheritedNavigationBarController(
5763
itemIndex: i,
58-
child: navItems[i].toWidget(payload),
64+
child: Builder(
65+
builder: (context) => navItems[i].toWidget(
66+
payload.copyWith(buildContext: context),
67+
),
68+
),
5969
),
6070
);
6171
}

0 commit comments

Comments
 (0)