-
-
Notifications
You must be signed in to change notification settings - Fork 404
Expand file tree
/
Copy pathadd_exercise_dropdown_button.dart
More file actions
60 lines (55 loc) · 1.62 KB
/
Copy pathadd_exercise_dropdown_button.dart
File metadata and controls
60 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:flutter/material.dart';
class AddExerciseDropdownButton extends StatefulWidget {
const AddExerciseDropdownButton({
super.key,
required this.items,
required this.title,
required this.onChange,
this.validator,
this.onSaved,
});
final List<String> items;
final String title;
final ValueChanged<String?> onChange;
final FormFieldValidator<String?>? validator;
final FormFieldSetter<String?>? onSaved;
@override
_AddExerciseDropdownButtonState createState() => _AddExerciseDropdownButtonState();
}
class _AddExerciseDropdownButtonState extends State<AddExerciseDropdownButton> {
String? _selectedItem;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButtonFormField<String>(
validator: widget.validator,
isExpanded: true,
onSaved: widget.onSaved,
onChanged: (value) {
setState(() {
_selectedItem = value;
});
widget.onChange(value);
},
initialValue: _selectedItem,
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(10)),
),
labelText: widget.title,
alignLabelWithHint: true,
),
items: widget.items
.map(
(item) => DropdownMenuItem<String>(
value: item,
child: Text(item),
),
)
.toList(),
),
);
}
}