import 'dart:collection'; import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/repository/customer_repository.dart'; import 'package:aitrainer_app/repository/exercise_repository.dart'; import 'package:aitrainer_app/util/enums.dart'; import 'package:aitrainer_app/util/track.dart'; import 'package:aitrainer_app/widgets/dialog_common.dart'; import 'package:aitrainer_app/widgets/dialog_premium.dart'; import 'package:badges/badges.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:aitrainer_app/util/trans.dart'; import 'package:aitrainer_app/widgets/app_bar.dart'; import 'package:aitrainer_app/widgets/bottom_nav.dart'; import 'package:aitrainer_app/widgets/image_button.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class MyDevelopmentPage extends StatefulWidget { @override _MyDevelopmentPage createState() => _MyDevelopmentPage(); } class _MyDevelopmentPage extends State with Trans { @override Widget build(BuildContext context) { final ExerciseRepository exerciseRepository = ExerciseRepository(); final CustomerRepository customerRepository = CustomerRepository(); final LinkedHashMap args = LinkedHashMap(); setContext(context); double mediaWidth = MediaQuery.of(context).size.width; double imageWidth = (mediaWidth - 45) / 2; bool showExerciseLogBadge = Cache().getBadges()["exerciseLog"] != null; int counterExerciseLogBadge = Cache().getBadges()["exerciseLog"] != null ? Cache().getBadges()["exerciseLog"] : 0; bool showMuscleDevelopmentBadge = Cache().getBadges()["muscleDevelopment"] != null; int counterMuscleDevelopmentBadge = Cache().getBadges()["muscleDevelopment"] != null ? Cache().getBadges()["muscleDevelopment"] : 0; return Scaffold( appBar: AppBarNav(depth: 0), body: Container( padding: EdgeInsets.all(10), decoration: BoxDecoration( image: DecorationImage( image: AssetImage('asset/image/WT_menu_dark.jpg'), fit: BoxFit.cover, alignment: Alignment.center, ), ), child: CustomScrollView(scrollDirection: Axis.vertical, slivers: [ SliverGrid( delegate: SliverChildListDelegate([ Badge( padding: EdgeInsets.all(8), position: BadgePosition.topEnd(top: -5, end: -3), animationDuration: Duration(milliseconds: 500), animationType: BadgeAnimationType.slide, badgeColor: Colors.red, showBadge: showExerciseLogBadge, badgeContent: Text(counterExerciseLogBadge.toString(), style: TextStyle( color: Colors.white, fontSize: 16, )), child: ImageButton( width: imageWidth, textAlignment: Alignment.topCenter, text: t("My Training Logs"), style: GoogleFonts.robotoMono( textStyle: TextStyle( fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))), image: "asset/image/edzesnaplom400400.jpg", left: 5, onTap: () => Navigator.of(context).pushNamed('mydevelopmentLog', arguments: args), isLocked: false, )), Badge( elevation: 0, padding: EdgeInsets.all(0), position: BadgePosition.topStart(top: -12, start: -12), animationDuration: Duration(milliseconds: 1500), animationType: BadgeAnimationType.fade, badgeColor: Colors.transparent, showBadge: Cache().hasPurchased, badgeContent: IconButton( iconSize: 36, onPressed: () => showDialog( context: context, builder: (BuildContext context) { return DialogCommon( title: t("Premium function"), descriptions: Cache().canTrial() ? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription") : t("This is a premium function, you can reach it only with a valid subscription"), onCancel: () => Navigator.of(context).pop(), onTap: () => Navigator.of(context).pop(), text: '', ); }), icon: Icon( Icons.star, color: Colors.orange[600], )), child: ImageButton( width: imageWidth, textAlignment: Alignment.topLeft, text: t("My Whole Body Development"), style: GoogleFonts.robotoMono( textStyle: TextStyle( fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4)), ), image: "asset/image/testemfejl400x400.jpg", left: 5, onTap: () => { if (Cache().userLoggedIn != null) { args['customerId'] = Cache().userLoggedIn!.customerId, Navigator.of(context).pushNamed('mydevelopmentBodyPage', arguments: args) } else { showDialog( context: context, builder: (BuildContext context) { return DialogCommon( warning: true, title: t("Warning"), descriptions: t("Please log in"), description2: t("because only that way can we show you the personalized development diagrams and analysises"), text: "OK", onTap: () => Navigator.of(context).popAndPushNamed("login"), onCancel: () => { Navigator.of(context).pop(), }, ); }) } }, isLocked: true, )), Badge( elevation: 0, padding: EdgeInsets.all(0), position: BadgePosition.topStart(top: -12, start: -12), animationDuration: Duration(milliseconds: 1500), animationType: BadgeAnimationType.fade, badgeColor: Colors.transparent, showBadge: Cache().hasPurchased, badgeContent: IconButton( iconSize: 36, onPressed: () => showDialog( context: context, builder: (BuildContext context) { return DialogCommon( title: t("Premium function"), descriptions: Cache().canTrial() ? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription") : t("This is a premium function, you can reach it only with a valid subscription"), onCancel: () => Navigator.of(context).pop(), onTap: () => Navigator.of(context).pop(), text: '', ); }), icon: Icon( Icons.star, color: Colors.orange[600], )), child: Badge( padding: EdgeInsets.all(8), position: BadgePosition.topEnd(top: -5, end: -3), animationDuration: Duration(milliseconds: 500), animationType: BadgeAnimationType.slide, badgeColor: Colors.red, showBadge: showMuscleDevelopmentBadge, badgeContent: Text(counterMuscleDevelopmentBadge.toString(), style: TextStyle( color: Colors.white, fontSize: 16, )), child: ImageButton( width: imageWidth, textAlignment: Alignment.topLeft, text: t("Development Of Muscles"), style: GoogleFonts.robotoMono( textStyle: TextStyle( fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))), image: "asset/image/izomcsop400400.jpg", left: 5, onTap: () => {Navigator.of(context).pushNamed('mydevelopmentMusclePage', arguments: args)}, isLocked: true, ))), Badge( elevation: 0, padding: EdgeInsets.all(0), position: BadgePosition.topStart(top: -12, start: -12), animationDuration: Duration(milliseconds: 1500), animationType: BadgeAnimationType.fade, badgeColor: Colors.transparent, showBadge: Cache().hasPurchased, badgeContent: IconButton( iconSize: 36, onPressed: () => showDialog( context: context, builder: (BuildContext context) { return DialogCommon( title: t("Premium function"), descriptions: Cache().canTrial() ? t("This is a premium function, you can reach it outside of the trial period only with a valid subscription") : t("This is a premium function, you can reach it only with a valid subscription"), onCancel: () => Navigator.of(context).pop(), onTap: () => Navigator.of(context).pop(), text: '', ); }), icon: Icon( Icons.star, color: Colors.orange[600], )), child: ImageButton( width: imageWidth, left: 5, textAlignment: Alignment.topLeft, text: t("Predictions"), style: GoogleFonts.robotoMono( textStyle: TextStyle( fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))), image: "asset/image/predictions.jpg", onTap: () => { if (Cache().userLoggedIn != null) { Track().track(TrackingEvent.prediction), showDialog( context: context, builder: (BuildContext context) { return DialogPremium( unlocked: Cache().hasPurchased, unlockRound: 12, function: "Predictions", unlockedText: null, onTap: () => {Navigator.of(context).pop()}, ); }) } }, isLocked: true, )), //developmentWidget(imageWidth, "Development Size", "asset/image/predictions.jpg", TrackingEvent.my_size_development, args), hiddenWidget(customerRepository, exerciseRepository), ]), gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, mainAxisSpacing: 15.0, crossAxisSpacing: 15.0, childAspectRatio: 1.0, ), ) ])), bottomNavigationBar: BottomNavigator(bottomNavIndex: 1)); } Widget developmentWidget(double imageWidth, String title, String imageUrl, TrackingEvent trackingEvent, LinkedHashMap args) { return ImageButton( width: imageWidth, left: 5, textAlignment: Alignment.topLeft, text: t(title), style: GoogleFonts.robotoMono( textStyle: TextStyle(fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, backgroundColor: Colors.black54.withOpacity(0.4))), image: imageUrl, onTap: () => { if (Cache().userLoggedIn != null) { Track().track(trackingEvent), SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]), Future.delayed(Duration(seconds: 400)), Navigator.of(context).pushNamed('mydevelopmentSizesPage', arguments: args), /* showDialog( context: context, builder: (BuildContext context) { return DialogPremium( unlocked: Cache().hasPurchased, unlockRound: 12, function: "Predictions", unlockedText: null, onTap: () => {Navigator.of(context).pop()}, ); }) */ } }, isLocked: true, ); } Widget hiddenWidget(CustomerRepository customerRepository, ExerciseRepository exerciseRepository) { final LinkedHashMap args = LinkedHashMap(); if (Cache().getTrainee() != null) { return TextButton( style: TextButton.styleFrom( padding: EdgeInsets.all(20), primary: Colors.white, onSurface: Colors.blueAccent, ), onPressed: () => { if (Cache().getTrainee() != null) { args['exerciseRepository'] = exerciseRepository, args['customerRepository'] = customerRepository, args['customerId'] = Cache().getTrainee()!.customerId, Navigator.of(context).pushNamed('exerciseLogPage', arguments: args) }, }, child: Text( t("My Trainee's Exercise Logs"), style: TextStyle(fontSize: 18), )); } else { return Container(); } } void callBackExerciseLog(ExerciseRepository exerciseRepository, CustomerRepository customerRepository) { if (Cache().userLoggedIn != null) { final LinkedHashMap args = LinkedHashMap(); args['exerciseRepository'] = exerciseRepository; args['customerRepository'] = customerRepository; args['customerId'] = Cache().userLoggedIn!.customerId; Navigator.of(context).pushNamed('exerciseLogPage', arguments: args); } else { showDialog( context: context, builder: (BuildContext context) { return DialogCommon( warning: true, title: t("Warning"), descriptions: t("Please log in"), description2: t("because only that way can we show you your exercises, results and evaluations."), text: "OK", onTap: () => Navigator.of(context).popAndPushNamed("login"), onCancel: () => { Navigator.of(context).pop(), }, ); }); } } }