workouttest_app/lib/widgets/bottom_nav.dart
2021-03-28 12:45:14 +02:00

126 lines
4.2 KiB
Dart

import 'package:aitrainer_app/library/gradient_bottom_navigation_bar.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';
// 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 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: Text(t("Home"), style: TextStyle(fontSize: 12)),
),
BottomNavigationBarItem(
backgroundColor: bgrColor,
icon: Common.badgedIcon(inactive, Icons.trending_up, "development"),
activeIcon: Common.badgedIcon(active, Icons.trending_up, "development"),
title: Text(
t("My Development"),
style: TextStyle(fontSize: 12),
),
),
BottomNavigationBarItem(
backgroundColor: bgrColor,
icon: Icon(Icons.featured_play_list, color: inactive),
activeIcon: Icon(
Icons.featured_play_list,
color: active,
),
title: 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(
t("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))),
],
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;
}
});
});
}
}