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

92 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2025-12-04 10:45:10 +01:00
class CustomDropdown extends StatelessWidget {
final List<Widget> items;
2025-12-04 10:45:10 +01:00
final List<dynamic>? values;
2025-12-26 00:29:15 +01:00
2025-12-04 10:45:10 +01:00
final ValueChanged<dynamic> onChanged;
2025-12-26 00:29:15 +01:00
2025-12-04 10:45:10 +01:00
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,
2025-12-04 10:45:10 +01:00
this.color,
});
@override
Widget build(BuildContext context) {
2025-12-26 00:29:15 +01:00
final borderColor = color ?? const Color(0xFF4B4B4B);
OutlineInputBorder border(Color c) => OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(radius)),
borderSide: BorderSide(color: c),
);
return Column(
children: [
2025-12-26 00:29:15 +01:00
if (label != null) ...[
2025-12-04 10:45:10 +01:00
Align(
alignment: Alignment.bottomLeft,
child: Text(
label!,
style: const TextStyle(fontSize: 14, letterSpacing: 0),
),
),
2025-12-26 00:29:15 +01:00
const SizedBox(height: 8),
],
SizedBox(
width: width,
height: height,
2025-12-04 10:45:10 +01:00
child: Center(
child: DropdownButtonFormField<dynamic>(
dropdownColor: Colors.white,
decoration: InputDecoration(
2025-12-26 00:29:15 +01:00
enabledBorder: border(borderColor),
focusedBorder: border(borderColor),
disabledBorder: border(borderColor),
errorBorder: border(borderColor),
focusedErrorBorder: border(borderColor),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 16,
2025-12-04 10:45:10 +01:00
),
),
2025-12-26 00:29:15 +01:00
2025-12-04 10:45:10 +01:00
initialValue: value,
2025-12-26 00:29:15 +01:00
2025-12-04 10:45:10 +01:00
onChanged: onChanged,
2025-12-26 00:29:15 +01:00
2025-12-04 10:45:10 +01:00
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],
);
}),
),
2025-12-04 10:45:10 +01:00
),
),
],
2025-12-04 10:45:10 +01:00
);
}
2025-12-04 10:45:10 +01:00
}