From 389a41091b1ac93631689537d60eb3cf7de498d7 Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Sun, 26 Jan 2025 18:37:20 +0400 Subject: [PATCH] feat: Add tristate, onChanged, mouseCursor and materialTapTargetSize parameters to Mirai Checkbox --- .../mirai_check_box/mirai_check_box.dart | 7 +- .../mirai_check_box.freezed.dart | 126 ++++++++++++++---- .../mirai_check_box/mirai_check_box.g.dart | 57 +++++++- .../mirai_check_box_parser.dart | 45 ++++--- 4 files changed, 186 insertions(+), 49 deletions(-) diff --git a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.dart b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.dart index a0673b77..bdeb6044 100644 --- a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.dart +++ b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.dart @@ -1,5 +1,7 @@ +import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:mirai/src/parsers/mirai_material_color/mirai_material_color.dart'; +import 'package:mirai/src/parsers/mirai_mouse_cursor/mirai_mouse_cursor.dart'; export 'package:mirai/src/parsers/mirai_check_box/mirai_check_box_parser.dart'; @@ -11,14 +13,17 @@ class MiraiCheckBox with _$MiraiCheckBox { const factory MiraiCheckBox({ String? id, bool? value, + @Default(false) bool tristate, + Map? onChanged, + MiraiMouseCursor? mouseCursor, String? activeColor, MiraiMaterialColor? fillColor, String? checkColor, - @Default(false) bool tristate, String? focusColor, String? hoverColor, MiraiMaterialColor? overlayColor, double? splashRadius, + MaterialTapTargetSize? materialTapTargetSize, @Default(false) bool autofocus, @Default(false) bool isError, }) = _MiraiCheckBoxWidget; diff --git a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.freezed.dart b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.freezed.dart index aaba4ff1..3d646fae 100644 --- a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.freezed.dart +++ b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.freezed.dart @@ -22,14 +22,18 @@ MiraiCheckBox _$MiraiCheckBoxFromJson(Map json) { mixin _$MiraiCheckBox { String? get id => throw _privateConstructorUsedError; bool? get value => throw _privateConstructorUsedError; + bool get tristate => throw _privateConstructorUsedError; + Map? get onChanged => throw _privateConstructorUsedError; + MiraiMouseCursor? get mouseCursor => throw _privateConstructorUsedError; String? get activeColor => throw _privateConstructorUsedError; MiraiMaterialColor? get fillColor => throw _privateConstructorUsedError; String? get checkColor => throw _privateConstructorUsedError; - bool get tristate => throw _privateConstructorUsedError; String? get focusColor => throw _privateConstructorUsedError; String? get hoverColor => throw _privateConstructorUsedError; MiraiMaterialColor? get overlayColor => throw _privateConstructorUsedError; double? get splashRadius => throw _privateConstructorUsedError; + MaterialTapTargetSize? get materialTapTargetSize => + throw _privateConstructorUsedError; bool get autofocus => throw _privateConstructorUsedError; bool get isError => throw _privateConstructorUsedError; @@ -52,14 +56,17 @@ abstract class $MiraiCheckBoxCopyWith<$Res> { $Res call( {String? id, bool? value, + bool tristate, + Map? onChanged, + MiraiMouseCursor? mouseCursor, String? activeColor, MiraiMaterialColor? fillColor, String? checkColor, - bool tristate, String? focusColor, String? hoverColor, MiraiMaterialColor? overlayColor, double? splashRadius, + MaterialTapTargetSize? materialTapTargetSize, bool autofocus, bool isError}); @@ -84,14 +91,17 @@ class _$MiraiCheckBoxCopyWithImpl<$Res, $Val extends MiraiCheckBox> $Res call({ Object? id = freezed, Object? value = freezed, + Object? tristate = null, + Object? onChanged = freezed, + Object? mouseCursor = freezed, Object? activeColor = freezed, Object? fillColor = freezed, Object? checkColor = freezed, - Object? tristate = null, Object? focusColor = freezed, Object? hoverColor = freezed, Object? overlayColor = freezed, Object? splashRadius = freezed, + Object? materialTapTargetSize = freezed, Object? autofocus = null, Object? isError = null, }) { @@ -104,6 +114,18 @@ class _$MiraiCheckBoxCopyWithImpl<$Res, $Val extends MiraiCheckBox> ? _value.value : value // ignore: cast_nullable_to_non_nullable as bool?, + tristate: null == tristate + ? _value.tristate + : tristate // ignore: cast_nullable_to_non_nullable + as bool, + onChanged: freezed == onChanged + ? _value.onChanged + : onChanged // ignore: cast_nullable_to_non_nullable + as Map?, + mouseCursor: freezed == mouseCursor + ? _value.mouseCursor + : mouseCursor // ignore: cast_nullable_to_non_nullable + as MiraiMouseCursor?, activeColor: freezed == activeColor ? _value.activeColor : activeColor // ignore: cast_nullable_to_non_nullable @@ -116,10 +138,6 @@ class _$MiraiCheckBoxCopyWithImpl<$Res, $Val extends MiraiCheckBox> ? _value.checkColor : checkColor // ignore: cast_nullable_to_non_nullable as String?, - tristate: null == tristate - ? _value.tristate - : tristate // ignore: cast_nullable_to_non_nullable - as bool, focusColor: freezed == focusColor ? _value.focusColor : focusColor // ignore: cast_nullable_to_non_nullable @@ -136,6 +154,10 @@ class _$MiraiCheckBoxCopyWithImpl<$Res, $Val extends MiraiCheckBox> ? _value.splashRadius : splashRadius // ignore: cast_nullable_to_non_nullable as double?, + materialTapTargetSize: freezed == materialTapTargetSize + ? _value.materialTapTargetSize + : materialTapTargetSize // ignore: cast_nullable_to_non_nullable + as MaterialTapTargetSize?, autofocus: null == autofocus ? _value.autofocus : autofocus // ignore: cast_nullable_to_non_nullable @@ -187,14 +209,17 @@ abstract class _$$MiraiCheckBoxWidgetImplCopyWith<$Res> $Res call( {String? id, bool? value, + bool tristate, + Map? onChanged, + MiraiMouseCursor? mouseCursor, String? activeColor, MiraiMaterialColor? fillColor, String? checkColor, - bool tristate, String? focusColor, String? hoverColor, MiraiMaterialColor? overlayColor, double? splashRadius, + MaterialTapTargetSize? materialTapTargetSize, bool autofocus, bool isError}); @@ -219,14 +244,17 @@ class __$$MiraiCheckBoxWidgetImplCopyWithImpl<$Res> $Res call({ Object? id = freezed, Object? value = freezed, + Object? tristate = null, + Object? onChanged = freezed, + Object? mouseCursor = freezed, Object? activeColor = freezed, Object? fillColor = freezed, Object? checkColor = freezed, - Object? tristate = null, Object? focusColor = freezed, Object? hoverColor = freezed, Object? overlayColor = freezed, Object? splashRadius = freezed, + Object? materialTapTargetSize = freezed, Object? autofocus = null, Object? isError = null, }) { @@ -239,6 +267,18 @@ class __$$MiraiCheckBoxWidgetImplCopyWithImpl<$Res> ? _value.value : value // ignore: cast_nullable_to_non_nullable as bool?, + tristate: null == tristate + ? _value.tristate + : tristate // ignore: cast_nullable_to_non_nullable + as bool, + onChanged: freezed == onChanged + ? _value._onChanged + : onChanged // ignore: cast_nullable_to_non_nullable + as Map?, + mouseCursor: freezed == mouseCursor + ? _value.mouseCursor + : mouseCursor // ignore: cast_nullable_to_non_nullable + as MiraiMouseCursor?, activeColor: freezed == activeColor ? _value.activeColor : activeColor // ignore: cast_nullable_to_non_nullable @@ -251,10 +291,6 @@ class __$$MiraiCheckBoxWidgetImplCopyWithImpl<$Res> ? _value.checkColor : checkColor // ignore: cast_nullable_to_non_nullable as String?, - tristate: null == tristate - ? _value.tristate - : tristate // ignore: cast_nullable_to_non_nullable - as bool, focusColor: freezed == focusColor ? _value.focusColor : focusColor // ignore: cast_nullable_to_non_nullable @@ -271,6 +307,10 @@ class __$$MiraiCheckBoxWidgetImplCopyWithImpl<$Res> ? _value.splashRadius : splashRadius // ignore: cast_nullable_to_non_nullable as double?, + materialTapTargetSize: freezed == materialTapTargetSize + ? _value.materialTapTargetSize + : materialTapTargetSize // ignore: cast_nullable_to_non_nullable + as MaterialTapTargetSize?, autofocus: null == autofocus ? _value.autofocus : autofocus // ignore: cast_nullable_to_non_nullable @@ -289,16 +329,20 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { const _$MiraiCheckBoxWidgetImpl( {this.id, this.value, + this.tristate = false, + final Map? onChanged, + this.mouseCursor, this.activeColor, this.fillColor, this.checkColor, - this.tristate = false, this.focusColor, this.hoverColor, this.overlayColor, this.splashRadius, + this.materialTapTargetSize, this.autofocus = false, - this.isError = false}); + this.isError = false}) + : _onChanged = onChanged; factory _$MiraiCheckBoxWidgetImpl.fromJson(Map json) => _$$MiraiCheckBoxWidgetImplFromJson(json); @@ -308,15 +352,27 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { @override final bool? value; @override + @JsonKey() + final bool tristate; + final Map? _onChanged; + @override + Map? get onChanged { + final value = _onChanged; + if (value == null) return null; + if (_onChanged is EqualUnmodifiableMapView) return _onChanged; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + final MiraiMouseCursor? mouseCursor; + @override final String? activeColor; @override final MiraiMaterialColor? fillColor; @override final String? checkColor; @override - @JsonKey() - final bool tristate; - @override final String? focusColor; @override final String? hoverColor; @@ -325,6 +381,8 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { @override final double? splashRadius; @override + final MaterialTapTargetSize? materialTapTargetSize; + @override @JsonKey() final bool autofocus; @override @@ -333,7 +391,7 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { @override String toString() { - return 'MiraiCheckBox(id: $id, value: $value, activeColor: $activeColor, fillColor: $fillColor, checkColor: $checkColor, tristate: $tristate, focusColor: $focusColor, hoverColor: $hoverColor, overlayColor: $overlayColor, splashRadius: $splashRadius, autofocus: $autofocus, isError: $isError)'; + return 'MiraiCheckBox(id: $id, value: $value, tristate: $tristate, onChanged: $onChanged, mouseCursor: $mouseCursor, activeColor: $activeColor, fillColor: $fillColor, checkColor: $checkColor, focusColor: $focusColor, hoverColor: $hoverColor, overlayColor: $overlayColor, splashRadius: $splashRadius, materialTapTargetSize: $materialTapTargetSize, autofocus: $autofocus, isError: $isError)'; } @override @@ -343,14 +401,18 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { other is _$MiraiCheckBoxWidgetImpl && (identical(other.id, id) || other.id == id) && (identical(other.value, value) || other.value == value) && + (identical(other.tristate, tristate) || + other.tristate == tristate) && + const DeepCollectionEquality() + .equals(other._onChanged, _onChanged) && + (identical(other.mouseCursor, mouseCursor) || + other.mouseCursor == mouseCursor) && (identical(other.activeColor, activeColor) || other.activeColor == activeColor) && (identical(other.fillColor, fillColor) || other.fillColor == fillColor) && (identical(other.checkColor, checkColor) || other.checkColor == checkColor) && - (identical(other.tristate, tristate) || - other.tristate == tristate) && (identical(other.focusColor, focusColor) || other.focusColor == focusColor) && (identical(other.hoverColor, hoverColor) || @@ -359,6 +421,8 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { other.overlayColor == overlayColor) && (identical(other.splashRadius, splashRadius) || other.splashRadius == splashRadius) && + (identical(other.materialTapTargetSize, materialTapTargetSize) || + other.materialTapTargetSize == materialTapTargetSize) && (identical(other.autofocus, autofocus) || other.autofocus == autofocus) && (identical(other.isError, isError) || other.isError == isError)); @@ -370,14 +434,17 @@ class _$MiraiCheckBoxWidgetImpl implements _MiraiCheckBoxWidget { runtimeType, id, value, + tristate, + const DeepCollectionEquality().hash(_onChanged), + mouseCursor, activeColor, fillColor, checkColor, - tristate, focusColor, hoverColor, overlayColor, splashRadius, + materialTapTargetSize, autofocus, isError); @@ -402,14 +469,17 @@ abstract class _MiraiCheckBoxWidget implements MiraiCheckBox { const factory _MiraiCheckBoxWidget( {final String? id, final bool? value, + final bool tristate, + final Map? onChanged, + final MiraiMouseCursor? mouseCursor, final String? activeColor, final MiraiMaterialColor? fillColor, final String? checkColor, - final bool tristate, final String? focusColor, final String? hoverColor, final MiraiMaterialColor? overlayColor, final double? splashRadius, + final MaterialTapTargetSize? materialTapTargetSize, final bool autofocus, final bool isError}) = _$MiraiCheckBoxWidgetImpl; @@ -421,14 +491,18 @@ abstract class _MiraiCheckBoxWidget implements MiraiCheckBox { @override bool? get value; @override + bool get tristate; + @override + Map? get onChanged; + @override + MiraiMouseCursor? get mouseCursor; + @override String? get activeColor; @override MiraiMaterialColor? get fillColor; @override String? get checkColor; @override - bool get tristate; - @override String? get focusColor; @override String? get hoverColor; @@ -437,6 +511,8 @@ abstract class _MiraiCheckBoxWidget implements MiraiCheckBox { @override double? get splashRadius; @override + MaterialTapTargetSize? get materialTapTargetSize; + @override bool get autofocus; @override bool get isError; diff --git a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.g.dart b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.g.dart index 2fba5533..a50b7f1b 100644 --- a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box.g.dart @@ -11,13 +11,16 @@ _$MiraiCheckBoxWidgetImpl _$$MiraiCheckBoxWidgetImplFromJson( _$MiraiCheckBoxWidgetImpl( id: json['id'] as String?, value: json['value'] as bool?, + tristate: json['tristate'] as bool? ?? false, + onChanged: json['onChanged'] as Map?, + mouseCursor: + $enumDecodeNullable(_$MiraiMouseCursorEnumMap, json['mouseCursor']), activeColor: json['activeColor'] as String?, fillColor: json['fillColor'] == null ? null : MiraiMaterialColor.fromJson( json['fillColor'] as Map), checkColor: json['checkColor'] as String?, - tristate: json['tristate'] as bool? ?? false, focusColor: json['focusColor'] as String?, hoverColor: json['hoverColor'] as String?, overlayColor: json['overlayColor'] == null @@ -25,6 +28,8 @@ _$MiraiCheckBoxWidgetImpl _$$MiraiCheckBoxWidgetImplFromJson( : MiraiMaterialColor.fromJson( json['overlayColor'] as Map), splashRadius: (json['splashRadius'] as num?)?.toDouble(), + materialTapTargetSize: $enumDecodeNullable( + _$MaterialTapTargetSizeEnumMap, json['materialTapTargetSize']), autofocus: json['autofocus'] as bool? ?? false, isError: json['isError'] as bool? ?? false, ); @@ -34,14 +39,62 @@ Map _$$MiraiCheckBoxWidgetImplToJson( { 'id': instance.id, 'value': instance.value, + 'tristate': instance.tristate, + 'onChanged': instance.onChanged, + 'mouseCursor': _$MiraiMouseCursorEnumMap[instance.mouseCursor], 'activeColor': instance.activeColor, 'fillColor': instance.fillColor, 'checkColor': instance.checkColor, - 'tristate': instance.tristate, 'focusColor': instance.focusColor, 'hoverColor': instance.hoverColor, 'overlayColor': instance.overlayColor, 'splashRadius': instance.splashRadius, + 'materialTapTargetSize': + _$MaterialTapTargetSizeEnumMap[instance.materialTapTargetSize], 'autofocus': instance.autofocus, 'isError': instance.isError, }; + +const _$MiraiMouseCursorEnumMap = { + MiraiMouseCursor.none: 'none', + MiraiMouseCursor.basic: 'basic', + MiraiMouseCursor.click: 'click', + MiraiMouseCursor.forbidden: 'forbidden', + MiraiMouseCursor.wait: 'wait', + MiraiMouseCursor.progress: 'progress', + MiraiMouseCursor.contextMenu: 'contextMenu', + MiraiMouseCursor.help: 'help', + MiraiMouseCursor.text: 'text', + MiraiMouseCursor.verticalText: 'verticalText', + MiraiMouseCursor.cell: 'cell', + MiraiMouseCursor.precise: 'precise', + MiraiMouseCursor.move: 'move', + MiraiMouseCursor.grab: 'grab', + MiraiMouseCursor.grabbing: 'grabbing', + MiraiMouseCursor.noDrop: 'noDrop', + MiraiMouseCursor.alias: 'alias', + MiraiMouseCursor.copy: 'copy', + MiraiMouseCursor.disappearing: 'disappearing', + MiraiMouseCursor.allScroll: 'allScroll', + MiraiMouseCursor.resizeLeftRight: 'resizeLeftRight', + MiraiMouseCursor.resizeUpDown: 'resizeUpDown', + MiraiMouseCursor.resizeUpLeftDownRight: 'resizeUpLeftDownRight', + MiraiMouseCursor.resizeUpRightDownLeft: 'resizeUpRightDownLeft', + MiraiMouseCursor.resizeUp: 'resizeUp', + MiraiMouseCursor.resizeDown: 'resizeDown', + MiraiMouseCursor.resizeLeft: 'resizeLeft', + MiraiMouseCursor.resizeRight: 'resizeRight', + MiraiMouseCursor.resizeUpLeft: 'resizeUpLeft', + MiraiMouseCursor.resizeUpRight: 'resizeUpRight', + MiraiMouseCursor.resizeDownLeft: 'resizeDownLeft', + MiraiMouseCursor.resizeDownRight: 'resizeDownRight', + MiraiMouseCursor.resizeColumn: 'resizeColumn', + MiraiMouseCursor.resizeRow: 'resizeRow', + MiraiMouseCursor.zoomIn: 'zoomIn', + MiraiMouseCursor.zoomOut: 'zoomOut', +}; + +const _$MaterialTapTargetSizeEnumMap = { + MaterialTapTargetSize.padded: 'padded', + MaterialTapTargetSize.shrinkWrap: 'shrinkWrap', +}; diff --git a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box_parser.dart b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box_parser.dart index 5f85a74f..8dea7a71 100644 --- a/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_check_box/mirai_check_box_parser.dart @@ -47,26 +47,29 @@ class _MiraiCheckBoxState extends State<_MiraiCheckBox> { @override Widget build(BuildContext context) { return Checkbox( - value: isMarkChecked, - onChanged: (value) { - setState(() { - isMarkChecked = !isMarkChecked; - }); - if (widget.model.id != null) { - widget.formScope?.formData[widget.model.id!] = value; - } - }, - activeColor: widget.model.activeColor.toColor(context), - fillColor: - WidgetStateProperty.all(widget.model.fillColor?.parse(context)), - checkColor: widget.model.checkColor.toColor(context), - tristate: widget.model.tristate, - focusColor: widget.model.focusColor.toColor(context), - hoverColor: widget.model.hoverColor.toColor(context), - overlayColor: - WidgetStateProperty.all(widget.model.overlayColor?.parse(context)), - splashRadius: widget.model.splashRadius, - autofocus: widget.model.autofocus, - isError: widget.model.isError); + value: isMarkChecked, + tristate: widget.model.tristate, + onChanged: (value) { + setState(() { + isMarkChecked = !isMarkChecked; + }); + if (widget.model.id != null) { + widget.formScope?.formData[widget.model.id!] = value; + } + }, + mouseCursor: widget.model.mouseCursor?.value, + activeColor: widget.model.activeColor.toColor(context), + fillColor: + WidgetStateProperty.all(widget.model.fillColor?.parse(context)), + checkColor: widget.model.checkColor.toColor(context), + focusColor: widget.model.focusColor.toColor(context), + hoverColor: widget.model.hoverColor.toColor(context), + overlayColor: + WidgetStateProperty.all(widget.model.overlayColor?.parse(context)), + splashRadius: widget.model.splashRadius, + materialTapTargetSize: widget.model.materialTapTargetSize, + autofocus: widget.model.autofocus, + isError: widget.model.isError, + ); } }