IconDataField constructor
IconDataField({
- String? labelPrefix,
- String? label,
- Widget? labelWidget,
- IconDataFieldController? controller,
- FormFieldValidator<
IconData> ? validator, - FormFieldSetter<
IconData> ? onSaved, - IconData? initialValue,
- Map<
String, IconData> icons = const <String, IconData>{}, - bool enabled = true,
- 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,
- int? sizeExtraSmall,
- int? sizeSmall,
- int? sizeMedium,
- int? sizeLarge,
- int? sizeExtraLarge,
- double? minHeight,
- 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,
),
),
);
},
),
),
),
),
],
),
),
);
},
);