-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#73 - feat(training plan): create dropdown for training plan selection
- Loading branch information
1 parent
6bee1b0
commit d5b39ca
Showing
6 changed files
with
189 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:lifting_progress_tracker/core/constants/localization.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/widgets/table_header.dart'; | ||
|
||
class SelectedTrainingPlan extends StatefulWidget { | ||
@override | ||
State<StatefulWidget> createState() => _SelectedTrainingPlanState(); | ||
} | ||
|
||
class _SelectedTrainingPlanState extends State<SelectedTrainingPlan> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
Table( | ||
border: TableBorder.all(), | ||
children: [ | ||
TableRow( | ||
children: [ | ||
for (final label in tableHeaderLabels) | ||
TableHeader(headerText: label), | ||
], | ||
), | ||
const TableRow( | ||
children: [ | ||
Text("Bench press"), | ||
Text("20 KG"), | ||
Text("3x15"), | ||
Text("More Weight next time."), | ||
IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.delete), | ||
), | ||
], | ||
), | ||
const TableRow( | ||
children: [ | ||
Text("Deadlift"), | ||
Text("30/40 KG"), | ||
Text("3x15/3x5"), | ||
Text("More Weight next time, slow down execution, ..."), | ||
IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.delete), | ||
), | ||
], | ||
), | ||
const TableRow( | ||
children: [ | ||
Text("Overhead Press"), | ||
Text("10 KG"), | ||
Text("3x5"), | ||
Text(""), | ||
IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.delete), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
const IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.create), | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,64 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:lifting_progress_tracker/core/constants/localization.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/widgets/table_header.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:lifting_progress_tracker/core/services/user_service.dart'; | ||
import 'package:lifting_progress_tracker/core/widgets/error_message.dart'; | ||
import 'package:lifting_progress_tracker/firebase/constants/collection_names.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/models/training_plan_list.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/training_plan_service.ts.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/widgets/traning_plan_selector.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
||
class TrainingPlanTable extends StatefulWidget { | ||
@override | ||
State<StatefulWidget> createState() => _TrainingPlanTableState(); | ||
} | ||
|
||
class _TrainingPlanTableState extends State<TrainingPlanTable> { | ||
final TrainingPlanService _trainingPlanService = | ||
GetIt.I.get<TrainingPlanService>(); | ||
|
||
final UserService _userService = GetIt.I.get<UserService>(); | ||
|
||
late final Future<TrainingPlanList> _trainingPlanList$; | ||
|
||
final Logger _logger = Logger("_TrainingPlanTableState"); | ||
|
||
late String dropdownValue; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_trainingPlanList$ = _trainingPlanService.get( | ||
CollectionNames.planEntries, | ||
_userService.user.uid, | ||
); | ||
} | ||
|
||
List<String> _extractTrainingPlanNames(TrainingPlanList list) { | ||
return list.trainingPlans.keys.toList(); | ||
} | ||
|
||
class TrainingPlanTable extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
const Text("Training Plan 1"), | ||
Table( | ||
border: TableBorder.all(), | ||
children: [ | ||
TableRow( | ||
children: [ | ||
for (final label in tableHeaderLabels) | ||
TableHeader(headerText: label), | ||
], | ||
), | ||
const TableRow( | ||
children: [ | ||
Text("Bench press"), | ||
Text("20 KG"), | ||
Text("3x15"), | ||
Text("More Weight next time."), | ||
IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.delete), | ||
), | ||
], | ||
), | ||
const TableRow( | ||
children: [ | ||
Text("Deadlift"), | ||
Text("30/40 KG"), | ||
Text("3x15/3x5"), | ||
Text("More Weight next time, slow down execution, ..."), | ||
IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.delete), | ||
), | ||
], | ||
), | ||
const TableRow( | ||
children: [ | ||
Text("Overhead Press"), | ||
Text("10 KG"), | ||
Text("3x5"), | ||
Text(""), | ||
IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.delete), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
const IconButton( | ||
onPressed: null, | ||
icon: Icon(Icons.create), | ||
), | ||
], | ||
return Center( | ||
child: FutureBuilder( | ||
future: _trainingPlanList$, | ||
builder: (_, snapshot) { | ||
if (snapshot.connectionState == ConnectionState.waiting) { | ||
return const CircularProgressIndicator(); | ||
} else if (snapshot.connectionState == ConnectionState.done) { | ||
return TrainingPlanSelector( | ||
trainingPlanNames: _extractTrainingPlanNames(snapshot.data!), | ||
); | ||
} else if (snapshot.hasError) { | ||
_logger.warning( | ||
"The training plan list was not loaded properly: ${snapshot.error}", | ||
); | ||
} | ||
|
||
return ErrorMessage(); | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:lifting_progress_tracker/training_plan/widgets/selected_training_plan.dart'; | ||
|
||
class TrainingPlanSelector extends StatefulWidget { | ||
final List<String> trainingPlanNames; | ||
|
||
const TrainingPlanSelector({required this.trainingPlanNames}); | ||
|
||
@override | ||
State<StatefulWidget> createState() => _TrainingPlanSelectorState(); | ||
} | ||
|
||
class _TrainingPlanSelectorState extends State<TrainingPlanSelector> { | ||
late String dropdownValue; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
dropdownValue = widget.trainingPlanNames.first; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
children: [ | ||
DropdownButton<String>( | ||
value: dropdownValue, | ||
items: _mapNamesToDropdownMenuItems(widget.trainingPlanNames), | ||
onChanged: (String? value) { | ||
setState(() { | ||
dropdownValue = value!; | ||
}); | ||
}, | ||
), | ||
SelectedTrainingPlan(), | ||
], | ||
); | ||
} | ||
} | ||
|
||
List<DropdownMenuItem<String>> _mapNamesToDropdownMenuItems( | ||
List<String> list, | ||
) { | ||
return list | ||
.map<DropdownMenuItem<String>>( | ||
(entry) => DropdownMenuItem( | ||
value: entry, | ||
child: Text(entry), | ||
), | ||
) | ||
.toList(); | ||
} |