142 lines
4.8 KiB
Dart
142 lines
4.8 KiB
Dart
import 'package:aitrainer_app/util/app_localization.dart';
|
|
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/service/logging.dart';
|
|
import 'package:aitrainer_app/util/common.dart';
|
|
import 'package:aitrainer_app/util/enums.dart';
|
|
import 'package:aitrainer_app/util/track.dart';
|
|
import 'package:aitrainer_app/util/trans.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, Logging {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(BottomNavigator oldWidget) {
|
|
Cache().initBadges();
|
|
|
|
super.didUpdateWidget(oldWidget);
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
Cache().initBadges();
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@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: Common.badgedIcon(inactive, Icons.home, "home"),
|
|
activeIcon: Common.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: Common.badgedIcon(inactive, Icons.person, "account"),
|
|
activeIcon: Common.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: Icon(Icons.settings, color: active),
|
|
title: Text(t("Settings"), style: TextStyle(fontSize: 12))),
|
|
/* BottomNavigationBarItem(
|
|
backgroundColor: bgrColor,
|
|
icon: Icon(Icons.multiple_stop, color: inactive),
|
|
activeIcon: Icon(Icons.multiple_stop, color: active),
|
|
title: Text(t("Multi test"), style: TextStyle(fontSize: 12))) */
|
|
],
|
|
onTap: (index) {
|
|
setState(() {
|
|
widget.bottomNavIndex = index;
|
|
switch (index) {
|
|
case 0:
|
|
Navigator.of(context).pop();
|
|
Track().track(TrackingEvent.home);
|
|
Navigator.of(context).pushNamed('home');
|
|
|
|
break;
|
|
case 1:
|
|
Navigator.of(context).pop();
|
|
Track().track(TrackingEvent.my_development);
|
|
Navigator.of(context).pushNamed('myDevelopment');
|
|
break;
|
|
case 2:
|
|
Navigator.of(context).pop();
|
|
Track().track(TrackingEvent.my_exerciseplan);
|
|
Navigator.of(context).pushNamed('myExercisePlan');
|
|
|
|
break;
|
|
case 3:
|
|
Navigator.of(context).pop();
|
|
Track().track(TrackingEvent.account);
|
|
Navigator.of(context).pushNamed('account');
|
|
|
|
break;
|
|
case 4:
|
|
Navigator.of(context).pop();
|
|
Track().track(TrackingEvent.settings);
|
|
Navigator.of(context).pushNamed('settings');
|
|
|
|
break;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|