Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3rndt committed May 26, 2024
2 parents b5e42cb + f50dfc1 commit cc0ef4d
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,71 +149,67 @@ class CustomNavBar extends StatelessWidget {
final NavBarConfig navBarConfig;
final NavBarDecoration navBarDecoration;
CustomNavBar({
Key key,
@required this.navBarConfig,
const CustomNavBar({
super.key,
required this.navBarConfig,
this.navBarDecoration = const NavBarDecoration(),
}) : super(key: key);
});
Widget _buildItem(ItemConfig item, bool isSelected) {
final title = item.title;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
children: [
Expanded(
child: IconTheme(
data: IconThemeData(
size: item.iconSize,
color: isSelected
? item.activeColorPrimary
: item.inactiveColorPrimary),
size: item.iconSize,
color: isSelected
? item.activeForegroundColor
: item.inactiveForegroundColor,
),
child: isSelected ? item.icon : item.inactiveIcon,
),
),
Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Material(
type: MaterialType.transparency,
child: FittedBox(
child: Text(
item.title,
style: item.textStyle.apply(
color: isSelected
? item.activeColorPrimary
: item.inactiveColorPrimary,
if (title != null)
Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Material(
type: MaterialType.transparency,
child: FittedBox(
child: Text(
title,
style: item.textStyle.apply(
color: isSelected
? item.activeForegroundColor
: item.inactiveForegroundColor,
),
),
),
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
return DecoratedNavBar(
decoration: this.navBarDecoration,
filter: this.navBarConfig.selectedItem.filter,
opacity: this.navBarConfig.selectedItem.opacity,
height: this.navBarConfig.navBarHeight,
decoration: navBarDecoration,
height: navBarConfig.navBarHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: this.navBarConfig.items.map((item) {
int index = this.navBarConfig.items.indexOf(item);
return Expanded(
child: InkWell(
onTap: () {
this.navBarConfig.onItemSelected(index); // This is the most important part. Without this, nothing would happen if you tap on an item.
},
child: _buildItem(
item,
this.navBarConfig.selectedIndex == index,
children: [
for (final (index, item) in navBarConfig.items.indexed)
Expanded(
child: InkWell(
// This is the most important part. Without this, nothing would happen if you tap on an item.
onTap: () => navBarConfig.onItemSelected(index),
child: _buildItem(item, navBarConfig.selectedIndex == index),
),
),
);
}).toList(),
],
),
);
}
Expand Down

0 comments on commit cc0ef4d

Please sign in to comment.