81 lines
2.5 KiB
Dart
81 lines
2.5 KiB
Dart
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'local_text.dart';
|
|
|
|
class LocalDropdown<T> extends StatelessWidget {
|
|
final Function(T)? callback;
|
|
final IconData? iconData;
|
|
final T? selectedValue;
|
|
final List<T>? values;
|
|
final Function(T)? display;
|
|
final String? labelKey;
|
|
|
|
const LocalDropdown(
|
|
{super.key,
|
|
this.callback,
|
|
this.iconData,
|
|
this.selectedValue,
|
|
this.values,
|
|
this.labelKey,
|
|
this.display});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(left: 5.0, right: 0),
|
|
child: Row(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 0, right: 10),
|
|
child: Icon(iconData, color: primaryColor),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 18.0),
|
|
child: labelKey != null
|
|
? LocalText(
|
|
context,
|
|
labelKey!,
|
|
color: Colors.black54,
|
|
fontSize: 16,
|
|
)
|
|
: const SizedBox(),
|
|
),
|
|
DropdownButton<T>(
|
|
isDense: true,
|
|
value: selectedValue,
|
|
style: TextStyle(color: Colors.black, fontSize: 14),
|
|
underline: Container(height: 1, color: primaryColor),
|
|
onChanged: (T? newValue) {
|
|
callback!(newValue!);
|
|
},
|
|
isExpanded: true,
|
|
items: values == null
|
|
? []
|
|
: values!.map<DropdownMenuItem<T>>((T value) {
|
|
return DropdownMenuItem<T>(
|
|
value: value,
|
|
child: Text(
|
|
value == null
|
|
? ""
|
|
: display != null
|
|
? display!(value)
|
|
: value.toString(),
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(color: Colors.black)),
|
|
);
|
|
}).toList(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|