diff --git a/examples/mirai_gallery/assets/json/form_example.json b/examples/mirai_gallery/assets/json/form_example.json index 1acf139c..208d964c 100644 --- a/examples/mirai_gallery/assets/json/form_example.json +++ b/examples/mirai_gallery/assets/json/form_example.json @@ -214,6 +214,12 @@ "icon": "eye", "size": 24 }, + "visibilityIcon": { + "type": "icon", + "iconType": "cupertino", + "icon": "eye_slash", + "size": 24 + }, "labelText": "Password*" }, "validatorRules": [ @@ -256,6 +262,12 @@ "icon": "eye", "size": 24 }, + "visibilityIcon": { + "type": "icon", + "iconType": "cupertino", + "icon": "eye_slash", + "size": 24 + }, "labelText": "Re-type password*" }, "validatorRules": [ diff --git a/examples/mirai_gallery/assets/json/text_field_example.json b/examples/mirai_gallery/assets/json/text_field_example.json index e70bc17c..4ab73d63 100644 --- a/examples/mirai_gallery/assets/json/text_field_example.json +++ b/examples/mirai_gallery/assets/json/text_field_example.json @@ -193,6 +193,12 @@ "icon": "eye", "size": 24 }, + "visibilityIcon": { + "type": "icon", + "iconType": "cupertino", + "icon": "eye_slash", + "size": 24 + }, "labelText": "Password*" }, "autovalidateMode": "onUserInteraction", @@ -221,6 +227,12 @@ "icon": "eye", "size": 24 }, + "visibilityIcon": { + "type": "icon", + "iconType": "cupertino", + "icon": "eye_slash", + "size": 24 + }, "labelText": "Re-type password*" }, "readOnly": false, @@ -254,7 +266,8 @@ }, "gradient": { "colors": [ - "#FF0000", "#0000FF" + "#FF0000", + "#0000FF" ] } } diff --git a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart index 75d906eb..69df6501 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart @@ -43,6 +43,7 @@ class MiraiInputDecoration with _$MiraiInputDecoration { String? prefixIconColor, Map? suffix, Map? suffixIcon, + Map? visibilityIcon, MiraiBoxConstraints? suffixIconConstraints, String? suffixText, MiraiTextStyle? suffixStyle, diff --git a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.freezed.dart b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.freezed.dart index 5f1dcdb6..d6a46692 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.freezed.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.freezed.dart @@ -52,6 +52,8 @@ mixin _$MiraiInputDecoration { String? get prefixIconColor => throw _privateConstructorUsedError; Map? get suffix => throw _privateConstructorUsedError; Map? get suffixIcon => throw _privateConstructorUsedError; + Map? get visibilityIcon => + throw _privateConstructorUsedError; MiraiBoxConstraints? get suffixIconConstraints => throw _privateConstructorUsedError; String? get suffixText => throw _privateConstructorUsedError; @@ -118,6 +120,7 @@ abstract class $MiraiInputDecorationCopyWith<$Res> { String? prefixIconColor, Map? suffix, Map? suffixIcon, + Map? visibilityIcon, MiraiBoxConstraints? suffixIconConstraints, String? suffixText, MiraiTextStyle? suffixStyle, @@ -203,6 +206,7 @@ class _$MiraiInputDecorationCopyWithImpl<$Res, Object? prefixIconColor = freezed, Object? suffix = freezed, Object? suffixIcon = freezed, + Object? visibilityIcon = freezed, Object? suffixIconConstraints = freezed, Object? suffixText = freezed, Object? suffixStyle = freezed, @@ -342,6 +346,10 @@ class _$MiraiInputDecorationCopyWithImpl<$Res, ? _value.suffixIcon : suffixIcon // ignore: cast_nullable_to_non_nullable as Map?, + visibilityIcon: freezed == visibilityIcon + ? _value.visibilityIcon + : visibilityIcon // ignore: cast_nullable_to_non_nullable + as Map?, suffixIconConstraints: freezed == suffixIconConstraints ? _value.suffixIconConstraints : suffixIconConstraints // ignore: cast_nullable_to_non_nullable @@ -686,6 +694,7 @@ abstract class _$$_MiraiInputDecorationCopyWith<$Res> String? prefixIconColor, Map? suffix, Map? suffixIcon, + Map? visibilityIcon, MiraiBoxConstraints? suffixIconConstraints, String? suffixText, MiraiTextStyle? suffixStyle, @@ -786,6 +795,7 @@ class __$$_MiraiInputDecorationCopyWithImpl<$Res> Object? prefixIconColor = freezed, Object? suffix = freezed, Object? suffixIcon = freezed, + Object? visibilityIcon = freezed, Object? suffixIconConstraints = freezed, Object? suffixText = freezed, Object? suffixStyle = freezed, @@ -925,6 +935,10 @@ class __$$_MiraiInputDecorationCopyWithImpl<$Res> ? _value._suffixIcon : suffixIcon // ignore: cast_nullable_to_non_nullable as Map?, + visibilityIcon: freezed == visibilityIcon + ? _value._visibilityIcon + : visibilityIcon // ignore: cast_nullable_to_non_nullable + as Map?, suffixIconConstraints: freezed == suffixIconConstraints ? _value.suffixIconConstraints : suffixIconConstraints // ignore: cast_nullable_to_non_nullable @@ -1046,6 +1060,7 @@ class _$_MiraiInputDecoration implements _MiraiInputDecoration { this.prefixIconColor, final Map? suffix, final Map? suffixIcon, + final Map? visibilityIcon, this.suffixIconConstraints, this.suffixText, this.suffixStyle, @@ -1073,6 +1088,7 @@ class _$_MiraiInputDecoration implements _MiraiInputDecoration { _prefix = prefix, _suffix = suffix, _suffixIcon = suffixIcon, + _visibilityIcon = visibilityIcon, _counter = counter; factory _$_MiraiInputDecoration.fromJson(Map json) => @@ -1186,6 +1202,16 @@ class _$_MiraiInputDecoration implements _MiraiInputDecoration { return EqualUnmodifiableMapView(value); } + final Map? _visibilityIcon; + @override + Map? get visibilityIcon { + final value = _visibilityIcon; + if (value == null) return null; + if (_visibilityIcon is EqualUnmodifiableMapView) return _visibilityIcon; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + @override final MiraiBoxConstraints? suffixIconConstraints; @override @@ -1241,7 +1267,7 @@ class _$_MiraiInputDecoration implements _MiraiInputDecoration { @override String toString() { - return 'MiraiInputDecoration(icon: $icon, iconColor: $iconColor, label: $label, labelText: $labelText, labelStyle: $labelStyle, floatingLabelStyle: $floatingLabelStyle, helperText: $helperText, helperStyle: $helperStyle, hintText: $hintText, hintStyle: $hintStyle, helperMaxLines: $helperMaxLines, hintTextDirection: $hintTextDirection, hintMaxLines: $hintMaxLines, errorText: $errorText, errorStyle: $errorStyle, errorMaxLines: $errorMaxLines, floatingLabelBehavior: $floatingLabelBehavior, floatingLabelAlignment: $floatingLabelAlignment, isCollapsed: $isCollapsed, isDense: $isDense, contentPadding: $contentPadding, prefixIcon: $prefixIcon, prefixIconConstraints: $prefixIconConstraints, prefix: $prefix, prefixText: $prefixText, prefixStyle: $prefixStyle, prefixIconColor: $prefixIconColor, suffix: $suffix, suffixIcon: $suffixIcon, suffixIconConstraints: $suffixIconConstraints, suffixText: $suffixText, suffixStyle: $suffixStyle, suffixIconColor: $suffixIconColor, counter: $counter, counterText: $counterText, counterStyle: $counterStyle, filled: $filled, fillColor: $fillColor, hoverColor: $hoverColor, focusColor: $focusColor, errorBorder: $errorBorder, focusedBorder: $focusedBorder, focusedErrorBorder: $focusedErrorBorder, disabledBorder: $disabledBorder, enabledBorder: $enabledBorder, border: $border, enabled: $enabled, semanticCounterText: $semanticCounterText, alignLabelWithHint: $alignLabelWithHint, constraints: $constraints)'; + return 'MiraiInputDecoration(icon: $icon, iconColor: $iconColor, label: $label, labelText: $labelText, labelStyle: $labelStyle, floatingLabelStyle: $floatingLabelStyle, helperText: $helperText, helperStyle: $helperStyle, hintText: $hintText, hintStyle: $hintStyle, helperMaxLines: $helperMaxLines, hintTextDirection: $hintTextDirection, hintMaxLines: $hintMaxLines, errorText: $errorText, errorStyle: $errorStyle, errorMaxLines: $errorMaxLines, floatingLabelBehavior: $floatingLabelBehavior, floatingLabelAlignment: $floatingLabelAlignment, isCollapsed: $isCollapsed, isDense: $isDense, contentPadding: $contentPadding, prefixIcon: $prefixIcon, prefixIconConstraints: $prefixIconConstraints, prefix: $prefix, prefixText: $prefixText, prefixStyle: $prefixStyle, prefixIconColor: $prefixIconColor, suffix: $suffix, suffixIcon: $suffixIcon, visibilityIcon: $visibilityIcon, suffixIconConstraints: $suffixIconConstraints, suffixText: $suffixText, suffixStyle: $suffixStyle, suffixIconColor: $suffixIconColor, counter: $counter, counterText: $counterText, counterStyle: $counterStyle, filled: $filled, fillColor: $fillColor, hoverColor: $hoverColor, focusColor: $focusColor, errorBorder: $errorBorder, focusedBorder: $focusedBorder, focusedErrorBorder: $focusedErrorBorder, disabledBorder: $disabledBorder, enabledBorder: $enabledBorder, border: $border, enabled: $enabled, semanticCounterText: $semanticCounterText, alignLabelWithHint: $alignLabelWithHint, constraints: $constraints)'; } @override @@ -1302,6 +1328,8 @@ class _$_MiraiInputDecoration implements _MiraiInputDecoration { const DeepCollectionEquality().equals(other._suffix, _suffix) && const DeepCollectionEquality() .equals(other._suffixIcon, _suffixIcon) && + const DeepCollectionEquality() + .equals(other._visibilityIcon, _visibilityIcon) && (identical(other.suffixIconConstraints, suffixIconConstraints) || other.suffixIconConstraints == suffixIconConstraints) && (identical(other.suffixText, suffixText) || @@ -1375,6 +1403,7 @@ class _$_MiraiInputDecoration implements _MiraiInputDecoration { prefixIconColor, const DeepCollectionEquality().hash(_suffix), const DeepCollectionEquality().hash(_suffixIcon), + const DeepCollectionEquality().hash(_visibilityIcon), suffixIconConstraints, suffixText, suffixStyle, @@ -1444,6 +1473,7 @@ abstract class _MiraiInputDecoration implements MiraiInputDecoration { final String? prefixIconColor, final Map? suffix, final Map? suffixIcon, + final Map? visibilityIcon, final MiraiBoxConstraints? suffixIconConstraints, final String? suffixText, final MiraiTextStyle? suffixStyle, @@ -1528,6 +1558,8 @@ abstract class _MiraiInputDecoration implements MiraiInputDecoration { @override Map? get suffixIcon; @override + Map? get visibilityIcon; + @override MiraiBoxConstraints? get suffixIconConstraints; @override String? get suffixText; diff --git a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.g.dart b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.g.dart index ce71c6c0..101bbd50 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.g.dart @@ -62,6 +62,7 @@ _$_MiraiInputDecoration _$$_MiraiInputDecorationFromJson( prefixIconColor: json['prefixIconColor'] as String?, suffix: json['suffix'] as Map?, suffixIcon: json['suffixIcon'] as Map?, + visibilityIcon: json['visibilityIcon'] as Map?, suffixIconConstraints: json['suffixIconConstraints'] == null ? null : MiraiBoxConstraints.fromJson( @@ -148,6 +149,7 @@ Map _$$_MiraiInputDecorationToJson( 'prefixIconColor': instance.prefixIconColor, 'suffix': instance.suffix, 'suffixIcon': instance.suffixIcon, + 'visibilityIcon': instance.visibilityIcon, 'suffixIconConstraints': instance.suffixIconConstraints, 'suffixText': instance.suffixText, 'suffixStyle': instance.suffixStyle, diff --git a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart index f39d57ce..27325b09 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart @@ -135,7 +135,11 @@ class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { }); }, child: Mirai.fromJson( - widget.model.decoration?.suffixIcon, context) ?? + (!obscureText && + widget.model.decoration?.visibilityIcon != null) + ? widget.model.decoration?.visibilityIcon + : widget.model.decoration?.suffixIcon, + context) ?? const SizedBox(), ), );