Skip to content

Commit

Permalink
🔖 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
g-apparence committed Oct 12, 2023
1 parent 4672418 commit e818ca2
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 86 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.2.1]
* Fix prevent rebuilding bottom items when route change

## [1.2.0]
* Add BartMenuRoute.bottomBarBuilder to build a single item bottom bar (so you can show notification badge on it)
* Add onRouteChanged callback to BartScaffold to get notified when route change
Expand Down
3 changes: 2 additions & 1 deletion example/lib/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class _MainPageMenuState extends State<MainPageMenu> {
return BartScaffold(
routesBuilder: widget.routesBuilder,
showBottomBarOnStart: true,
bottomBar: BartBottomBar.adaptive(),
bottomBar: BartBottomBar.material3(),
// uncomment to use an exemple of custom bottom bar
// bottomBar: BartBottomBar.custom(
// bottomBarFactory: SimpleBottomBar(),
// ),
Expand Down
69 changes: 34 additions & 35 deletions lib/bart/widgets/bottom_bar/bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,39 @@ class BartBottomBarState extends State<BartBottomBar> {

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: currentIndexNotifier,
builder: ((context, int index, child) {
switch (widget.theme) {
case Theme.cupertino:
return BartCupertinoBottomBar(
routes: mainRoutes,
theme: widget.bottomBarTheme! as CupertinoBottomBarTheme,
currentIndex: index,
onTap: onTap,
);
case Theme.material:
return BartMaterialBottomBar(
routes: mainRoutes,
theme: widget.bottomBarTheme! as Material2BottomBarTheme,
currentIndex: index,
onTap: onTap,
);
case Theme.material3:
return BartMaterial3BottomBar(
routes: routes,
theme: widget.bottomBarTheme! as Material3BottomBarTheme,
currentIndex: index,
onTap: onTap,
);
default:
return widget.bottomBarCustom!.create(
context: context,
routes: mainRoutes,
currentIndex: index,
onTap: onTap,
);
}
}),
);
switch (widget.theme) {
case Theme.cupertino:
return BartCupertinoBottomBar(
routes: mainRoutes,
theme: widget.bottomBarTheme! as CupertinoBottomBarTheme,
currentIndexNotifier: currentIndexNotifier,
onTap: onTap,
);
case Theme.material:
return BartMaterialBottomBar(
routes: mainRoutes,
theme: widget.bottomBarTheme! as Material2BottomBarTheme,
currentIndexNotifier: currentIndexNotifier,
onTap: onTap,
);
case Theme.material3:
return BartMaterial3BottomBar(
routes: routes,
theme: widget.bottomBarTheme! as Material3BottomBarTheme,
currentIndexNotifier: currentIndexNotifier,
onTap: onTap,
);
default:
return ValueListenableBuilder(
valueListenable: currentIndexNotifier,
builder: (context, int index, child) {
return widget.bottomBarCustom!.create(
context: context,
routes: mainRoutes,
onTap: onTap,
currentIndex: index,
);
});
}
}
}
41 changes: 26 additions & 15 deletions lib/bart/widgets/bottom_bar/styles/bottom_bar_cupertino.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,49 @@ import 'package:bart/bart/bart_model.dart';
import 'package:bart/bart/widgets/bottom_bar/bottom_bar.dart';
import 'package:flutter/cupertino.dart';

class BartCupertinoBottomBar extends StatelessWidget {
class BartCupertinoBottomBar extends StatefulWidget {
final List<BartMenuRoute> routes;
final BottomBarTapAction onTap;
final int currentIndex;
final ValueNotifier<int> currentIndexNotifier;

final CupertinoBottomBarTheme theme;

const BartCupertinoBottomBar({
Key? key,
required this.routes,
required this.onTap,
required this.currentIndex,
required this.currentIndexNotifier,
required this.theme,
}) : super(key: key);

@override
State<BartCupertinoBottomBar> createState() => _BartCupertinoBottomBarState();
}

class _BartCupertinoBottomBarState extends State<BartCupertinoBottomBar> {
@override
Widget build(BuildContext context) {
return CupertinoTabBar(
items: getRouteWidgetList(context),
currentIndex: currentIndex,
iconSize: theme.iconSize,
border: theme.border,
backgroundColor: theme.bgColor,
activeColor: theme.selectedItemColor,
height: theme.height ?? 50.0,
inactiveColor: theme.unselectedItemColor ?? CupertinoColors.inactiveGray,
onTap: (index) => onTap(index),
return ValueListenableBuilder(
valueListenable: widget.currentIndexNotifier,
builder: ((context, int index, child) {
return CupertinoTabBar(
items: buildRouteWidgetList(context),
currentIndex: index,
iconSize: widget.theme.iconSize,
border: widget.theme.border,
backgroundColor: widget.theme.bgColor,
activeColor: widget.theme.selectedItemColor,
height: widget.theme.height ?? 50.0,
inactiveColor:
widget.theme.unselectedItemColor ?? CupertinoColors.inactiveGray,
onTap: (index) => widget.onTap(index),
);
}),
);
}

List<BottomNavigationBarItem> getRouteWidgetList(BuildContext context) =>
routes.map(
List<BottomNavigationBarItem> buildRouteWidgetList(BuildContext context) =>
widget.routes.map(
(route) {
if (route.icon != null) {
return BottomNavigationBarItem(
Expand Down
87 changes: 54 additions & 33 deletions lib/bart/widgets/bottom_bar/styles/bottom_bar_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,99 @@ import 'package:bart/bart/bart_model.dart';
import 'package:bart/bart/widgets/bottom_bar/bottom_bar.dart';
import 'package:flutter/material.dart';

class BartMaterialBottomBar extends StatelessWidget {
class BartMaterialBottomBar extends StatefulWidget {
final List<BartMenuRoute> routes;
final BottomBarTapAction onTap;
final int currentIndex;
final Material2BottomBarTheme theme;
final ValueNotifier<int> currentIndexNotifier;

const BartMaterialBottomBar({
Key? key,
required this.routes,
required this.onTap,
required this.currentIndex,
required this.currentIndexNotifier,
required this.theme,
}) : super(key: key);

@override
State<BartMaterialBottomBar> createState() => _BartMaterialBottomBarState();
}

class _BartMaterialBottomBarState extends State<BartMaterialBottomBar> {
@override
Widget build(BuildContext context) {
return SizedBox(
height: theme.height,
child: BottomNavigationBar(
items: routeWidgetList,
currentIndex: currentIndex,
elevation: theme.elevation,
iconSize: theme.iconSize,
backgroundColor: theme.bgColor,
type: theme.type ?? BottomNavigationBarType.fixed,
selectedIconTheme: theme.iconThemeData,
selectedItemColor: theme.selectedItemColor,
unselectedItemColor: theme.unselectedItemColor,
selectedFontSize: theme.selectedFontSize,
unselectedFontSize: theme.unselectedFontSize,
onTap: (index) => onTap(index),
),
return ValueListenableBuilder(
valueListenable: widget.currentIndexNotifier,
builder: (context, int index, child) {
return SizedBox(
height: widget.theme.height,
child: BottomNavigationBar(
items: routeWidgetList,
currentIndex: widget.currentIndexNotifier.value,
elevation: widget.theme.elevation,
iconSize: widget.theme.iconSize,
backgroundColor: widget.theme.bgColor,
type: widget.theme.type ?? BottomNavigationBarType.fixed,
selectedIconTheme: widget.theme.iconThemeData,
selectedItemColor: widget.theme.selectedItemColor,
unselectedItemColor: widget.theme.unselectedItemColor,
selectedFontSize: widget.theme.selectedFontSize,
unselectedFontSize: widget.theme.unselectedFontSize,
onTap: (index) => widget.onTap(index),
),
);
},
);
}

List<BottomNavigationBarItem> get routeWidgetList => routes
List<BottomNavigationBarItem> get routeWidgetList => widget.routes
.map((route) => BottomNavigationBarItem(
icon: Icon(route.icon),
label: route.label,
))
.toList();
}

class BartMaterial3BottomBar extends StatelessWidget {
class BartMaterial3BottomBar extends StatefulWidget {
final List<BartMenuRoute> routes;
final BottomBarTapAction onTap;
final int currentIndex;
final Material3BottomBarTheme theme;
final ValueNotifier<int> currentIndexNotifier;

const BartMaterial3BottomBar({
Key? key,
required this.routes,
required this.onTap,
required this.currentIndex,
required this.currentIndexNotifier,
required this.theme,
}) : super(key: key);

@override
State<BartMaterial3BottomBar> createState() => _BartMaterial3BottomBarState();
}

class _BartMaterial3BottomBarState extends State<BartMaterial3BottomBar> {
@override
Widget build(BuildContext context) {
return NavigationBar(
selectedIndex: currentIndex,
destinations: getRouteWidgetList(context),
elevation: theme.elevation,
backgroundColor: theme.bgColor,
height: theme.height,
onDestinationSelected: onTap,
animationDuration: theme.animationDuration,
labelBehavior: theme.labelBehavior,
return ValueListenableBuilder(
valueListenable: widget.currentIndexNotifier,
builder: (context, int index, child) {
return NavigationBar(
selectedIndex: index,
destinations: getRouteWidgetList(context),
elevation: widget.theme.elevation,
backgroundColor: widget.theme.bgColor,
height: widget.theme.height,
onDestinationSelected: widget.onTap,
animationDuration: widget.theme.animationDuration,
labelBehavior: widget.theme.labelBehavior,
);
},
);
}

List<NavigationDestination> getRouteWidgetList(BuildContext context) => routes
List<NavigationDestination> getRouteWidgetList(BuildContext context) =>
widget.routes
.where(
(element) => element.type == BartMenuRouteType.bottomNavigation)
.map(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: bart
description: A bottom navigation bar using navigator 2 for switching tabs
version: 1.2.0
version: 1.2.1
homepage: https://en.apparence.io
repository: https://github.com/Apparence-io/bart

Expand Down
2 changes: 1 addition & 1 deletion test/bart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ void main() {
final materialBottomBar =
tester.firstWidget(find.byType(BartMaterialBottomBar))
as BartMaterialBottomBar;
expect(materialBottomBar.currentIndex, equals(1));
expect(materialBottomBar.currentIndexNotifier.value, equals(1));
});

testWidgets(
Expand Down

0 comments on commit e818ca2

Please sign in to comment.