showMapTreeCascadePicker<V> function

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

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

Implementation

Future<Map?> showMapTreeCascadePicker<V>({
  required BuildContext context,
  required List<Map> datasource,
  String? labelKey,
  String? valueKey,
  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],
  );
  return showDefaultBottomSheet<Map>(
    context,
    title: title ?? '请选择',
    contentBuilder: (context) {
      return TxCascadePicker<Map, V>.fromMapTree(
        datasource: datasource,
        labelKey: labelKey,
        valueKey: valueKey,
        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),
  );
}