You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
car_customer_app/lib/widgets/dropdown/dropdow_field.dart

75 lines
1.9 KiB
Dart

import 'package:car_customer_app/extensions/string_extensions.dart';
import 'package:car_customer_app/theme/colors.dart';
import 'package:car_customer_app/utils/utils.dart';
import 'package:flutter/material.dart';
class DropValue {
int id;
String value;
String subValue;
DropValue(this.id, this.value,this.subValue);
}
class DropdownField extends StatefulWidget {
String? hint;
List<DropValue>? list;
Function(DropValue) onSelect;
DropdownField(this.onSelect, {this.hint, this.list});
@override
State<DropdownField> createState() => _DropdownFieldState();
}
class _DropdownFieldState extends State<DropdownField> {
DropValue? dropdownValue;
List<DropValue> defaultV = [
new DropValue(1, "One",""),
new DropValue(2, "Two",""),
];
@override
Widget build(BuildContext context) {
return Container(
decoration: containerColorRadiusBorderWidth(
Colors.transparent,
4,
borderColor,
0.5,
),
margin: EdgeInsets.all(2),
padding: EdgeInsets.only(left: 8, right: 8),
child: DropdownButton<DropValue>(
value: dropdownValue,
icon: const Icon(Icons.keyboard_arrow_down_sharp),
elevation: 16,
iconSize: 16,
iconEnabledColor: borderColor,
iconDisabledColor: borderColor,
isExpanded: true,
style: const TextStyle(color: Colors.black),
hint: (widget.hint ?? "").toText12(color: borderColor),
underline: Container(
height: 0,
),
onChanged: (DropValue? newValue) {
setState(() {
dropdownValue = newValue!;
widget.onSelect(newValue);
});
},
items: (widget.list ?? defaultV).map<DropdownMenuItem<DropValue>>(
(DropValue value) {
return DropdownMenuItem<DropValue>(
value: value,
child: value.value.toText12(),
);
},
).toList(),
),
);
}
}