manager-app/lib/Components/single_choice_input_container.dart

67 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_api_new/api.dart';
import 'package:manager_app/constants.dart';
class SingleChoiceInputContainer<T> extends StatelessWidget {
final String label;
final T? selected;
final List<T> values;
final ValueChanged<T> onChanged;
final double borderRadius;
final Color selectedColor;
final Color textColor;
const SingleChoiceInputContainer({
Key? key,
required this.label,
required this.selected,
required this.values,
required this.onChanged,
this.borderRadius = 12,
this.selectedColor = kPrimaryColor,
this.textColor = kWhite,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return FormField<T>(
initialValue: selected,
builder: (state) {
return InputDecorator(
decoration: InputDecoration(
labelText: label,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 25, vertical: 20),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<T>(
value: selected,
isExpanded: true,
// todo handle view
items: values.map((v) {
return DropdownMenuItem<T>(
value: v,
child: Row(
children: [
Text((v as SectionEventDTO).label ?? ""), // TODO Update to handle more types !
],
),
);
}).toList(),
onChanged: (value) {
if (value != null) {
onChanged(value);
state.didChange(value);
}
},
),
),
);
},
);
}
}