Skip to content

Commit

Permalink
Merge pull request #105 from andreped:98-bug-db-not-synced-with-prede…
Browse files Browse the repository at this point in the history
…fined-exercises-if-already-constructed-2

98-bug-db-not-synced-with-predefined-exercises-if-already-constructed-2
  • Loading branch information
andreped authored Aug 9, 2024
2 parents 703fd14 + 314ceb9 commit 0b5aa92
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/tabs/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _ExerciseStoreHomePageState extends State<ExerciseStoreHomePage> with Sing
@override
void initState() {
super.initState();
_tabController = TabController(length: 5, vsync: this); // Update length to 5
_tabController = TabController(length: 5, vsync: this);
}

@override
Expand Down
73 changes: 42 additions & 31 deletions lib/tabs/inputs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,46 @@ class _ExerciseSetterState extends State<ExerciseSetter> {
}
}

void _onPopupMenuSelected(String value) {
setState(() {
if (value == 'custom') {
_isAddingNewExercise = true;
_selectedExercise = null;
_weightController.clear();
_repsController.clear();
_setsController.text = '1';
} else {
_isAddingNewExercise = false;
_selectedExercise = value;
_loadLastLoggedExercise();
}
});
void _openExerciseSelectionSheet() {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: Text('Add New Exercise'),
onTap: () {
Navigator.pop(context);
setState(() {
_isAddingNewExercise = true;
_selectedExercise = null;
});
},
),
Expanded(
child: ListView.builder(
itemCount: _predefinedExercises.length,
itemBuilder: (context, index) {
final exercise = _predefinedExercises[index];
return ListTile(
title: Text(exercise),
onTap: () {
setState(() {
_selectedExercise = exercise;
_isAddingNewExercise = false;
});
Navigator.pop(context);
_loadLastLoggedExercise();
},
);
},
),
),
],
);
},
);
}

@override
Expand All @@ -140,30 +166,15 @@ class _ExerciseSetterState extends State<ExerciseSetter> {
children: [
Expanded(
flex: 2,
child: PopupMenuButton<String>(
onSelected: _onPopupMenuSelected,
child: GestureDetector(
onTap: _openExerciseSelectionSheet,
child: InputDecorator(
decoration: const InputDecoration(labelText: 'Select Exercise'),
child: Text(
_isAddingNewExercise ? 'Add New Exercise' : _selectedExercise ?? 'Select Exercise',
style: TextStyle(color: _selectedExercise == null ? Colors.grey : Colors.black),
),
),
itemBuilder: (context) {
final exercisesToShow = List<String>.from(_predefinedExercises);
if (exercisesToShow.length > 5) {
exercisesToShow.removeRange(5, exercisesToShow.length);
}
exercisesToShow.add('custom');

return exercisesToShow.map((String value) {
return PopupMenuItem<String>(
value: value,
child: Text(value == 'custom' ? 'Add New Exercise' : value),
);
}).toList();
},
constraints: BoxConstraints(maxHeight: 300.0),
),
),
],
Expand Down

0 comments on commit 0b5aa92

Please sign in to comment.