manager-app/lib/Components/dropDown_input_container.dart

75 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/constants.dart';
class DropDownInputContainer extends StatefulWidget {
final String label;
final List<String> values;
final String? initialValue;
final ValueChanged<String>? onChange;
const DropDownInputContainer({
Key? key,
required this.label,
required this.values,
this.initialValue,
this.onChange,
}) : super(key: key);
@override
_DropDownInputContainerState createState() => _DropDownInputContainerState();
}
class _DropDownInputContainerState extends State<DropDownInputContainer> {
late String? selectedValue;
@override
void initState() {
super.initState();
selectedValue = widget.initialValue;
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Text(
widget.label,
style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: DropdownButton<String>(
value: selectedValue,
icon: const Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: const TextStyle(color: Colors.black),
underline: Container(
height: 2,
color: kPrimaryColor,
),
onChanged: (String? newValue) {
setState(() {
selectedValue = newValue;
widget.onChange!(selectedValue!);
});
},
items: widget.values.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(fontSize: 15),
),
);
}).toList(),
),
),
],
);
}
}