diff --git a/lib/importing/ex_match_listview.dart b/lib/importing/ex_match_listview.dart index b9bb488..9d6f4ae 100644 --- a/lib/importing/ex_match_listview.dart +++ b/lib/importing/ex_match_listview.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:go_router/go_router.dart'; import 'package:open_fitness_tracker/DOM/exercise_metadata.dart'; import 'package:open_fitness_tracker/common/common_widgets.dart'; import 'package:open_fitness_tracker/exercises/ex_search_page.dart'; import 'package:open_fitness_tracker/exercises/ex_tile.dart'; import 'package:open_fitness_tracker/importing/history_importing_cubits.dart'; - -//TODO give them a #/total cards on each card. +import 'package:open_fitness_tracker/navigation/routes.dart'; class MatchExercisesScrollView extends StatefulWidget { final VoidCallback confirmSelections; @@ -62,7 +62,10 @@ class _MatchExercisesScrollViewState extends State { ), const SizedBox(height: 10), MyGenericButton( - onPressed: widget.confirmSelections, + onPressed: () { + widget.confirmSelections(); + context.push(routeNames.History.text); + }, label: "Confirm Selections", ), ], @@ -70,65 +73,78 @@ class _MatchExercisesScrollViewState extends State { ); } - Widget _buildExerciseMatchTile( - int index, - ) { + Widget _buildExerciseMatchTile(int index) { ExerciseMatchCard exerciseMatch = exerciseMatches[index]; - Color matchedExerciseBackgroundColor; - if (exerciseMatch.matchedExercise == null && !exerciseMatch.isConfirmed) { - matchedExerciseBackgroundColor = Colors.red.shade300; - } else if (exerciseMatch.isConfirmed) { - matchedExerciseBackgroundColor = Colors.greenAccent.shade400; - } else { - matchedExerciseBackgroundColor = Colors.yellow.shade300; - } - - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), - child: Container( - padding: const EdgeInsets.all(8.0), - decoration: BoxDecoration( - color: Colors.white, - border: Border.all(color: Colors.grey.shade300), - borderRadius: BorderRadius.circular(8.0), - boxShadow: [ - BoxShadow( - color: Colors.grey.shade200, offset: const Offset(0, 2), blurRadius: 4.0) - ], + return Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0), + child: Text( + '${index + 1} of ${exerciseMatches.length}', + style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16), + ), ), - child: Row( - children: [ - Expanded( - child: Opacity( - opacity: exerciseMatch.bDiscard ? .33 : 1, - child: Column( - children: [ - ExerciseTile(exercise: exerciseMatch.foreignExercise), - const SizedBox(height: 8.0), - _selectableExTile( - index, exerciseMatch, matchedExerciseBackgroundColor), - ], - ), - ), + Padding( + padding: const EdgeInsets.symmetric(vertical: 4.0, horizontal: 8.0), + child: Container( + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.grey.shade300), + borderRadius: BorderRadius.circular(8.0), + boxShadow: [ + BoxShadow( + color: Colors.grey.shade200, + offset: const Offset(0, 2), + blurRadius: 4.0, + ) + ], ), - SizedBox( - width: 80, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _acceptSwitch(exerciseMatch), - _useMyNameSwitch(exerciseMatch), - _discardThisExSwitch(exerciseMatch), - ], - ), + child: Row( + children: [ + Expanded( + child: Opacity( + opacity: exerciseMatch.bDiscard ? .33 : 1, + child: Column( + children: [ + ExerciseTile(exercise: exerciseMatch.foreignExercise), + const SizedBox(height: 8.0), + _selectableExTile(index, exerciseMatch, + _getExerciseBackgroundColor(exerciseMatch)), + ], + ), + ), + ), + SizedBox( + width: 80, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + _acceptSwitch(exerciseMatch), + _useMyNameSwitch(exerciseMatch), + _discardThisExSwitch(exerciseMatch), + ], + ), + ), + ], ), - ], + ), ), - ), + ], ); } + Color _getExerciseBackgroundColor(ExerciseMatchCard exerciseMatch) { + if (exerciseMatch.matchedExercise == null && !exerciseMatch.isConfirmed) { + return Colors.red.shade300; + } else if (exerciseMatch.isConfirmed) { + return Colors.greenAccent.shade400; + } else { + return Colors.yellow.shade300; + } + } + Column _discardThisExSwitch(ExerciseMatchCard exerciseMatch) { return Column( children: [ @@ -154,8 +170,10 @@ class _MatchExercisesScrollViewState extends State { child: Text('Use my name?', textAlign: TextAlign.center), ), Switch( - value: - (exerciseMatch.bDiscard) ? false : exerciseMatch.preferForeignExerciseName, + value: (exerciseMatch.bDiscard) + ? false + : exerciseMatch.preferForeignExerciseName || + (exerciseMatch.isConfirmed && exerciseMatch.matchedExercise == null), onChanged: (bool value) { if (exerciseMatch.bDiscard) return; setState(() { diff --git a/lib/importing/import_inspection_page.dart b/lib/importing/import_inspection_page.dart index ccc5b5d..1cbdbc1 100644 --- a/lib/importing/import_inspection_page.dart +++ b/lib/importing/import_inspection_page.dart @@ -52,6 +52,7 @@ class _ImportInspectionPageState extends State { if (matchPairs.isEmpty) { matchPairs = _exerciseMatcher(newExs, exercisesState, 92); + context.read().deleteAll(); context.read().addMatches(matchPairs); } return Scaffold( @@ -167,13 +168,9 @@ class _ImportInspectionPageState extends State { } histCubit.loadUserTrainingHistory(useCache: true); - if (mounted) { - //i think this should be fine, what's a dialog going to do? - context.push(routeNames.History.text); - } else { - //todo error handling? - throw Exception("todo help me..import still worked, just go back"); - } + //the user made it! + context.read().deleteAll(); + context.read().deleteSessions(); } Future _confirmCreatingNewExercisesDialog( diff --git a/lib/navigation/routes.dart b/lib/navigation/routes.dart index 04787f1..7702221 100644 --- a/lib/navigation/routes.dart +++ b/lib/navigation/routes.dart @@ -40,10 +40,10 @@ enum routeNames { final GoRouter appRouter = GoRouter( errorBuilder: (context, state) => const ScaffoldWithNavBar(child: PageNotFoundPage()), navigatorKey: _rootNavigatorKey, - initialLocation: routeNames.Temp.text, + // initialLocation: routeNames.Temp.text, // initialLocation: routeNames.Training.text, //////////<--- This is the initial route // initialLocation: routeNames.Exercises.text, //////////<--- This is the initial route - // initialLocation: routeNames.History.text, //////////<--- This is the initial route + initialLocation: routeNames.History.text, //////////<--- This is the initial route // initialLocation: routeNames.Community.text, //////////<--- This is the initial route routes: [ ShellRoute(