145 lines
4.7 KiB
Dart
145 lines
4.7 KiB
Dart
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/util/trans.dart';
|
|
import 'package:badges/badges.dart';
|
|
import 'package:flurry/flurry.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:gradient_bottom_navigation_bar/gradient_bottom_navigation_bar.dart';
|
|
|
|
// ignore: must_be_immutable
|
|
class BottomNavigator extends StatefulWidget {
|
|
int bottomNavIndex = 0;
|
|
BottomNavigator({this.bottomNavIndex}) {
|
|
this.bottomNavIndex = bottomNavIndex;
|
|
}
|
|
|
|
@override
|
|
_NawDrawerWidget createState() => _NawDrawerWidget();
|
|
}
|
|
|
|
class _NawDrawerWidget extends State<BottomNavigator> with Trans {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Color bgrColor = Color(0xffb4f500);
|
|
final Color bgrColorEnd = Colors.blue;
|
|
final Color active = Colors.black;
|
|
final Color inactive = Colors.black26;
|
|
setContext(context);
|
|
|
|
return GradientBottomNavigationBar(
|
|
currentIndex: widget.bottomNavIndex, // this will be set when a new tab is tapped
|
|
backgroundColorStart: bgrColorEnd,
|
|
backgroundColorEnd: bgrColor,
|
|
fixedColor: active,
|
|
items: [
|
|
BottomNavigationBarItem(
|
|
backgroundColor: bgrColor,
|
|
icon: badgedIcon(inactive, Icons.home, "home"),
|
|
activeIcon: badgedIcon(active, Icons.home, "home"),
|
|
title: new Text(t("Home"), style: TextStyle(fontSize: 12)),
|
|
),
|
|
BottomNavigationBarItem(
|
|
backgroundColor: bgrColor,
|
|
icon: new Icon(Icons.trending_up, color: inactive),
|
|
activeIcon: new Icon(
|
|
Icons.trending_up,
|
|
color: active,
|
|
),
|
|
title: new Text(
|
|
t("My Development"),
|
|
style: TextStyle(fontSize: 12),
|
|
),
|
|
),
|
|
BottomNavigationBarItem(
|
|
backgroundColor: bgrColor,
|
|
icon: new Icon(Icons.featured_play_list, color: inactive),
|
|
activeIcon: new Icon(
|
|
Icons.featured_play_list,
|
|
color: active,
|
|
),
|
|
title: new Text(
|
|
t("My Training Plan"),
|
|
style: TextStyle(fontSize: 12),
|
|
),
|
|
),
|
|
BottomNavigationBarItem(
|
|
backgroundColor: bgrColor,
|
|
icon: badgedIcon(inactive, Icons.person, "account"),
|
|
activeIcon: badgedIcon(active, Icons.person, "account"),
|
|
title: Text(
|
|
AppLocalizations.of(context).translate("Account"),
|
|
style: TextStyle(fontSize: 12),
|
|
)),
|
|
BottomNavigationBarItem(
|
|
backgroundColor: bgrColor,
|
|
icon: Icon(Icons.settings, color: inactive),
|
|
activeIcon: new Icon(
|
|
Icons.settings,
|
|
color: active,
|
|
),
|
|
title: Text(t("Settings"), style: TextStyle(fontSize: 12)))
|
|
],
|
|
onTap: (index) {
|
|
setState(() {
|
|
widget.bottomNavIndex = index;
|
|
switch (index) {
|
|
case 0:
|
|
Navigator.of(context).pop();
|
|
Flurry.logEvent("Home");
|
|
Navigator.of(context).pushNamed('home');
|
|
|
|
break;
|
|
case 1:
|
|
Navigator.of(context).pop();
|
|
Flurry.logEvent("myDevelopment");
|
|
Navigator.of(context).pushNamed('myDevelopment');
|
|
break;
|
|
case 2:
|
|
Navigator.of(context).pop();
|
|
Flurry.logEvent("myExercisePlan");
|
|
Navigator.of(context).pushNamed('myExercisePlan');
|
|
|
|
break;
|
|
case 3:
|
|
Navigator.of(context).pop();
|
|
Flurry.logEvent("Account");
|
|
Navigator.of(context).pushNamed('account');
|
|
|
|
break;
|
|
case 4:
|
|
Navigator.of(context).pop();
|
|
Flurry.logEvent("Settings");
|
|
Navigator.of(context).pushNamed('settings');
|
|
|
|
break;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
Widget badgedIcon(Color color, IconData icon, String badgeKey) {
|
|
bool show = Cache().getBadges()[badgeKey] != null;
|
|
int counter = Cache().getBadges()[badgeKey] != null ? Cache().getBadges()[badgeKey] : 0;
|
|
return Badge(
|
|
position: BadgePosition.topEnd(top: -10, end: -10),
|
|
animationDuration: Duration(milliseconds: 500),
|
|
animationType: BadgeAnimationType.slide,
|
|
badgeColor: Colors.red,
|
|
showBadge: show,
|
|
badgeContent: Text(
|
|
counter.toString(),
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
child: Icon(
|
|
icon,
|
|
color: color,
|
|
),
|
|
);
|
|
}
|
|
}
|