showMapListCascadePicker<V> function

Future<Map?> showMapListCascadePicker<V>({
  1. required BuildContext context,
  2. required List<Map> datasource,
  3. String? valueKey,
  4. String? labelKey,
  5. String? idKey,
  6. String? pidKey,
  7. String? childrenKey,
  8. V? initialValue,
  9. Map? initialData,
  10. SelectableWidgetBuilder<Map>? itemBuilder,
  11. IndexedDataWidgetBuilder<Map?>? tabItemBuilder,
  12. ListTileThemeData? listTheme,
  13. String? placeholder,
  14. bool? isParentNodeSelectable,
  15. String? title,
})

弹出数据为 Map 列表类型级联选择器

Implementation

Future<Map?> showMapListCascadePicker<V>({
  required BuildContext context,
  required List<Map> datasource,
  String? valueKey,
  String? labelKey,
  String? idKey,
  String? pidKey,
  String? childrenKey,
  V? initialValue,
  Map? initialData,
  SelectableWidgetBuilder<Map>? itemBuilder,
  IndexedDataWidgetBuilder<Map?>? tabItemBuilder,
  ListTileThemeData? listTheme,
  String? placeholder,
  bool? isParentNodeSelectable,
  String? title,
}) async {
  Map? result = datasource.getInitialData<V>(
    initialValue: initialValue,
    initialData: initialData,
    valueMapper: (data) => data[valueKey ?? idKey],
  );
  return showDefaultBottomSheet<Map>(
    context,
    title: title ?? '请选择',
    contentBuilder: (context) {
      return TxCascadePicker<Map, V>.fromMapList(
        datasource: datasource,
        labelKey: labelKey,
        valueKey: valueKey,
        idKey: idKey,
        pidKey: pidKey,
        childrenKey: childrenKey,
        initialData: initialData,
        itemBuilder: itemBuilder,
        tabItemBuilder: tabItemBuilder,
        listTheme: listTheme,
        placeholder: placeholder,
        isParentNodeSelectable: isParentNodeSelectable,
        onChanged: (val) {
          if (isParentNodeSelectable == true) {
            result = val;
          } else {
            Navigator.pop(context, val);
          }
        },
      );
    },
    showConfirmButton: isParentNodeSelectable == true,
    onConfirm: () => Navigator.pop(context, result),
    actionsPosition: ActionsPosition.footer,
  );
}