showMultipleIconPicker function

Future<List<IconPickerIcon>?> showMultipleIconPicker(
  1. BuildContext context, {
  2. MultiplePickerConfiguration configuration = const MultiplePickerConfiguration(),
})

Implementation

Future<List<IconPickerIcon>?> showMultipleIconPicker(
  BuildContext context, {
  MultiplePickerConfiguration configuration =
      const MultiplePickerConfiguration(),
}) async {
  if (configuration.constraints == null) {
    if (configuration.adaptiveDialog) {
      configuration = configuration.copyWith(
        constraints:
            const BoxConstraints(maxHeight: 500, minWidth: 450, maxWidth: 720),
      );
    } else {
      configuration = configuration.copyWith(
        constraints:
            const BoxConstraints(maxHeight: 350, minWidth: 450, maxWidth: 678),
      );
    }
  }

  configuration = configuration.copyWith(
    iconColor: configuration.iconColor ?? Theme.of(context).iconTheme.color,
    iconPickerShape: configuration.iconPickerShape ??
        RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
    backgroundColor: configuration.backgroundColor ??
        Theme.of(context).dialogBackgroundColor,
  );

  final controller = FIPIconController.multiple(
    selectedIcons: configuration.preSelected ?? [],
    shouldScrollToSelectedIcon: configuration.shouldScrollToSelectedIcon,
    iconBuilder: configuration.iconBuilder,
  );

  if (configuration.adaptiveDialog) {
    if (MediaQuery.of(context).size.width >=
        configuration.constraints!.maxWidth) {
      await showDialog(
        barrierDismissible: configuration.barrierDismissible,
        context: context,
        builder: (BuildContext context) => FIPDefaultDialog(
          controller: controller,
          selectedIconBackgroundColor:
              configuration.selectedIconBackgroundColor,
          showSearchBar: configuration.showSearchBar,
          adaptive: configuration.adaptiveDialog,
          showTooltips: configuration.showTooltips,
          barrierDismissible: configuration.barrierDismissible,
          iconSize: configuration.iconSize,
          iconColor: configuration.iconColor,
          mainAxisSpacing: configuration.mainAxisSpacing,
          crossAxisSpacing: configuration.crossAxisSpacing,
          iconPickerShape: configuration.iconPickerShape,
          backgroundColor: configuration.backgroundColor,
          constraints: configuration.constraints,
          title: configuration.title,
          closeChild: configuration.closeChild,
          searchIcon: configuration.searchIcon,
          searchHintText: configuration.searchHintText,
          searchClearIcon: configuration.searchClearIcon,
          noResultsText: configuration.noResultsText,
          iconPackMode: configuration.iconPackModes,
          customIconPack: configuration.customIconPack,
          searchComparator: configuration.searchComparator,
        ),
      );
    } else {
      await Navigator.push(
        context,
        MaterialPageRoute(
          fullscreenDialog: true,
          builder: (context) => FIPDefaultDialog(
            controller: controller,
            selectedIconBackgroundColor:
                configuration.selectedIconBackgroundColor,
            showSearchBar: configuration.showSearchBar,
            routedView: true,
            adaptive: configuration.adaptiveDialog,
            showTooltips: configuration.showTooltips,
            barrierDismissible: configuration.barrierDismissible,
            iconSize: configuration.iconSize,
            iconColor: configuration.iconColor,
            mainAxisSpacing: configuration.mainAxisSpacing,
            crossAxisSpacing: configuration.crossAxisSpacing,
            iconPickerShape: configuration.iconPickerShape,
            backgroundColor: configuration.backgroundColor,
            constraints: configuration.constraints,
            title: configuration.title,
            closeChild: configuration.closeChild,
            searchIcon: configuration.searchIcon,
            searchHintText: configuration.searchHintText,
            searchClearIcon: configuration.searchClearIcon,
            noResultsText: configuration.noResultsText,
            iconPackMode: configuration.iconPackModes,
            customIconPack: configuration.customIconPack,
            searchComparator: configuration.searchComparator,
          ),
        ),
      );
    }
  } else {
    await showDialog(
      barrierDismissible: configuration.barrierDismissible,
      context: context,
      builder: (BuildContext context) => FIPDefaultDialog(
        controller: controller,
        selectedIconBackgroundColor: configuration.selectedIconBackgroundColor,
        showSearchBar: configuration.showSearchBar,
        showTooltips: configuration.showTooltips,
        barrierDismissible: configuration.barrierDismissible,
        iconSize: configuration.iconSize,
        iconColor: configuration.iconColor,
        mainAxisSpacing: configuration.mainAxisSpacing,
        crossAxisSpacing: configuration.crossAxisSpacing,
        iconPickerShape: configuration.iconPickerShape,
        backgroundColor: configuration.backgroundColor,
        constraints: configuration.constraints,
        title: configuration.title,
        closeChild: configuration.closeChild,
        searchIcon: configuration.searchIcon,
        searchHintText: configuration.searchHintText,
        searchClearIcon: configuration.searchClearIcon,
        noResultsText: configuration.noResultsText,
        iconPackMode: configuration.iconPackModes,
        customIconPack: configuration.customIconPack,
        searchComparator: configuration.searchComparator,
      ),
    );
  }

  controller.searchTextController.clear();

  return controller.selectedIcons;
}