bharat_erp/lib/shared/widgets/app_dropdown.dart

63 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
import 'app_searchable_dropdown.dart';
class AppDropdownOption<T> {
const AppDropdownOption({required this.value, required this.label});
final T value;
final String label;
}
/// Searchable dropdown — all app dropdowns use [AppSearchableDropdown] under the hood.
class AppDropdown<T> extends StatelessWidget {
const AppDropdown({
super.key,
required this.label,
required this.value,
required this.options,
required this.onChanged,
this.validator,
this.hint,
this.searchHint,
this.enabled = true,
this.isDense = false,
});
final String label;
final T? value;
final List<AppDropdownOption<T>> options;
final ValueChanged<T?> onChanged;
final String? Function(T?)? validator;
final String? hint;
final String? searchHint;
final bool enabled;
final bool isDense;
@override
Widget build(BuildContext context) {
return AppSearchableDropdown<T>(
label: label,
value: value,
options: options,
onChanged: onChanged,
validator: validator,
hint: hint,
searchHint: searchHint ?? 'Search ${label.toLowerCase()}...',
enabled: enabled,
isDense: isDense,
);
}
}
List<AppDropdownOption<String>> stringDropdownOptions(List<String> values) {
return values
.map(
(value) => AppDropdownOption(
value: value,
label: value.replaceAll('_', ' '),
),
)
.toList();
}