widgets/exercise_dropdown.dart

mail@pastecode.io avatar
unknown
dart
5 months ago
1.1 kB
0
Indexable
import 'package:flutter/material.dart';
import '../data/exercises_data.dart';

class ExerciseDropdown extends StatefulWidget {
  final Function(String) onSelectExercise;

  ExerciseDropdown({required this.onSelectExercise});

  @override
  _ExerciseDropdownState createState() => _ExerciseDropdownState();
}

class _ExerciseDropdownState extends State<ExerciseDropdown> {
  String? selectedExercise;

  @override
  Widget build(BuildContext context) {
    return DropdownButton<String>(
      value: selectedExercise,
      hint: Text('Select an exercise'),
      onChanged: (String? newValue) {
        setState(() {
          selectedExercise = newValue!;
        });
        widget.onSelectExercise(newValue!);
      },
      items: exercises.keys.expand((muscleGroup) {
        return exercises[muscleGroup]!.map((exercise) {
          return DropdownMenuItem<String>(
            value: exercise['title'],
            child: Text(exercise['title']),
          );
        }).toList();
      }).toList(),
    );
  }
}
Leave a Comment