flutter_material_pickers
flutter_material_pickers copied to clipboard
transform does not work for showMaterialScrollPicker
flutter_material_pickers: ^3.1.0
I'm using a transform parameter in my showMaterialScrollPicker function.
I expect to get a debug print message "transform" when building the picker dialog. but it looks like the transform function will not be called at all.
Future<T?> showPickerDialog<T>(
BuildContext context,
List<T> items,
String transformString,
void Function(T) onChange,
T selected,
) {
if (transformString.endsWith("."))
transformString =
transformString.substring(0, transformString.length - 1);
return showMaterialScrollPicker(
transformer: (e) => "$transformString.values.${items.indexOf(e)}".tr(),
confirmText: LocaleKeys.standard_button_okay.tr(),
cancelText: LocaleKeys.standard_button_cancel.tr(),
context: context,
title: "$transformString.title".tr(),
items: items,
onChanged: onChange,
selectedItem: selected,
);
}
As List<T> items i transform an enum to an array by passing "EnumName.values" this will then generate a List<EnumName>.
For my translation i use something like:
en:
"fruites.title": "Fruits",
"fruites.values.1": "Apple",
"fruites.values.2": "Banana",
"fruites.values.3": "Orange"
de:
"fruites.title": "Früchte",
"fruites.values.1": "Apfel",
"fruites.values.2": "Banane",
"fruites.values.3": "Orange"
Than i use an
enum Fruites { apple, banana, orange }
And than i try to get the translation according to the index in the enum.
Hint: I'm using easy_localization as translator plugin.
For the Checkbock Picker i'm using the same concept and there it works:
Future<List<T>?> showCheckboxPicker<T>(
BuildContext context,
List<T> items,
List<T> selected,
String transformString,
void Function(List<T>) onChange,
) {
return showMaterialCheckboxPicker(
context: context,
items: items,
selectedItems: selected,
onChanged: onChange,
transformer: (e) => "$transformString.values.${items.indexOf(e)}".tr(),
confirmText: LocaleKeys.standard_button_okay.tr(),
cancelText: LocaleKeys.standard_button_cancel.tr(),
title: "$transformString.title".tr(),
);
}
Can confirm this isn't working. I opened the pull request https://github.com/codegrue/flutter_material_pickers/pull/34 to fix it.
Please check if this is working since the PR was merged in.