Skip to content

Commit

Permalink
Remove navBarHeight use the height of each style instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3rndt committed Oct 25, 2024
1 parent 24bd019 commit 657cdae
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Set `popAction` to `PopActionType.single` to pop a single screen of the current tab if it is pressed again
- Set `popAction` to `PopActionType.none` to pop no screen of the current tab if it is pressed again
- Replaced `onSelectedTabPressWhenNoScreensPushed` with `SelectedTabPressConfig.onPressed`. You need to check the passed argument whether there are any pages pushed to that tab.
- Removed `navBarHeight` parameter. Use the `height` parameter of each style instead if needed.

### Fixed
- Adjusting the number of tabs at runtime threw an error
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class CustomNavBar extends StatelessWidget {
Widget build(BuildContext context) {
return DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: kBottomNavigationBarHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down
7 changes: 4 additions & 3 deletions lib/components/decorated_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class DecoratedNavBar extends StatelessWidget {
required this.child,
super.key,
this.decoration = const NavBarDecoration(),
this.height = kBottomNavigationBarHeight,
this.height,
});

final NavBarDecoration decoration;
final Widget child;
final double height;
final double? height;

@override
Widget build(BuildContext context) => Stack(
Expand All @@ -34,7 +34,8 @@ class DecoratedNavBar extends StatelessWidget {
left: false,
child: Container(
padding: decoration.padding,
height: height - decoration.borderHeight(),
height:
height != null ? height! - decoration.borderHeight() : null,
child: child,
),
),
Expand Down
9 changes: 0 additions & 9 deletions lib/components/persistent_tab_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class PersistentTabView extends StatefulWidget {
required this.navBarBuilder,
super.key,
this.controller,
this.navBarHeight = kBottomNavigationBarHeight,
this.navBarOverlap = const NavBarOverlap.none(),
this.margin = EdgeInsets.zero,
this.backgroundColor = Colors.white,
Expand All @@ -42,7 +41,6 @@ class PersistentTabView extends StatefulWidget {
required this.navBarBuilder,
required StatefulNavigationShell this.navigationShell,
super.key,
this.navBarHeight = kBottomNavigationBarHeight,
this.navBarOverlap = const NavBarOverlap.none(),
this.margin = EdgeInsets.zero,
this.backgroundColor = Colors.white,
Expand Down Expand Up @@ -93,12 +91,6 @@ class PersistentTabView extends StatefulWidget {
/// Defaults to [FloatingActionButtonLocation.endFloat].
final FloatingActionButtonLocation? floatingActionButtonLocation;

/// Specifies the navBarHeight
///
/// Defaults to `kBottomNavigationBarHeight` which is `56.0`.
// TODO: Get rid of this
final double navBarHeight;

/// Works similar to [Scaffold.extendBody].
///
/// If set to [NavBarOverlap.full], the tabs will extend to the bottom of
Expand Down Expand Up @@ -303,7 +295,6 @@ class _PersistentTabViewState extends State<PersistentTabView> {
NavBarConfig(
selectedIndex: _controller.index,
items: widget.tabs.map((e) => e.item).toList(),
navBarHeight: widget.navBarHeight,
onItemSelected: onItemSelected,
),
),
Expand Down
4 changes: 0 additions & 4 deletions lib/models/configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,22 @@ class NavBarConfig {
required this.selectedIndex,
required this.items,
required this.onItemSelected,
this.navBarHeight = kBottomNavigationBarHeight,
});
final int selectedIndex;
final List<ItemConfig> items;
final void Function(int) onItemSelected;
final double navBarHeight;

ItemConfig get selectedItem => items[selectedIndex];

NavBarConfig copyWith({
int? selectedIndex,
List<ItemConfig>? items,
bool Function(int)? onItemSelected,
double? navBarHeight,
}) =>
NavBarConfig(
selectedIndex: selectedIndex ?? this.selectedIndex,
items: items ?? this.items,
onItemSelected: onItemSelected ?? this.onItemSelected,
navBarHeight: navBarHeight ?? this.navBarHeight,
);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/models/navbar_overlap.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
part of "../persistent_bottom_nav_bar_v2.dart";

class NavBarOverlap {
const NavBarOverlap.full()
:
// This is the placeholder so [PersistentTabScaffold] uses the navBarHeight instead
overlap = double.infinity;
const NavBarOverlap.full() : overlap = double.infinity;

const NavBarOverlap.none() : overlap = 0.0;

Expand Down
4 changes: 3 additions & 1 deletion lib/styles/neumorphic_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class NeumorphicBottomNavBar extends StatelessWidget {
super.key,
this.navBarDecoration = const NavBarDecoration(),
this.neumorphicProperties = const NeumorphicProperties(),
this.height = kBottomNavigationBarHeight,
});

final NavBarConfig navBarConfig;
final NeumorphicProperties neumorphicProperties;
final NavBarDecoration navBarDecoration;
final double height;

Widget _getNavItem(
ItemConfig item,
Expand Down Expand Up @@ -72,7 +74,7 @@ class NeumorphicBottomNavBar extends StatelessWidget {
@override
Widget build(BuildContext context) => DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: navBarConfig.items.map((item) {
Expand Down
6 changes: 4 additions & 2 deletions lib/styles/style_10_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class Style10BottomNavBar extends StatefulWidget {
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
this.itemAnimationProperties = const ItemAnimation(),
this.height = kBottomNavigationBarHeight,
super.key,
});

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

/// This controls the animation properties of the items of the NavBar.
final ItemAnimation itemAnimationProperties;
Expand Down Expand Up @@ -41,7 +43,7 @@ class _Style10BottomNavBarState extends State<Style10BottomNavBar>
);
_animationList.add(
Tween(
begin: Offset(0, widget.navBarConfig.navBarHeight),
begin: Offset(0, widget.height),
end: Offset.zero,
)
.chain(CurveTween(curve: widget.itemAnimationProperties.curve))
Expand Down Expand Up @@ -107,7 +109,7 @@ class _Style10BottomNavBarState extends State<Style10BottomNavBar>
}
return DecoratedNavBar(
decoration: widget.navBarDecoration,
height: widget.navBarConfig.navBarHeight,
height: widget.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: widget.navBarConfig.items.map((item) {
Expand Down
6 changes: 4 additions & 2 deletions lib/styles/style_11_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class Style11BottomNavBar extends StatefulWidget {
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
this.itemAnimationProperties = const ItemAnimation(),
this.height = kBottomNavigationBarHeight,
super.key,
});

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

/// This controls the animation properties of the items of the NavBar.
final ItemAnimation itemAnimationProperties;
Expand Down Expand Up @@ -40,7 +42,7 @@ class _Style11BottomNavBarState extends State<Style11BottomNavBar>
);
_animationList.add(
Tween(
begin: Offset(0, widget.navBarConfig.navBarHeight / 1.5),
begin: Offset(0, widget.height / 1.5),
end: Offset.zero,
)
.chain(CurveTween(curve: widget.itemAnimationProperties.curve))
Expand Down Expand Up @@ -110,7 +112,7 @@ class _Style11BottomNavBarState extends State<Style11BottomNavBar>
}
return DecoratedNavBar(
decoration: widget.navBarDecoration,
height: widget.navBarConfig.navBarHeight,
height: widget.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: widget.navBarConfig.items.map((item) {
Expand Down
6 changes: 4 additions & 2 deletions lib/styles/style_12_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class Style12BottomNavBar extends StatefulWidget {
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
this.itemAnimationProperties = const ItemAnimation(),
this.height = kBottomNavigationBarHeight,
super.key,
});

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

/// This controls the animation properties of the items of the NavBar.
final ItemAnimation itemAnimationProperties;
Expand Down Expand Up @@ -41,7 +43,7 @@ class _Style12BottomNavBarState extends State<Style12BottomNavBar>
);
_animationList.add(
Tween(
begin: Offset(0, widget.navBarConfig.navBarHeight / 1.5),
begin: Offset(0, widget.height / 1.5),
end: Offset.zero,
)
.chain(CurveTween(curve: widget.itemAnimationProperties.curve))
Expand Down Expand Up @@ -125,7 +127,7 @@ class _Style12BottomNavBarState extends State<Style12BottomNavBar>
}
return DecoratedNavBar(
decoration: widget.navBarDecoration,
height: widget.navBarConfig.navBarHeight,
height: widget.height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: widget.navBarConfig.items.map((item) {
Expand Down
6 changes: 4 additions & 2 deletions lib/styles/style_13_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Style13BottomNavBar extends StatelessWidget {
Style13BottomNavBar({
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
this.height = kBottomNavigationBarHeight,
super.key,
}) : assert(
navBarConfig.items.length.isOdd,
Expand All @@ -12,6 +13,7 @@ class Style13BottomNavBar extends StatelessWidget {

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

Widget _buildItem(BuildContext context, ItemConfig item, bool isSelected) =>
Column(
Expand Down Expand Up @@ -48,7 +50,7 @@ class Style13BottomNavBar extends StatelessWidget {
children: <Widget>[
Container(
width: 150,
height: navBarConfig.navBarHeight,
height: height,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: item.activeForegroundColor,
Expand Down Expand Up @@ -96,7 +98,7 @@ class Style13BottomNavBar extends StatelessWidget {
const SizedBox(height: 23),
DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: navBarConfig.items.map((item) {
Expand Down
8 changes: 5 additions & 3 deletions lib/styles/style_14_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Style14BottomNavBar extends StatelessWidget {
Style14BottomNavBar({
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
this.height = kBottomNavigationBarHeight,
super.key,
}) : assert(
navBarConfig.items.length.isOdd,
Expand All @@ -12,6 +13,7 @@ class Style14BottomNavBar extends StatelessWidget {

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

Widget _buildItem(ItemConfig item, bool isSelected) => Column(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -52,8 +54,8 @@ class Style14BottomNavBar extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: navBarConfig.navBarHeight,
height: navBarConfig.navBarHeight,
width: height,
height: height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: item.activeForegroundColor,
Expand Down Expand Up @@ -101,7 +103,7 @@ class Style14BottomNavBar extends StatelessWidget {
const SizedBox(height: 23),
DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: navBarConfig.items.map((item) {
Expand Down
1 change: 0 additions & 1 deletion lib/styles/style_15_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Style15BottomNavBar extends StatelessWidget {
final midIndex = (navBarConfig.items.length / 2).floor();
return DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: navBarConfig.items.map((item) {
Expand Down
4 changes: 3 additions & 1 deletion lib/styles/style_16_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Style16BottomNavBar extends StatelessWidget {
Style16BottomNavBar({
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
this.height = kBottomNavigationBarHeight,
super.key,
}) : assert(
navBarConfig.items.length.isOdd,
Expand All @@ -12,6 +13,7 @@ class Style16BottomNavBar extends StatelessWidget {

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

Widget _buildItem(ItemConfig item, bool isSelected) => Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -76,7 +78,7 @@ class Style16BottomNavBar extends StatelessWidget {
final midIndex = (navBarConfig.items.length / 2).floor();
return DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: navBarConfig.items.map((item) {
Expand Down
4 changes: 3 additions & 1 deletion lib/styles/style_1_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ class Style1BottomNavBar extends StatelessWidget {
required this.navBarConfig,
super.key,
this.navBarDecoration = const NavBarDecoration(),
this.height = kBottomNavigationBarHeight,
});

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final double height;

Widget _buildItem(ItemConfig item, bool isSelected) => Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down Expand Up @@ -47,7 +49,7 @@ class Style1BottomNavBar extends StatelessWidget {
@override
Widget build(BuildContext context) => DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: navBarConfig.items.map((item) {
Expand Down
4 changes: 3 additions & 1 deletion lib/styles/style_2_bottom_navbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class Style2BottomNavBar extends StatelessWidget {
this.navBarDecoration = const NavBarDecoration(),
this.itemAnimationProperties = const ItemAnimation(),
this.itemPadding = const EdgeInsets.all(5),
this.height = kBottomNavigationBarHeight,
super.key,
});

final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
final EdgeInsets itemPadding;
final double height;

/// This controls the animation properties of the items of the NavBar.
final ItemAnimation itemAnimationProperties;
Expand Down Expand Up @@ -62,7 +64,7 @@ class Style2BottomNavBar extends StatelessWidget {
@override
Widget build(BuildContext context) => DecoratedNavBar(
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
height: height,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: navBarConfig.items.map((item) {
Expand Down
Loading

0 comments on commit 657cdae

Please sign in to comment.