IconDataField constructor

IconDataField({
  1. String? labelPrefix,
  2. String? label,
  3. Widget? labelWidget,
  4. IconDataFieldController? controller,
  5. FormFieldValidator<IconData>? validator,
  6. FormFieldSetter<IconData>? onSaved,
  7. IconData? initialValue,
  8. Map<String, IconData> icons = const <String, IconData>{},
  9. bool enabled = true,
  10. AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
  11. bool filled = false,
  12. Color? fillColor,
  13. double iconSize = 32.0,
  14. double maxCrossAxisExtent = 40.0,
  15. double mainAxisSpacing = 6.0,
  16. double crossAxisSpacing = 6.0,
  17. double height = 128.0,
  18. double spaceBetween = 16.0,
  19. InputDecoration? decoration,
  20. EdgeInsets padding = const EdgeInsets.all(8),
  21. String? hintText,
  22. EdgeInsets? contentPadding,
  23. int? sizeExtraSmall,
  24. int? sizeSmall,
  25. int? sizeMedium,
  26. int? sizeLarge,
  27. int? sizeExtraLarge,
  28. double? minHeight,
  29. Key? key,
})

Implementation

IconDataField({
  String? labelPrefix,
  String? label,
  Widget? labelWidget,
  this.controller,
  FormFieldValidator<IconData>? validator,
  super.onSaved,
  IconData? initialValue,
  this.icons = const <String, IconData>{},
  super.enabled,
  AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
  bool filled = false,
  Color? fillColor,
  double iconSize = 32.0,
  double maxCrossAxisExtent = 40.0,
  double mainAxisSpacing = 6.0,
  double crossAxisSpacing = 6.0,
  double height = 128.0,
  double spaceBetween = 16.0,
  InputDecoration? decoration,
  EdgeInsets padding = const EdgeInsets.all(8),
  String? hintText,
  EdgeInsets? contentPadding,
  super.sizeExtraSmall,
  super.sizeSmall,
  super.sizeMedium,
  super.sizeLarge,
  super.sizeExtraLarge,
  super.minHeight,
  super.key,
})  : assert(
        initialValue == null || controller == null,
        'initialValue or controller must be null.',
      ),
      assert(
        label == null || labelWidget == null,
        'label or labelWidget must be null.',
      ),
      super(
        initialValue: controller != null ? controller.value : initialValue,
        validator: enabled ? validator : (_) => null,
        autovalidateMode: autoValidateMode,
        builder: (FormFieldState<IconData> field) {
          _IconDataFieldState state = field as _IconDataFieldState;

          InputDecoration effectiveDecoration = (decoration ??
                  InputDecoration(
                    border: const OutlineInputBorder(),
                    filled: filled,
                    fillColor: fillColor,
                    label: labelWidget,
                    labelText: (labelPrefix?.isEmpty ?? true)
                        ? label
                        : '$labelPrefix - $label',
                    counterText: '',
                    hintText: hintText,
                    contentPadding: contentPadding ??
                        const EdgeInsets.fromLTRB(12, 0, 8, 12),
                  ))
              .applyDefaults(Theme.of(field.context).inputDecorationTheme);

          Map<String, IconData> controllerIcons =
              state._effectiveController.icons;

          List<String> keys = state.names;

          return Padding(
            padding: padding,
            child: InputDecorator(
              decoration: effectiveDecoration.copyWith(
                errorText: enabled ? field.errorText : null,
              ),
              child: Column(
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(top: 16),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      children: <Widget>[
                        Expanded(
                          child: state.value == null
                              ? Container()
                              : Padding(
                                  padding: const EdgeInsets.only(
                                    left: 8,
                                    right: 16,
                                  ),
                                  child: Row(
                                    children: <Widget>[
                                      FaIcon(
                                        state.value,
                                        size: iconSize,
                                      ),
                                      Padding(
                                        padding:
                                            const EdgeInsets.only(left: 8),
                                        child: Text(
                                          state._effectiveController.name,
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                        ),
                        AnimatedSearch(
                          controller: state._textController,
                        ),
                      ],
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(top: spaceBetween),
                    child: SizedBox(
                      height: height,
                      child: Scrollbar(
                        controller: state._scrollController,
                        child: GridView.builder(
                          controller: state._scrollController,
                          gridDelegate:
                              SliverGridDelegateWithMaxCrossAxisExtent(
                            maxCrossAxisExtent: maxCrossAxisExtent,
                            mainAxisSpacing: mainAxisSpacing,
                            crossAxisSpacing: crossAxisSpacing,
                          ),
                          itemCount: keys.length,
                          itemBuilder: (BuildContext context, int index) {
                            IconData iconData = controllerIcons[keys[index]]!;

                            return GestureDetector(
                              onTap: () => state.didChange(iconData),
                              child: Align(
                                child: FaIcon(
                                  iconData,
                                  size: iconSize,
                                ),
                              ),
                            );
                          },
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      );