-
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.
- Loading branch information
Showing
2 changed files
with
77 additions
and
48 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
72 changes: 72 additions & 0 deletions
72
random_workout/lib/widgets/exercise/predefined_exercises_dialog.dart
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,72 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import '../../models/exercise.dart'; | ||
import '../../providers/app_state.dart'; | ||
|
||
class PreDefinedExercisesDialog extends StatelessWidget { | ||
final List<Exercise> availableExercises; | ||
final ExerciseCategory category; | ||
final VoidCallback onCreateCustomExercise; | ||
|
||
const PreDefinedExercisesDialog({ | ||
Key? key, | ||
required this.availableExercises, | ||
required this.category, | ||
required this.onCreateCustomExercise, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final appState = Provider.of<AppState>(context, listen: false); | ||
|
||
return AlertDialog( | ||
title: const Text('Choose an Exercise'), | ||
content: SizedBox( | ||
width: double.maxFinite, | ||
child: availableExercises.isEmpty | ||
? const Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Text( | ||
'No more pre-defined exercises available. Try creating your own custom exercise!', | ||
style: TextStyle(fontStyle: FontStyle.italic), | ||
), | ||
) | ||
: ScrollbarTheme( | ||
data: ScrollbarThemeData( | ||
thumbVisibility: MaterialStateProperty.all(true), | ||
), | ||
child: ListView.builder( | ||
itemCount: availableExercises.length, | ||
itemBuilder: (context, index) { | ||
final exercise = availableExercises[index]; | ||
return ListTile( | ||
title: Text(exercise.name), | ||
subtitle: Text(exercise.description), | ||
onTap: () { | ||
appState.addExercise(exercise); | ||
Navigator.of(context).pop(); | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: const Text('Cancel'), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
if (availableExercises.isEmpty) | ||
TextButton( | ||
child: const Text('Create Custom Exercise'), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
onCreateCustomExercise(); | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
} |