Files
sf-app-platform/packages/design_system/lib/src/dropdowns/dropdown.dart

92 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
class CustomDropdown extends StatelessWidget {
final List<Widget> items;
final List<dynamic>? values;
final ValueChanged<dynamic> onChanged;
final dynamic value;
final String? hint;
final String? label;
final double radius;
final double height;
final double width;
final Color? color;
const CustomDropdown({
super.key,
required this.items,
this.values,
required this.onChanged,
this.value,
this.hint,
this.label,
this.radius = 12,
this.width = double.infinity,
this.height = 70,
this.color,
});
@override
Widget build(BuildContext context) {
final borderColor = color ?? const Color(0xFF4B4B4B);
OutlineInputBorder border(Color c) => OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(radius)),
borderSide: BorderSide(color: c),
);
return Column(
children: [
if (label != null) ...[
Align(
alignment: Alignment.bottomLeft,
child: Text(
label!,
style: const TextStyle(fontSize: 14, letterSpacing: 0),
),
),
const SizedBox(height: 8),
],
SizedBox(
width: width,
height: height,
child: Center(
child: DropdownButtonFormField<dynamic>(
dropdownColor: Colors.white,
decoration: InputDecoration(
enabledBorder: border(borderColor),
focusedBorder: border(borderColor),
disabledBorder: border(borderColor),
errorBorder: border(borderColor),
focusedErrorBorder: border(borderColor),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 16,
),
),
initialValue: value,
onChanged: onChanged,
hint: hint != null ? Text(hint!) : null,
items: List<DropdownMenuItem<dynamic>>.generate(items.length, (
int index,
) {
final dynamic itemValue = values != null
? values![index]
: index;
return DropdownMenuItem<dynamic>(
value: itemValue,
child: items[index],
);
}),
),
),
),
],
);
}
}