From 90cc40946f6b04c41cb704ed0f95526ba4158235 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 00:49:43 +0400 Subject: [PATCH 01/21] Adding AspectRatio --- packages/mirai/lib/src/framework/mirai.dart | 2 + .../mirai_aspect_ratio.dart | 16 ++ .../mirai_aspect_ratio.freezed.dart | 195 ++++++++++++++++++ .../mirai_aspect_ratio.g.dart | 21 ++ .../mirai_aspect_ratio_parser.dart | 24 +++ packages/mirai/lib/src/parsers/parsers.dart | 2 + packages/mirai/lib/src/utils/widget_type.dart | 2 + 7 files changed, 262 insertions(+) create mode 100644 packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 5388be24..3dd3f5e0 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -92,6 +92,8 @@ class Mirai { const MiraiSliderParser(), const MiraiOpacityParser(), const MiraiPlaceholderParser(), + const MiraiAspectRatioParser(), + const MiraiFittedBoxParser(), ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart new file mode 100644 index 00000000..c4239708 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart @@ -0,0 +1,16 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart'; + +part 'mirai_aspect_ratio.freezed.dart'; +part 'mirai_aspect_ratio.g.dart'; + +@freezed +class MiraiAspectRatio with _$MiraiAspectRatio { + const factory MiraiAspectRatio({ + @Default(1) double aspectRatio, + Map? child, + }) = _MiraiAspectRatio; + + factory MiraiAspectRatio.fromJson(Map json) => + _$MiraiAspectRatioFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart new file mode 100644 index 00000000..8e0f9fed --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart @@ -0,0 +1,195 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_aspect_ratio.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiAspectRatio _$MiraiAspectRatioFromJson(Map json) { + return _MiraiAspectRatio.fromJson(json); +} + +/// @nodoc +mixin _$MiraiAspectRatio { + double get aspectRatio => throw _privateConstructorUsedError; + Map? get child => throw _privateConstructorUsedError; + + /// Serializes this MiraiAspectRatio to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiAspectRatioCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiAspectRatioCopyWith<$Res> { + factory $MiraiAspectRatioCopyWith( + MiraiAspectRatio value, $Res Function(MiraiAspectRatio) then) = + _$MiraiAspectRatioCopyWithImpl<$Res, MiraiAspectRatio>; + @useResult + $Res call({double aspectRatio, Map? child}); +} + +/// @nodoc +class _$MiraiAspectRatioCopyWithImpl<$Res, $Val extends MiraiAspectRatio> + implements $MiraiAspectRatioCopyWith<$Res> { + _$MiraiAspectRatioCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? aspectRatio = null, + Object? child = freezed, + }) { + return _then(_value.copyWith( + aspectRatio: null == aspectRatio + ? _value.aspectRatio + : aspectRatio // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiAspectRatioImplCopyWith<$Res> + implements $MiraiAspectRatioCopyWith<$Res> { + factory _$$MiraiAspectRatioImplCopyWith(_$MiraiAspectRatioImpl value, + $Res Function(_$MiraiAspectRatioImpl) then) = + __$$MiraiAspectRatioImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double aspectRatio, Map? child}); +} + +/// @nodoc +class __$$MiraiAspectRatioImplCopyWithImpl<$Res> + extends _$MiraiAspectRatioCopyWithImpl<$Res, _$MiraiAspectRatioImpl> + implements _$$MiraiAspectRatioImplCopyWith<$Res> { + __$$MiraiAspectRatioImplCopyWithImpl(_$MiraiAspectRatioImpl _value, + $Res Function(_$MiraiAspectRatioImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? aspectRatio = null, + Object? child = freezed, + }) { + return _then(_$MiraiAspectRatioImpl( + aspectRatio: null == aspectRatio + ? _value.aspectRatio + : aspectRatio // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiAspectRatioImpl implements _MiraiAspectRatio { + const _$MiraiAspectRatioImpl( + {this.aspectRatio = 1, final Map? child}) + : _child = child; + + factory _$MiraiAspectRatioImpl.fromJson(Map json) => + _$$MiraiAspectRatioImplFromJson(json); + + @override + @JsonKey() + final double aspectRatio; + final Map? _child; + @override + Map? get child { + final value = _child; + if (value == null) return null; + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + String toString() { + return 'MiraiAspectRatio(aspectRatio: $aspectRatio, child: $child)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiAspectRatioImpl && + (identical(other.aspectRatio, aspectRatio) || + other.aspectRatio == aspectRatio) && + const DeepCollectionEquality().equals(other._child, _child)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, aspectRatio, const DeepCollectionEquality().hash(_child)); + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiAspectRatioImplCopyWith<_$MiraiAspectRatioImpl> get copyWith => + __$$MiraiAspectRatioImplCopyWithImpl<_$MiraiAspectRatioImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiAspectRatioImplToJson( + this, + ); + } +} + +abstract class _MiraiAspectRatio implements MiraiAspectRatio { + const factory _MiraiAspectRatio( + {final double aspectRatio, + final Map? child}) = _$MiraiAspectRatioImpl; + + factory _MiraiAspectRatio.fromJson(Map json) = + _$MiraiAspectRatioImpl.fromJson; + + @override + double get aspectRatio; + @override + Map? get child; + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiAspectRatioImplCopyWith<_$MiraiAspectRatioImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart new file mode 100644 index 00000000..2bc94e90 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_aspect_ratio.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiAspectRatioImpl _$$MiraiAspectRatioImplFromJson( + Map json) => + _$MiraiAspectRatioImpl( + aspectRatio: (json['aspectRatio'] as num?)?.toDouble() ?? 1, + child: json['child'] as Map?, + ); + +Map _$$MiraiAspectRatioImplToJson( + _$MiraiAspectRatioImpl instance) => + { + 'aspectRatio': instance.aspectRatio, + 'child': instance.child, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart new file mode 100644 index 00000000..2eaf477a --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiAspectRatioParser extends MiraiParser { + const MiraiAspectRatioParser(); + + @override + String get type => WidgetType.aspectRatio.name; + + @override + MiraiAspectRatio getModel(Map json) => + MiraiAspectRatio.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiAspectRatio model) { + return AspectRatio( + aspectRatio: model.aspectRatio, + child: Mirai.fromJson(model.child, context), + ); + } +} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index a6d14bd7..9e1787d2 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -87,3 +87,5 @@ export 'package:mirai/src/parsers/mirai_radio_group/mirai_radio_group.dart'; export 'package:mirai/src/parsers/mirai_slider/mirai_slider.dart'; export 'package:mirai/src/parsers/mirai_opacity/mirai_opacity.dart'; export 'package:mirai/src/parsers/mirai_placeholder/mirai_placeholder.dart'; +export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; +export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index a8262727..c14bcd9c 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -62,4 +62,6 @@ enum WidgetType { slider, opacity, placeholder, + aspectRatio, + fittedBox, } From d871e75b7cb04cce2e1873f1b8b5323a57e52c2b Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 00:52:55 +0400 Subject: [PATCH 02/21] Adding Adding AspectRatio Doc --- website/docs/widgets/aspect_ratio.md | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 website/docs/widgets/aspect_ratio.md diff --git a/website/docs/widgets/aspect_ratio.md b/website/docs/widgets/aspect_ratio.md new file mode 100644 index 00000000..4c6a73d0 --- /dev/null +++ b/website/docs/widgets/aspect_ratio.md @@ -0,0 +1,30 @@ +# AspectRatio + +Mirai aspectRatio allows you to build the Flutter AspectRatio widget using JSON. +To know more about the aspectRatio widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/AspectRatio-class.html). + +--- + +## Properties + +| Property | Type | Description | +| ------------- | ----------------------- | ------------------------------------------------------------------------------------------------ | +| `aspectRatio` | `double` | The desired width-to-height ratio for the child widget. Defaults to `1` (a square aspect ratio). | +| `child` | `Map?` | The child widget that should adhere to the specified aspect ratio, represented as a JSON object. | + +--- + +## Example JSON + +```json +{ + "type": "aspectRatio", + "aspectRatio": 4 / 3, + "child": { + "type": "container", + "color": "#FF5733", + "width": 100, + "height": 100 + } +} +``` From baf4ef06c64ccf7aa619498d35c70a6d24104c6b Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 00:53:31 +0400 Subject: [PATCH 03/21] Adding FittedBox Widget --- .../mirai_fitted_box/mirai_fitted_box.dart | 22 ++ .../mirai_fitted_box.freezed.dart | 243 ++++++++++++++++++ .../mirai_fitted_box/mirai_fitted_box.g.dart | 56 ++++ .../mirai_fitted_box_parser.dart | 26 ++ 4 files changed, 347 insertions(+) create mode 100644 packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart new file mode 100644 index 00000000..4aa981f3 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:mirai/src/parsers/parsers.dart'; + +export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart'; + +part 'mirai_fitted_box.freezed.dart'; +part 'mirai_fitted_box.g.dart'; + +@freezed +class MiraiFittedBox with _$MiraiFittedBox { + const factory MiraiFittedBox({ + @Default(BoxFit.contain) BoxFit fit, + @Default(MiraiAlignmentDirectional.center) + MiraiAlignmentDirectional alignment, + @Default(Clip.none) Clip clipBehavior, + Map? child, + }) = _MiraiFittedBox; + + factory MiraiFittedBox.fromJson(Map json) => + _$MiraiFittedBoxFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart new file mode 100644 index 00000000..f52abd02 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart @@ -0,0 +1,243 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_fitted_box.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiFittedBox _$MiraiFittedBoxFromJson(Map json) { + return _MiraiFittedBox.fromJson(json); +} + +/// @nodoc +mixin _$MiraiFittedBox { + BoxFit get fit => throw _privateConstructorUsedError; + MiraiAlignmentDirectional get alignment => throw _privateConstructorUsedError; + Clip get clipBehavior => throw _privateConstructorUsedError; + Map? get child => throw _privateConstructorUsedError; + + /// Serializes this MiraiFittedBox to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiFittedBoxCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiFittedBoxCopyWith<$Res> { + factory $MiraiFittedBoxCopyWith( + MiraiFittedBox value, $Res Function(MiraiFittedBox) then) = + _$MiraiFittedBoxCopyWithImpl<$Res, MiraiFittedBox>; + @useResult + $Res call( + {BoxFit fit, + MiraiAlignmentDirectional alignment, + Clip clipBehavior, + Map? child}); +} + +/// @nodoc +class _$MiraiFittedBoxCopyWithImpl<$Res, $Val extends MiraiFittedBox> + implements $MiraiFittedBoxCopyWith<$Res> { + _$MiraiFittedBoxCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? fit = null, + Object? alignment = null, + Object? clipBehavior = null, + Object? child = freezed, + }) { + return _then(_value.copyWith( + fit: null == fit + ? _value.fit + : fit // ignore: cast_nullable_to_non_nullable + as BoxFit, + alignment: null == alignment + ? _value.alignment + : alignment // ignore: cast_nullable_to_non_nullable + as MiraiAlignmentDirectional, + clipBehavior: null == clipBehavior + ? _value.clipBehavior + : clipBehavior // ignore: cast_nullable_to_non_nullable + as Clip, + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiFittedBoxImplCopyWith<$Res> + implements $MiraiFittedBoxCopyWith<$Res> { + factory _$$MiraiFittedBoxImplCopyWith(_$MiraiFittedBoxImpl value, + $Res Function(_$MiraiFittedBoxImpl) then) = + __$$MiraiFittedBoxImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {BoxFit fit, + MiraiAlignmentDirectional alignment, + Clip clipBehavior, + Map? child}); +} + +/// @nodoc +class __$$MiraiFittedBoxImplCopyWithImpl<$Res> + extends _$MiraiFittedBoxCopyWithImpl<$Res, _$MiraiFittedBoxImpl> + implements _$$MiraiFittedBoxImplCopyWith<$Res> { + __$$MiraiFittedBoxImplCopyWithImpl( + _$MiraiFittedBoxImpl _value, $Res Function(_$MiraiFittedBoxImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? fit = null, + Object? alignment = null, + Object? clipBehavior = null, + Object? child = freezed, + }) { + return _then(_$MiraiFittedBoxImpl( + fit: null == fit + ? _value.fit + : fit // ignore: cast_nullable_to_non_nullable + as BoxFit, + alignment: null == alignment + ? _value.alignment + : alignment // ignore: cast_nullable_to_non_nullable + as MiraiAlignmentDirectional, + clipBehavior: null == clipBehavior + ? _value.clipBehavior + : clipBehavior // ignore: cast_nullable_to_non_nullable + as Clip, + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiFittedBoxImpl implements _MiraiFittedBox { + const _$MiraiFittedBoxImpl( + {this.fit = BoxFit.contain, + this.alignment = MiraiAlignmentDirectional.center, + this.clipBehavior = Clip.none, + final Map? child}) + : _child = child; + + factory _$MiraiFittedBoxImpl.fromJson(Map json) => + _$$MiraiFittedBoxImplFromJson(json); + + @override + @JsonKey() + final BoxFit fit; + @override + @JsonKey() + final MiraiAlignmentDirectional alignment; + @override + @JsonKey() + final Clip clipBehavior; + final Map? _child; + @override + Map? get child { + final value = _child; + if (value == null) return null; + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + String toString() { + return 'MiraiFittedBox(fit: $fit, alignment: $alignment, clipBehavior: $clipBehavior, child: $child)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiFittedBoxImpl && + (identical(other.fit, fit) || other.fit == fit) && + (identical(other.alignment, alignment) || + other.alignment == alignment) && + (identical(other.clipBehavior, clipBehavior) || + other.clipBehavior == clipBehavior) && + const DeepCollectionEquality().equals(other._child, _child)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, fit, alignment, clipBehavior, + const DeepCollectionEquality().hash(_child)); + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiFittedBoxImplCopyWith<_$MiraiFittedBoxImpl> get copyWith => + __$$MiraiFittedBoxImplCopyWithImpl<_$MiraiFittedBoxImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiFittedBoxImplToJson( + this, + ); + } +} + +abstract class _MiraiFittedBox implements MiraiFittedBox { + const factory _MiraiFittedBox( + {final BoxFit fit, + final MiraiAlignmentDirectional alignment, + final Clip clipBehavior, + final Map? child}) = _$MiraiFittedBoxImpl; + + factory _MiraiFittedBox.fromJson(Map json) = + _$MiraiFittedBoxImpl.fromJson; + + @override + BoxFit get fit; + @override + MiraiAlignmentDirectional get alignment; + @override + Clip get clipBehavior; + @override + Map? get child; + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiFittedBoxImplCopyWith<_$MiraiFittedBoxImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart new file mode 100644 index 00000000..b1ae465e --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart @@ -0,0 +1,56 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_fitted_box.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiFittedBoxImpl _$$MiraiFittedBoxImplFromJson(Map json) => + _$MiraiFittedBoxImpl( + fit: $enumDecodeNullable(_$BoxFitEnumMap, json['fit']) ?? BoxFit.contain, + alignment: $enumDecodeNullable( + _$MiraiAlignmentDirectionalEnumMap, json['alignment']) ?? + MiraiAlignmentDirectional.center, + clipBehavior: + $enumDecodeNullable(_$ClipEnumMap, json['clipBehavior']) ?? Clip.none, + child: json['child'] as Map?, + ); + +Map _$$MiraiFittedBoxImplToJson( + _$MiraiFittedBoxImpl instance) => + { + 'fit': _$BoxFitEnumMap[instance.fit]!, + 'alignment': _$MiraiAlignmentDirectionalEnumMap[instance.alignment]!, + 'clipBehavior': _$ClipEnumMap[instance.clipBehavior]!, + 'child': instance.child, + }; + +const _$BoxFitEnumMap = { + BoxFit.fill: 'fill', + BoxFit.contain: 'contain', + BoxFit.cover: 'cover', + BoxFit.fitWidth: 'fitWidth', + BoxFit.fitHeight: 'fitHeight', + BoxFit.none: 'none', + BoxFit.scaleDown: 'scaleDown', +}; + +const _$MiraiAlignmentDirectionalEnumMap = { + MiraiAlignmentDirectional.topStart: 'topStart', + MiraiAlignmentDirectional.topCenter: 'topCenter', + MiraiAlignmentDirectional.topEnd: 'topEnd', + MiraiAlignmentDirectional.centerStart: 'centerStart', + MiraiAlignmentDirectional.center: 'center', + MiraiAlignmentDirectional.centerEnd: 'centerEnd', + MiraiAlignmentDirectional.bottomStart: 'bottomStart', + MiraiAlignmentDirectional.bottomCenter: 'bottomCenter', + MiraiAlignmentDirectional.bottomEnd: 'bottomEnd', +}; + +const _$ClipEnumMap = { + Clip.none: 'none', + Clip.hardEdge: 'hardEdge', + Clip.antiAlias: 'antiAlias', + Clip.antiAliasWithSaveLayer: 'antiAliasWithSaveLayer', +}; diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart new file mode 100644 index 00000000..6f8a71cc --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiFittedBoxParser extends MiraiParser { + const MiraiFittedBoxParser(); + + @override + String get type => WidgetType.fittedBox.name; + + @override + MiraiFittedBox getModel(Map json) => + MiraiFittedBox.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiFittedBox model) { + return FittedBox( + fit: model.fit, + alignment: model.alignment.value, + clipBehavior: model.clipBehavior, + child: Mirai.fromJson(model.child, context), + ); + } +} From aae312ac11007bde067596bafc773f8f6a23b7b9 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 00:53:49 +0400 Subject: [PATCH 04/21] Adding FittedBox Doc --- website/docs/widgets/fitted_box.md | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 website/docs/widgets/fitted_box.md diff --git a/website/docs/widgets/fitted_box.md b/website/docs/widgets/fitted_box.md new file mode 100644 index 00000000..122e31ae --- /dev/null +++ b/website/docs/widgets/fitted_box.md @@ -0,0 +1,84 @@ +# FittedBox + +Mirai FittedBox allows you to build the Flutter FittedBox widget using JSON. +To know more about the FittedBox widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/FittedBox-class.html). + +--- + +## Properties + +| Property | Type | Description | +| -------------- | --------------------------- | ------------------------------------------------------------------------------------ | +| `fit` | `BoxFit` | Defines how the child should be fitted within the box. Defaults to `BoxFit.contain`. | +| `alignment` | `MiraiAlignmentDirectional` | Aligns the child within the box. Defaults to `MiraiAlignmentDirectional.center`. | +| `clipBehavior` | `Clip` | Specifies whether and how the content should be clipped. Defaults to `Clip.none`. | +| `child` | `Map?` | The child widget, represented as a JSON object, to be positioned and scaled. | + +--- + +## Enums + +### BoxFit + +The `fit` property supports the following values: + +| Value | Description | +| ----------- | ----------------------------------------------------------------------------------- | +| `fill` | Stretches the child to fill the box, distorting the aspect ratio if necessary. | +| `contain` | Scales the child to fit within the box while maintaining its aspect ratio. | +| `cover` | Scales the child to completely cover the box, possibly cropping parts of it. | +| `fitWidth` | Scales the child to match the width of the box, possibly overflowing vertically. | +| `fitHeight` | Scales the child to match the height of the box, possibly overflowing horizontally. | +| `none` | Positions the child without scaling, potentially allowing it to overflow the box. | +| `scaleDown` | Scales the child down to fit within the box only if it is larger than the box. | + +--- + +### MiraiAlignmentDirectional + +The `alignment` property determines where the child is positioned within the box: + +| Value | Description | +| -------------- | ----------------------------------------- | +| `topStart` | Aligns the child to the top-start corner. | +| `topCenter` | Aligns the child to the top-center. | +| `topEnd` | Aligns the child to the top-end corner. | +| `centerStart` | Aligns the child to the center-start. | +| `center` | Centers the child in the box. | +| `centerEnd` | Aligns the child to the center-end. | +| `bottomStart` | Aligns the child to the bottom-start. | +| `bottomCenter` | Aligns the child to the bottom-center. | +| `bottomEnd` | Aligns the child to the bottom-end. | + +--- + +### Clip + +The `clipBehavior` property determines how the content outside the box is handled: + +| Value | Description | +| ------------------------ | -------------------------------------------------------------------------------- | +| `none` | No clipping is applied (default). | +| `hardEdge` | Clips the content without anti-aliasing. | +| `antiAlias` | Clips the content with anti-aliasing for smoother edges. | +| `antiAliasWithSaveLayer` | Clips the content with anti-aliasing and saves an offscreen buffer for painting. | + +--- + +## Example JSON + +```json +{ + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } +} +``` From 3726d1a25ca1f3be12655a26e67b0235cada8f6f Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 00:54:22 +0400 Subject: [PATCH 05/21] Adding AspectRatio And FittedBox Widget example --- .../assets/json/aspect_ratio_example.json | 39 +++++++++++ .../assets/json/fitted_box_example.json | 42 ++++++++++++ .../assets/json/home_screen.json | 67 +++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 examples/mirai_gallery/assets/json/aspect_ratio_example.json create mode 100644 examples/mirai_gallery/assets/json/fitted_box_example.json diff --git a/examples/mirai_gallery/assets/json/aspect_ratio_example.json b/examples/mirai_gallery/assets/json/aspect_ratio_example.json new file mode 100644 index 00000000..252f8bf3 --- /dev/null +++ b/examples/mirai_gallery/assets/json/aspect_ratio_example.json @@ -0,0 +1,39 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "AspectRatio" + } + }, + "body": { + "type": "padding", + "padding": { + "top": 12, + "left": 12, + "right": 12 + }, + "child": { + "type": "column", + "mainAxisAlignment": "start", + "crossAxisAlignment": "start", + "children": [ + { + "type": "sizedBox", + "height": 12 + }, + { + "type": "aspectRatio", + "aspectRatio": 1.33, + "child": { + "type": "container", + "color": "#FF5733", + "width": 100, + "height": 100 + } + } + ] + } + } +} \ No newline at end of file diff --git a/examples/mirai_gallery/assets/json/fitted_box_example.json b/examples/mirai_gallery/assets/json/fitted_box_example.json new file mode 100644 index 00000000..3107fbe6 --- /dev/null +++ b/examples/mirai_gallery/assets/json/fitted_box_example.json @@ -0,0 +1,42 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "FittedBox" + } + }, + "body": { + "type": "padding", + "padding": { + "top": 12, + "left": 12, + "right": 12 + }, + "child": { + "type": "column", + "mainAxisAlignment": "start", + "crossAxisAlignment": "start", + "children": [ + { + "type": "sizedBox", + "height": 12 + }, + { + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index 8dd0463f..162ef6c8 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -1629,6 +1629,73 @@ "behavior": "floating" } }, + + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "apartment" + }, + + "title": { + "type": "text", + "data": "AspectRatio", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai AspectRatio widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/aspect_ratio_example.json" + } + } + }, + + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "apartment" + }, + + "title": { + "type": "text", + "data": "FittedBox", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai FittedBox widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/fitted_box_example.json" + } + } + }, + { "type": "sizedBox", "height": 24.0 From f23e6d2409d9ea8dca29fd7c30f3b6a264eef520 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 01:58:16 +0400 Subject: [PATCH 06/21] Adding LimitedBox Widget --- packages/mirai/lib/src/framework/mirai.dart | 1 + .../mirai_limited_box/mirai_limited_box.dart | 18 ++ .../mirai_limited_box.freezed.dart | 216 ++++++++++++++++++ .../mirai_limited_box.g.dart | 23 ++ .../mirai_limited_box_parser.dart | 25 ++ packages/mirai/lib/src/parsers/parsers.dart | 1 + packages/mirai/lib/src/utils/widget_type.dart | 1 + 7 files changed, 285 insertions(+) create mode 100644 packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 3dd3f5e0..98cfda8e 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -94,6 +94,7 @@ class Mirai { const MiraiPlaceholderParser(), const MiraiAspectRatioParser(), const MiraiFittedBoxParser(), + const MiraiLimitedBoxParser(), ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart new file mode 100644 index 00000000..89d8c405 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart @@ -0,0 +1,18 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +export 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart'; + +part 'mirai_limited_box.freezed.dart'; +part 'mirai_limited_box.g.dart'; + +@freezed +class MiraiLimitedBox with _$MiraiLimitedBox { + const factory MiraiLimitedBox({ + @Default(double.infinity) double maxHeight, + @Default(double.infinity) double maxWidth, + Map? child, + }) = _MiraiLimitedBox; + + factory MiraiLimitedBox.fromJson(Map json) => + _$MiraiLimitedBoxFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart new file mode 100644 index 00000000..7776dba6 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart @@ -0,0 +1,216 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_limited_box.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiLimitedBox _$MiraiLimitedBoxFromJson(Map json) { + return _MiraiLimitedBox.fromJson(json); +} + +/// @nodoc +mixin _$MiraiLimitedBox { + double get maxHeight => throw _privateConstructorUsedError; + double get maxWidth => throw _privateConstructorUsedError; + Map? get child => throw _privateConstructorUsedError; + + /// Serializes this MiraiLimitedBox to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiLimitedBoxCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiLimitedBoxCopyWith<$Res> { + factory $MiraiLimitedBoxCopyWith( + MiraiLimitedBox value, $Res Function(MiraiLimitedBox) then) = + _$MiraiLimitedBoxCopyWithImpl<$Res, MiraiLimitedBox>; + @useResult + $Res call({double maxHeight, double maxWidth, Map? child}); +} + +/// @nodoc +class _$MiraiLimitedBoxCopyWithImpl<$Res, $Val extends MiraiLimitedBox> + implements $MiraiLimitedBoxCopyWith<$Res> { + _$MiraiLimitedBoxCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? maxHeight = null, + Object? maxWidth = null, + Object? child = freezed, + }) { + return _then(_value.copyWith( + maxHeight: null == maxHeight + ? _value.maxHeight + : maxHeight // ignore: cast_nullable_to_non_nullable + as double, + maxWidth: null == maxWidth + ? _value.maxWidth + : maxWidth // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiLimitedBoxImplCopyWith<$Res> + implements $MiraiLimitedBoxCopyWith<$Res> { + factory _$$MiraiLimitedBoxImplCopyWith(_$MiraiLimitedBoxImpl value, + $Res Function(_$MiraiLimitedBoxImpl) then) = + __$$MiraiLimitedBoxImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double maxHeight, double maxWidth, Map? child}); +} + +/// @nodoc +class __$$MiraiLimitedBoxImplCopyWithImpl<$Res> + extends _$MiraiLimitedBoxCopyWithImpl<$Res, _$MiraiLimitedBoxImpl> + implements _$$MiraiLimitedBoxImplCopyWith<$Res> { + __$$MiraiLimitedBoxImplCopyWithImpl( + _$MiraiLimitedBoxImpl _value, $Res Function(_$MiraiLimitedBoxImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? maxHeight = null, + Object? maxWidth = null, + Object? child = freezed, + }) { + return _then(_$MiraiLimitedBoxImpl( + maxHeight: null == maxHeight + ? _value.maxHeight + : maxHeight // ignore: cast_nullable_to_non_nullable + as double, + maxWidth: null == maxWidth + ? _value.maxWidth + : maxWidth // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiLimitedBoxImpl implements _MiraiLimitedBox { + const _$MiraiLimitedBoxImpl( + {this.maxHeight = double.infinity, + this.maxWidth = double.infinity, + final Map? child}) + : _child = child; + + factory _$MiraiLimitedBoxImpl.fromJson(Map json) => + _$$MiraiLimitedBoxImplFromJson(json); + + @override + @JsonKey() + final double maxHeight; + @override + @JsonKey() + final double maxWidth; + final Map? _child; + @override + Map? get child { + final value = _child; + if (value == null) return null; + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + String toString() { + return 'MiraiLimitedBox(maxHeight: $maxHeight, maxWidth: $maxWidth, child: $child)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiLimitedBoxImpl && + (identical(other.maxHeight, maxHeight) || + other.maxHeight == maxHeight) && + (identical(other.maxWidth, maxWidth) || + other.maxWidth == maxWidth) && + const DeepCollectionEquality().equals(other._child, _child)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, maxHeight, maxWidth, + const DeepCollectionEquality().hash(_child)); + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiLimitedBoxImplCopyWith<_$MiraiLimitedBoxImpl> get copyWith => + __$$MiraiLimitedBoxImplCopyWithImpl<_$MiraiLimitedBoxImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiLimitedBoxImplToJson( + this, + ); + } +} + +abstract class _MiraiLimitedBox implements MiraiLimitedBox { + const factory _MiraiLimitedBox( + {final double maxHeight, + final double maxWidth, + final Map? child}) = _$MiraiLimitedBoxImpl; + + factory _MiraiLimitedBox.fromJson(Map json) = + _$MiraiLimitedBoxImpl.fromJson; + + @override + double get maxHeight; + @override + double get maxWidth; + @override + Map? get child; + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiLimitedBoxImplCopyWith<_$MiraiLimitedBoxImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart new file mode 100644 index 00000000..9babb576 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart @@ -0,0 +1,23 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_limited_box.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiLimitedBoxImpl _$$MiraiLimitedBoxImplFromJson( + Map json) => + _$MiraiLimitedBoxImpl( + maxHeight: (json['maxHeight'] as num?)?.toDouble() ?? double.infinity, + maxWidth: (json['maxWidth'] as num?)?.toDouble() ?? double.infinity, + child: json['child'] as Map?, + ); + +Map _$$MiraiLimitedBoxImplToJson( + _$MiraiLimitedBoxImpl instance) => + { + 'maxHeight': instance.maxHeight, + 'maxWidth': instance.maxWidth, + 'child': instance.child, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart new file mode 100644 index 00000000..b0cc7190 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiLimitedBoxParser extends MiraiParser { + const MiraiLimitedBoxParser(); + + @override + String get type => WidgetType.limitedBox.name; + + @override + MiraiLimitedBox getModel(Map json) => + MiraiLimitedBox.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiLimitedBox model) { + return LimitedBox( + maxHeight: model.maxHeight, + maxWidth: model.maxWidth, + child: Mirai.fromJson(model.child, context), + ); + } +} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index 9e1787d2..304ab6be 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -89,3 +89,4 @@ export 'package:mirai/src/parsers/mirai_opacity/mirai_opacity.dart'; export 'package:mirai/src/parsers/mirai_placeholder/mirai_placeholder.dart'; export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; +export 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index c14bcd9c..2033b652 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -64,4 +64,5 @@ enum WidgetType { placeholder, aspectRatio, fittedBox, + limitedBox, } From bc17b944245e3f3ce6f4c9458dec1bebdd96ec10 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 01:58:35 +0400 Subject: [PATCH 07/21] Adding LimitedBox Doc --- website/docs/widgets/sized_box copy.md | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 website/docs/widgets/sized_box copy.md diff --git a/website/docs/widgets/sized_box copy.md b/website/docs/widgets/sized_box copy.md new file mode 100644 index 00000000..11747a08 --- /dev/null +++ b/website/docs/widgets/sized_box copy.md @@ -0,0 +1,48 @@ +# LimitedBox + +Mirai LimitedBox allows you to build the Flutter LimitedBox widget using JSON. +To know more about the LimitedBox widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/LimitedBox-class.html). + +## Properties + +| Property | Type | Description | +| ----------- | ----------------------- | ---------------------------------------------------------------------------------------------------- | +| `maxHeight` | `double` | The maximum height for the child if the parent's height is unbounded. Defaults to `double.infinity`. | +| `maxWidth` | `double` | The maximum width for the child if the parent's width is unbounded. Defaults to `double.infinity`. | +| `child` | `Map?` | The child widget represented as a JSON object. | + +--- + +## Example JSON + +### Example 1: Limited Box with Default Constraints + +```json +{ + "type": "limitedBox", + "child": { + "type": "container", + "width": 100, + "height": 100, + "color": "#FF0000" + } +} +``` + +### Example 2: Limited Box with Custom Constraints + +```json +{ + "type": "limitedBox", + "maxHeight": 200.0, + "maxWidth": 300.0, + "child": { + "type": "text", + "data": "Hello, World! from Limited Box", + "style": { + "fontSize": 16, + "color": "#000000" + } + } +} +``` From 73930604fbdef308e00fda23d987adc797194f7b Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 02:00:42 +0400 Subject: [PATCH 08/21] re-name limited_box file --- website/docs/widgets/{sized_box copy.md => limited_box.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/docs/widgets/{sized_box copy.md => limited_box.md} (100%) diff --git a/website/docs/widgets/sized_box copy.md b/website/docs/widgets/limited_box.md similarity index 100% rename from website/docs/widgets/sized_box copy.md rename to website/docs/widgets/limited_box.md From 2543dba6f2156eb4331e383319c83468ef104e27 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 02:12:39 +0400 Subject: [PATCH 09/21] add Mirai LimitedBox example --- .../assets/json/home_screen.json | 38 +++++++++++++++++- .../assets/json/limited_box_example.json | 40 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 examples/mirai_gallery/assets/json/limited_box_example.json diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index 162ef6c8..bd9d2cfe 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -1640,7 +1640,7 @@ "title": { "type": "text", - "data": "AspectRatio", + "data": "Mirai AspectRatio", "style": { "fontSize": 21 } @@ -1673,7 +1673,7 @@ "title": { "type": "text", - "data": "FittedBox", + "data": "Mirai FittedBox", "style": { "fontSize": 21 } @@ -1696,6 +1696,40 @@ } }, + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "apartment" + }, + + "title": { + "type": "text", + "data": "Mirai LimitedBox", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai LimitedBox widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/limited_box_example.json" + } + } + }, + + { "type": "sizedBox", "height": 24.0 diff --git a/examples/mirai_gallery/assets/json/limited_box_example.json b/examples/mirai_gallery/assets/json/limited_box_example.json new file mode 100644 index 00000000..fda3e29c --- /dev/null +++ b/examples/mirai_gallery/assets/json/limited_box_example.json @@ -0,0 +1,40 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "LimitedBox" + } + }, + "body": { + "type": "listView", + "shrinkWrap": true, + "children": [ + { + "type": "sizedBox", + "height": 25 + }, + + { + "type": "limitedBox", + "child": { + "type": "container", + "height": 100, + "color": "#FF0000", + "child": { + "type": "text", + "data": "Hello, World! from Limited Box", + "style": { + "fontSize": 16, + "color": "#000000" + } + } + + } + } + + + ] + } +} \ No newline at end of file From 77eae8d6e4a84498d089b95a31a51b001d992846 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 02:34:11 +0400 Subject: [PATCH 10/21] adding Mirai Visibility widget --- packages/mirai/lib/src/framework/mirai.dart | 1 + .../mirai_visibility/mirai_visibility.dart | 23 ++ .../mirai_visibility.freezed.dart | 346 ++++++++++++++++++ .../mirai_visibility/mirai_visibility.g.dart | 33 ++ .../mirai_visibility_parser.dart | 31 ++ packages/mirai/lib/src/parsers/parsers.dart | 1 + packages/mirai/lib/src/utils/widget_type.dart | 1 + 7 files changed, 436 insertions(+) create mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 98cfda8e..301d777b 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -95,6 +95,7 @@ class Mirai { const MiraiAspectRatioParser(), const MiraiFittedBoxParser(), const MiraiLimitedBoxParser(), + const MiraiVisibilityParser() ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart new file mode 100644 index 00000000..dca65498 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart @@ -0,0 +1,23 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +export 'package:mirai/src/parsers/mirai_Visibility/mirai_Visibility_parser.dart'; + +part 'mirai_visibility.freezed.dart'; +part 'mirai_visibility.g.dart'; + +@freezed +class MiraiVisibility with _$MiraiVisibility { + const factory MiraiVisibility({ + required Map child, + Map? replacement, + @Default(true) bool visible, + @Default(false) bool maintainState, + @Default(false) bool maintainAnimation, + @Default(false) bool maintainSize, + @Default(false) bool maintainSemantics, + @Default(false) bool maintainInteractivity, + }) = _MiraiVisibility; + + factory MiraiVisibility.fromJson(Map json) => + _$MiraiVisibilityFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart new file mode 100644 index 00000000..fd5d108e --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart @@ -0,0 +1,346 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_visibility.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiVisibility _$MiraiVisibilityFromJson(Map json) { + return _MiraiVisibility.fromJson(json); +} + +/// @nodoc +mixin _$MiraiVisibility { + Map get child => throw _privateConstructorUsedError; + Map? get replacement => throw _privateConstructorUsedError; + bool get visible => throw _privateConstructorUsedError; + bool get maintainState => throw _privateConstructorUsedError; + bool get maintainAnimation => throw _privateConstructorUsedError; + bool get maintainSize => throw _privateConstructorUsedError; + bool get maintainSemantics => throw _privateConstructorUsedError; + bool get maintainInteractivity => throw _privateConstructorUsedError; + + /// Serializes this MiraiVisibility to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiVisibility + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiVisibilityCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiVisibilityCopyWith<$Res> { + factory $MiraiVisibilityCopyWith( + MiraiVisibility value, $Res Function(MiraiVisibility) then) = + _$MiraiVisibilityCopyWithImpl<$Res, MiraiVisibility>; + @useResult + $Res call( + {Map child, + Map? replacement, + bool visible, + bool maintainState, + bool maintainAnimation, + bool maintainSize, + bool maintainSemantics, + bool maintainInteractivity}); +} + +/// @nodoc +class _$MiraiVisibilityCopyWithImpl<$Res, $Val extends MiraiVisibility> + implements $MiraiVisibilityCopyWith<$Res> { + _$MiraiVisibilityCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiVisibility + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? child = null, + Object? replacement = freezed, + Object? visible = null, + Object? maintainState = null, + Object? maintainAnimation = null, + Object? maintainSize = null, + Object? maintainSemantics = null, + Object? maintainInteractivity = null, + }) { + return _then(_value.copyWith( + child: null == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map, + replacement: freezed == replacement + ? _value.replacement + : replacement // ignore: cast_nullable_to_non_nullable + as Map?, + visible: null == visible + ? _value.visible + : visible // ignore: cast_nullable_to_non_nullable + as bool, + maintainState: null == maintainState + ? _value.maintainState + : maintainState // ignore: cast_nullable_to_non_nullable + as bool, + maintainAnimation: null == maintainAnimation + ? _value.maintainAnimation + : maintainAnimation // ignore: cast_nullable_to_non_nullable + as bool, + maintainSize: null == maintainSize + ? _value.maintainSize + : maintainSize // ignore: cast_nullable_to_non_nullable + as bool, + maintainSemantics: null == maintainSemantics + ? _value.maintainSemantics + : maintainSemantics // ignore: cast_nullable_to_non_nullable + as bool, + maintainInteractivity: null == maintainInteractivity + ? _value.maintainInteractivity + : maintainInteractivity // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiVisibilityImplCopyWith<$Res> + implements $MiraiVisibilityCopyWith<$Res> { + factory _$$MiraiVisibilityImplCopyWith(_$MiraiVisibilityImpl value, + $Res Function(_$MiraiVisibilityImpl) then) = + __$$MiraiVisibilityImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {Map child, + Map? replacement, + bool visible, + bool maintainState, + bool maintainAnimation, + bool maintainSize, + bool maintainSemantics, + bool maintainInteractivity}); +} + +/// @nodoc +class __$$MiraiVisibilityImplCopyWithImpl<$Res> + extends _$MiraiVisibilityCopyWithImpl<$Res, _$MiraiVisibilityImpl> + implements _$$MiraiVisibilityImplCopyWith<$Res> { + __$$MiraiVisibilityImplCopyWithImpl( + _$MiraiVisibilityImpl _value, $Res Function(_$MiraiVisibilityImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiVisibility + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? child = null, + Object? replacement = freezed, + Object? visible = null, + Object? maintainState = null, + Object? maintainAnimation = null, + Object? maintainSize = null, + Object? maintainSemantics = null, + Object? maintainInteractivity = null, + }) { + return _then(_$MiraiVisibilityImpl( + child: null == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map, + replacement: freezed == replacement + ? _value._replacement + : replacement // ignore: cast_nullable_to_non_nullable + as Map?, + visible: null == visible + ? _value.visible + : visible // ignore: cast_nullable_to_non_nullable + as bool, + maintainState: null == maintainState + ? _value.maintainState + : maintainState // ignore: cast_nullable_to_non_nullable + as bool, + maintainAnimation: null == maintainAnimation + ? _value.maintainAnimation + : maintainAnimation // ignore: cast_nullable_to_non_nullable + as bool, + maintainSize: null == maintainSize + ? _value.maintainSize + : maintainSize // ignore: cast_nullable_to_non_nullable + as bool, + maintainSemantics: null == maintainSemantics + ? _value.maintainSemantics + : maintainSemantics // ignore: cast_nullable_to_non_nullable + as bool, + maintainInteractivity: null == maintainInteractivity + ? _value.maintainInteractivity + : maintainInteractivity // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiVisibilityImpl implements _MiraiVisibility { + const _$MiraiVisibilityImpl( + {required final Map child, + final Map? replacement, + this.visible = true, + this.maintainState = false, + this.maintainAnimation = false, + this.maintainSize = false, + this.maintainSemantics = false, + this.maintainInteractivity = false}) + : _child = child, + _replacement = replacement; + + factory _$MiraiVisibilityImpl.fromJson(Map json) => + _$$MiraiVisibilityImplFromJson(json); + + final Map _child; + @override + Map get child { + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_child); + } + + final Map? _replacement; + @override + Map? get replacement { + final value = _replacement; + if (value == null) return null; + if (_replacement is EqualUnmodifiableMapView) return _replacement; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + @JsonKey() + final bool visible; + @override + @JsonKey() + final bool maintainState; + @override + @JsonKey() + final bool maintainAnimation; + @override + @JsonKey() + final bool maintainSize; + @override + @JsonKey() + final bool maintainSemantics; + @override + @JsonKey() + final bool maintainInteractivity; + + @override + String toString() { + return 'MiraiVisibility(child: $child, replacement: $replacement, visible: $visible, maintainState: $maintainState, maintainAnimation: $maintainAnimation, maintainSize: $maintainSize, maintainSemantics: $maintainSemantics, maintainInteractivity: $maintainInteractivity)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiVisibilityImpl && + const DeepCollectionEquality().equals(other._child, _child) && + const DeepCollectionEquality() + .equals(other._replacement, _replacement) && + (identical(other.visible, visible) || other.visible == visible) && + (identical(other.maintainState, maintainState) || + other.maintainState == maintainState) && + (identical(other.maintainAnimation, maintainAnimation) || + other.maintainAnimation == maintainAnimation) && + (identical(other.maintainSize, maintainSize) || + other.maintainSize == maintainSize) && + (identical(other.maintainSemantics, maintainSemantics) || + other.maintainSemantics == maintainSemantics) && + (identical(other.maintainInteractivity, maintainInteractivity) || + other.maintainInteractivity == maintainInteractivity)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(_child), + const DeepCollectionEquality().hash(_replacement), + visible, + maintainState, + maintainAnimation, + maintainSize, + maintainSemantics, + maintainInteractivity); + + /// Create a copy of MiraiVisibility + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiVisibilityImplCopyWith<_$MiraiVisibilityImpl> get copyWith => + __$$MiraiVisibilityImplCopyWithImpl<_$MiraiVisibilityImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiVisibilityImplToJson( + this, + ); + } +} + +abstract class _MiraiVisibility implements MiraiVisibility { + const factory _MiraiVisibility( + {required final Map child, + final Map? replacement, + final bool visible, + final bool maintainState, + final bool maintainAnimation, + final bool maintainSize, + final bool maintainSemantics, + final bool maintainInteractivity}) = _$MiraiVisibilityImpl; + + factory _MiraiVisibility.fromJson(Map json) = + _$MiraiVisibilityImpl.fromJson; + + @override + Map get child; + @override + Map? get replacement; + @override + bool get visible; + @override + bool get maintainState; + @override + bool get maintainAnimation; + @override + bool get maintainSize; + @override + bool get maintainSemantics; + @override + bool get maintainInteractivity; + + /// Create a copy of MiraiVisibility + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiVisibilityImplCopyWith<_$MiraiVisibilityImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart new file mode 100644 index 00000000..e9104b19 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart @@ -0,0 +1,33 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_visibility.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiVisibilityImpl _$$MiraiVisibilityImplFromJson( + Map json) => + _$MiraiVisibilityImpl( + child: json['child'] as Map, + replacement: json['replacement'] as Map?, + visible: json['visible'] as bool? ?? true, + maintainState: json['maintainState'] as bool? ?? false, + maintainAnimation: json['maintainAnimation'] as bool? ?? false, + maintainSize: json['maintainSize'] as bool? ?? false, + maintainSemantics: json['maintainSemantics'] as bool? ?? false, + maintainInteractivity: json['maintainInteractivity'] as bool? ?? false, + ); + +Map _$$MiraiVisibilityImplToJson( + _$MiraiVisibilityImpl instance) => + { + 'child': instance.child, + 'replacement': instance.replacement, + 'visible': instance.visible, + 'maintainState': instance.maintainState, + 'maintainAnimation': instance.maintainAnimation, + 'maintainSize': instance.maintainSize, + 'maintainSemantics': instance.maintainSemantics, + 'maintainInteractivity': instance.maintainInteractivity, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart new file mode 100644 index 00000000..c9e169f3 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_visibility/mirai_visibility.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiVisibilityParser extends MiraiParser { + const MiraiVisibilityParser(); + + @override + String get type => WidgetType.visibility.name; + + @override + MiraiVisibility getModel(Map json) => + MiraiVisibility.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiVisibility model) { + return Visibility( + visible: model.visible, + maintainState: model.maintainState, + maintainAnimation: model.maintainAnimation, + maintainSize: model.maintainSize, + maintainSemantics: model.maintainSemantics, + maintainInteractivity: model.maintainInteractivity, + replacement: + Mirai.fromJson(model.replacement, context) ?? SizedBox.shrink(), + child: Mirai.fromJson(model.child, context) ?? SizedBox.shrink(), + ); + } +} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index 304ab6be..1d0968d2 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -90,3 +90,4 @@ export 'package:mirai/src/parsers/mirai_placeholder/mirai_placeholder.dart'; export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; export 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box.dart'; +export 'package:mirai/src/parsers/mirai_visibility/mirai_visibility.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index 2033b652..59dc7ae9 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -65,4 +65,5 @@ enum WidgetType { aspectRatio, fittedBox, limitedBox, + visibility, } From d2ab1c6e44b2d44c021310c3a2283cd8466b40eb Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 02:41:51 +0400 Subject: [PATCH 11/21] add Mirai Visibility Doc --- website/docs/widgets/visibility.md | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 website/docs/widgets/visibility.md diff --git a/website/docs/widgets/visibility.md b/website/docs/widgets/visibility.md new file mode 100644 index 00000000..bb58d703 --- /dev/null +++ b/website/docs/widgets/visibility.md @@ -0,0 +1,55 @@ +# Visibility + +Mirai Visibility allows you to build the Flutter Visibility widget using JSON. +To know more about the Visibility widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/Visibility-class.html). + +--- + +## Properties + +| Property | Type | Description | +| ----------------------- | ----------------------- | ------------------------------------------------------------------------------------------------- | +| `child` | `Map` | The widget to be displayed when `visible` is `true`. | +| `replacement` | `Map?` | The widget to display when `visible` is `false`. Defaults to an empty widget (`SizedBox.shrink`). | +| `visible` | `bool` | Whether the child is visible. Defaults to `true`. | +| `maintainState` | `bool` | Whether to maintain the state of the widget when it is hidden. Defaults to `false`. | +| `maintainAnimation` | `bool` | Whether to maintain the animation of the widget when it is hidden. Defaults to `false`. | +| `maintainSize` | `bool` | Whether to maintain the size of the widget when it is hidden. Defaults to `false`. | +| `maintainSemantics` | `bool` | Whether to maintain the semantics of the widget when it is hidden. Defaults to `false`. | +| `maintainInteractivity` | `bool` | Whether to maintain the interactivity of the widget when it is hidden. Defaults to `false`. | + +--- + +## Example JSON + +### Example 1: Basic Visibility + +```json +{ + "type": "visibility", + "child": { + "type": "text", + "data": "I am visible!" + }, + "visible": true +} +``` + +### Example 2: Hidden with Replacement + +```json +{ + "type": "visibility", + "child": { + "type": "text", + "data": "I am hidden!" + }, + "replacement": { + "type": "container", + "color": "#FF5733", + "width": 50, + "height": 50 + }, + "visible": false +} +``` From 7e557ac2e6fdf3fd6e38372b24ad02c320f135ca Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 02:49:35 +0400 Subject: [PATCH 12/21] adding mirai visibility example --- .../assets/json/home_screen.json | 33 +++++++++++++ .../assets/json/visibility_example.json | 46 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 examples/mirai_gallery/assets/json/visibility_example.json diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index bd9d2cfe..2b25534f 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -1729,6 +1729,39 @@ } }, + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "visibility" + }, + + "title": { + "type": "text", + "data": "Mirai Visibility", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai Visibility widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/visibility_example.json" + } + } + }, + { "type": "sizedBox", diff --git a/examples/mirai_gallery/assets/json/visibility_example.json b/examples/mirai_gallery/assets/json/visibility_example.json new file mode 100644 index 00000000..bf02dbe9 --- /dev/null +++ b/examples/mirai_gallery/assets/json/visibility_example.json @@ -0,0 +1,46 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "Visibility" + } + }, + "body": { + "type": "listView", + "shrinkWrap": true, + "children": [ + { + "type": "sizedBox", + "height": 25 + }, + { + "type": "visibility", + "child": { + "type": "text", + "data": "I am visible!" + }, + "visible": true + }, + { + "type": "sizedBox", + "height": 25 + }, + { + "type": "visibility", + "child": { + "type": "text", + "data": "I am hidden!" + }, + "replacement": { + "type": "container", + "color": "#FF5733", + "width": 50, + "height": 50 + }, + "visible": false + } + ] + } +} \ No newline at end of file From e9d0301fc41e402d56fd97ad03761a5a0bdf1ef7 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sat, 18 Jan 2025 02:54:59 +0400 Subject: [PATCH 13/21] fix mirai_visibility_parser name --- .../lib/src/parsers/mirai_visibility/mirai_visibility.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart index dca65498..5dd4f45b 100644 --- a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart +++ b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart @@ -1,6 +1,6 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -export 'package:mirai/src/parsers/mirai_Visibility/mirai_Visibility_parser.dart'; +export 'package:mirai/src/parsers/mirai_visibility/mirai_visibility_parser.dart'; part 'mirai_visibility.freezed.dart'; part 'mirai_visibility.g.dart'; From bcfb6c20e008ac6a7d19a2a12933dbca0c1b0dab Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 02:06:21 +0400 Subject: [PATCH 14/21] convert used '/' to double in aspect ratio doc. --- website/docs/widgets/aspect_ratio.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/widgets/aspect_ratio.md b/website/docs/widgets/aspect_ratio.md index 4c6a73d0..36e47daa 100644 --- a/website/docs/widgets/aspect_ratio.md +++ b/website/docs/widgets/aspect_ratio.md @@ -19,7 +19,7 @@ To know more about the aspectRatio widget in Flutter, refer to the [official doc ```json { "type": "aspectRatio", - "aspectRatio": 4 / 3, + "aspectRatio": 1.33, "child": { "type": "container", "color": "#FF5733", From 9af4abf8220a2a47bd79a5a1cce1d588d567a284 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 02:16:25 +0400 Subject: [PATCH 15/21] add MiraiAlignmentDirectional Doc --- .../widgets/mirai_alignment_directional.md | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 website/docs/widgets/mirai_alignment_directional.md diff --git a/website/docs/widgets/mirai_alignment_directional.md b/website/docs/widgets/mirai_alignment_directional.md new file mode 100644 index 00000000..7f49b966 --- /dev/null +++ b/website/docs/widgets/mirai_alignment_directional.md @@ -0,0 +1,37 @@ +### MiraiAlignmentDirectional + +Mirai AlignmentDirectional allows you to handling alignment widget using JSON. + +The `alignment` property determines where the child is positioned within the box: + +| Value | Description | +| -------------- | ----------------------------------------- | +| `topStart` | Aligns the child to the top-start corner. | +| `topCenter` | Aligns the child to the top-center. | +| `topEnd` | Aligns the child to the top-end corner. | +| `centerStart` | Aligns the child to the center-start. | +| `center` | Centers the child in the box. | +| `centerEnd` | Aligns the child to the center-end. | +| `bottomStart` | Aligns the child to the bottom-start. | +| `bottomCenter` | Aligns the child to the bottom-center. | +| `bottomEnd` | Aligns the child to the bottom-end. | + +--- + +## Example JSON + +```json +{ + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } +} +``` From a468e37fbc252a2e3e568a65bfef2673aae0b5b5 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 02:23:09 +0400 Subject: [PATCH 16/21] create property folder in doc --- website/docs/{widgets => property}/mirai_alignment_directional.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/docs/{widgets => property}/mirai_alignment_directional.md (100%) diff --git a/website/docs/widgets/mirai_alignment_directional.md b/website/docs/property/mirai_alignment_directional.md similarity index 100% rename from website/docs/widgets/mirai_alignment_directional.md rename to website/docs/property/mirai_alignment_directional.md From 129ce921a382600a070c6386d5c00b0a87b8a85d Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 02:24:13 +0400 Subject: [PATCH 17/21] adding BoxFit property --- website/docs/property/box_fit.md | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 website/docs/property/box_fit.md diff --git a/website/docs/property/box_fit.md b/website/docs/property/box_fit.md new file mode 100644 index 00000000..1665bfd1 --- /dev/null +++ b/website/docs/property/box_fit.md @@ -0,0 +1,33 @@ +### BoxFit + +The `fit` property supports the following values: + +| Value | Description | +| ----------- | ----------------------------------------------------------------------------------- | +| `fill` | Stretches the child to fill the box, distorting the aspect ratio if necessary. | +| `contain` | Scales the child to fit within the box while maintaining its aspect ratio. | +| `cover` | Scales the child to completely cover the box, possibly cropping parts of it. | +| `fitWidth` | Scales the child to match the width of the box, possibly overflowing vertically. | +| `fitHeight` | Scales the child to match the height of the box, possibly overflowing horizontally. | +| `none` | Positions the child without scaling, potentially allowing it to overflow the box. | +| `scaleDown` | Scales the child down to fit within the box only if it is larger than the box. | + +--- + +## Example JSON + +```json +{ + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } +} +``` From f87ce3ce78e525e74e2fc521244c248a7defa26f Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 02:26:42 +0400 Subject: [PATCH 18/21] add clip_behavior property --- website/docs/property/clip_behavior.md | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 website/docs/property/clip_behavior.md diff --git a/website/docs/property/clip_behavior.md b/website/docs/property/clip_behavior.md new file mode 100644 index 00000000..4ed55f8a --- /dev/null +++ b/website/docs/property/clip_behavior.md @@ -0,0 +1,31 @@ +### Clip + +The `clipBehavior` property determines how the content outside the box is handled: + +| Value | Description | +| ------------------------ | -------------------------------------------------------------------------------- | +| `none` | No clipping is applied (default). | +| `hardEdge` | Clips the content without anti-aliasing. | +| `antiAlias` | Clips the content with anti-aliasing for smoother edges. | +| `antiAliasWithSaveLayer` | Clips the content with anti-aliasing and saves an offscreen buffer for painting. | + +--- + +## Example JSON + +```json +{ + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "clipBehavior": "hardEdge", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } +} +``` From 593a82dfd95919798f31fced21d7b59f51fd36a3 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 02:27:44 +0400 Subject: [PATCH 19/21] Update fitted_box.md --- website/docs/widgets/fitted_box.md | 49 ------------------------------ 1 file changed, 49 deletions(-) diff --git a/website/docs/widgets/fitted_box.md b/website/docs/widgets/fitted_box.md index 122e31ae..6f0ffde1 100644 --- a/website/docs/widgets/fitted_box.md +++ b/website/docs/widgets/fitted_box.md @@ -16,55 +16,6 @@ To know more about the FittedBox widget in Flutter, refer to the [official docum --- -## Enums - -### BoxFit - -The `fit` property supports the following values: - -| Value | Description | -| ----------- | ----------------------------------------------------------------------------------- | -| `fill` | Stretches the child to fill the box, distorting the aspect ratio if necessary. | -| `contain` | Scales the child to fit within the box while maintaining its aspect ratio. | -| `cover` | Scales the child to completely cover the box, possibly cropping parts of it. | -| `fitWidth` | Scales the child to match the width of the box, possibly overflowing vertically. | -| `fitHeight` | Scales the child to match the height of the box, possibly overflowing horizontally. | -| `none` | Positions the child without scaling, potentially allowing it to overflow the box. | -| `scaleDown` | Scales the child down to fit within the box only if it is larger than the box. | - ---- - -### MiraiAlignmentDirectional - -The `alignment` property determines where the child is positioned within the box: - -| Value | Description | -| -------------- | ----------------------------------------- | -| `topStart` | Aligns the child to the top-start corner. | -| `topCenter` | Aligns the child to the top-center. | -| `topEnd` | Aligns the child to the top-end corner. | -| `centerStart` | Aligns the child to the center-start. | -| `center` | Centers the child in the box. | -| `centerEnd` | Aligns the child to the center-end. | -| `bottomStart` | Aligns the child to the bottom-start. | -| `bottomCenter` | Aligns the child to the bottom-center. | -| `bottomEnd` | Aligns the child to the bottom-end. | - ---- - -### Clip - -The `clipBehavior` property determines how the content outside the box is handled: - -| Value | Description | -| ------------------------ | -------------------------------------------------------------------------------- | -| `none` | No clipping is applied (default). | -| `hardEdge` | Clips the content without anti-aliasing. | -| `antiAlias` | Clips the content with anti-aliasing for smoother edges. | -| `antiAliasWithSaveLayer` | Clips the content with anti-aliasing and saves an offscreen buffer for painting. | - ---- - ## Example JSON ```json From 802baadb493fdad34adb5ed31c71c070285379c6 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 14:32:37 +0400 Subject: [PATCH 20/21] rename property folder to styles --- website/docs/styles/_category_.json | 8 ++++++++ website/docs/{property => styles}/box_fit.md | 15 ++------------- .../docs/{property => styles}/clip_behavior.md | 16 ++-------------- .../mirai_alignment_directional.md | 15 ++------------- 4 files changed, 14 insertions(+), 40 deletions(-) create mode 100644 website/docs/styles/_category_.json rename website/docs/{property => styles}/box_fit.md (84%) rename website/docs/{property => styles}/clip_behavior.md (78%) rename website/docs/{property => styles}/mirai_alignment_directional.md (81%) diff --git a/website/docs/styles/_category_.json b/website/docs/styles/_category_.json new file mode 100644 index 00000000..b56cf829 --- /dev/null +++ b/website/docs/styles/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Mirai Styles", + "position": 6, + "link": { + "type": "generated-index", + "description": "Learn about the various Styles provided by Mirai" + } +} \ No newline at end of file diff --git a/website/docs/property/box_fit.md b/website/docs/styles/box_fit.md similarity index 84% rename from website/docs/property/box_fit.md rename to website/docs/styles/box_fit.md index 1665bfd1..efcf671a 100644 --- a/website/docs/property/box_fit.md +++ b/website/docs/styles/box_fit.md @@ -1,4 +1,4 @@ -### BoxFit +# BoxFit The `fit` property supports the following values: @@ -12,22 +12,11 @@ The `fit` property supports the following values: | `none` | Positions the child without scaling, potentially allowing it to overflow the box. | | `scaleDown` | Scales the child down to fit within the box only if it is larger than the box. | ---- - ## Example JSON ```json { "type": "fittedBox", - "fit": "contain", - "alignment": "center", - "child": { - "type": "text", - "data": "Hello, World!", - "style": { - "fontSize": 20, - "color": "#000000" - } - } + "fit": "contain" } ``` diff --git a/website/docs/property/clip_behavior.md b/website/docs/styles/clip_behavior.md similarity index 78% rename from website/docs/property/clip_behavior.md rename to website/docs/styles/clip_behavior.md index 4ed55f8a..a34834f6 100644 --- a/website/docs/property/clip_behavior.md +++ b/website/docs/styles/clip_behavior.md @@ -1,4 +1,4 @@ -### Clip +# Clip The `clipBehavior` property determines how the content outside the box is handled: @@ -9,23 +9,11 @@ The `clipBehavior` property determines how the content outside the box is handle | `antiAlias` | Clips the content with anti-aliasing for smoother edges. | | `antiAliasWithSaveLayer` | Clips the content with anti-aliasing and saves an offscreen buffer for painting. | ---- - ## Example JSON ```json { "type": "fittedBox", - "fit": "contain", - "alignment": "center", - "clipBehavior": "hardEdge", - "child": { - "type": "text", - "data": "Hello, World!", - "style": { - "fontSize": 20, - "color": "#000000" - } - } + "clipBehavior": "hardEdge" } ``` diff --git a/website/docs/property/mirai_alignment_directional.md b/website/docs/styles/mirai_alignment_directional.md similarity index 81% rename from website/docs/property/mirai_alignment_directional.md rename to website/docs/styles/mirai_alignment_directional.md index 7f49b966..0ab45f0e 100644 --- a/website/docs/property/mirai_alignment_directional.md +++ b/website/docs/styles/mirai_alignment_directional.md @@ -1,4 +1,4 @@ -### MiraiAlignmentDirectional +# MiraiAlignmentDirectional Mirai AlignmentDirectional allows you to handling alignment widget using JSON. @@ -16,22 +16,11 @@ The `alignment` property determines where the child is positioned within the box | `bottomCenter` | Aligns the child to the bottom-center. | | `bottomEnd` | Aligns the child to the bottom-end. | ---- - ## Example JSON ```json { "type": "fittedBox", - "fit": "contain", - "alignment": "center", - "child": { - "type": "text", - "data": "Hello, World!", - "style": { - "fontSize": 20, - "color": "#000000" - } - } + "alignment": "center" } ``` From 567c2d536ca9b9c764523014db6f9fd551704d49 Mon Sep 17 00:00:00 2001 From: mabdo Date: Sun, 19 Jan 2025 14:37:21 +0400 Subject: [PATCH 21/21] remove MiraiVisibility Widget --- .../assets/json/home_screen.json | 33 -- .../assets/json/visibility_example.json | 46 --- packages/mirai/lib/src/framework/mirai.dart | 1 - .../mirai_visibility/mirai_visibility.dart | 23 -- .../mirai_visibility.freezed.dart | 346 ------------------ .../mirai_visibility/mirai_visibility.g.dart | 33 -- .../mirai_visibility_parser.dart | 31 -- packages/mirai/lib/src/parsers/parsers.dart | 1 - packages/mirai/lib/src/utils/widget_type.dart | 1 - 9 files changed, 515 deletions(-) delete mode 100644 examples/mirai_gallery/assets/json/visibility_example.json delete mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index 2b25534f..bd9d2cfe 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -1729,39 +1729,6 @@ } }, - { - "type": "listTile", - "leading": { - "type": "icon", - "iconType": "material", - "icon": "visibility" - }, - - "title": { - "type": "text", - "data": "Mirai Visibility", - "style": { - "fontSize": 21 - } - }, - "subtitle": { - "type": "text", - "data": "A Material Design Mirai Visibility widget", - "style": { - "fontSize": 12 - } - }, - "isThreeLine": true, - "onTap": { - "actionType": "navigate", - "navigationStyle": "push", - "widgetJson": { - "type": "exampleScreen", - "assetPath": "assets/json/visibility_example.json" - } - } - }, - { "type": "sizedBox", diff --git a/examples/mirai_gallery/assets/json/visibility_example.json b/examples/mirai_gallery/assets/json/visibility_example.json deleted file mode 100644 index bf02dbe9..00000000 --- a/examples/mirai_gallery/assets/json/visibility_example.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "type": "scaffold", - "appBar": { - "type": "appBar", - "title": { - "type": "text", - "data": "Visibility" - } - }, - "body": { - "type": "listView", - "shrinkWrap": true, - "children": [ - { - "type": "sizedBox", - "height": 25 - }, - { - "type": "visibility", - "child": { - "type": "text", - "data": "I am visible!" - }, - "visible": true - }, - { - "type": "sizedBox", - "height": 25 - }, - { - "type": "visibility", - "child": { - "type": "text", - "data": "I am hidden!" - }, - "replacement": { - "type": "container", - "color": "#FF5733", - "width": 50, - "height": 50 - }, - "visible": false - } - ] - } -} \ No newline at end of file diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 301d777b..98cfda8e 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -95,7 +95,6 @@ class Mirai { const MiraiAspectRatioParser(), const MiraiFittedBoxParser(), const MiraiLimitedBoxParser(), - const MiraiVisibilityParser() ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart deleted file mode 100644 index 5dd4f45b..00000000 --- a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -export 'package:mirai/src/parsers/mirai_visibility/mirai_visibility_parser.dart'; - -part 'mirai_visibility.freezed.dart'; -part 'mirai_visibility.g.dart'; - -@freezed -class MiraiVisibility with _$MiraiVisibility { - const factory MiraiVisibility({ - required Map child, - Map? replacement, - @Default(true) bool visible, - @Default(false) bool maintainState, - @Default(false) bool maintainAnimation, - @Default(false) bool maintainSize, - @Default(false) bool maintainSemantics, - @Default(false) bool maintainInteractivity, - }) = _MiraiVisibility; - - factory MiraiVisibility.fromJson(Map json) => - _$MiraiVisibilityFromJson(json); -} diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart deleted file mode 100644 index fd5d108e..00000000 --- a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.freezed.dart +++ /dev/null @@ -1,346 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'mirai_visibility.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -MiraiVisibility _$MiraiVisibilityFromJson(Map json) { - return _MiraiVisibility.fromJson(json); -} - -/// @nodoc -mixin _$MiraiVisibility { - Map get child => throw _privateConstructorUsedError; - Map? get replacement => throw _privateConstructorUsedError; - bool get visible => throw _privateConstructorUsedError; - bool get maintainState => throw _privateConstructorUsedError; - bool get maintainAnimation => throw _privateConstructorUsedError; - bool get maintainSize => throw _privateConstructorUsedError; - bool get maintainSemantics => throw _privateConstructorUsedError; - bool get maintainInteractivity => throw _privateConstructorUsedError; - - /// Serializes this MiraiVisibility to a JSON map. - Map toJson() => throw _privateConstructorUsedError; - - /// Create a copy of MiraiVisibility - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $MiraiVisibilityCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MiraiVisibilityCopyWith<$Res> { - factory $MiraiVisibilityCopyWith( - MiraiVisibility value, $Res Function(MiraiVisibility) then) = - _$MiraiVisibilityCopyWithImpl<$Res, MiraiVisibility>; - @useResult - $Res call( - {Map child, - Map? replacement, - bool visible, - bool maintainState, - bool maintainAnimation, - bool maintainSize, - bool maintainSemantics, - bool maintainInteractivity}); -} - -/// @nodoc -class _$MiraiVisibilityCopyWithImpl<$Res, $Val extends MiraiVisibility> - implements $MiraiVisibilityCopyWith<$Res> { - _$MiraiVisibilityCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of MiraiVisibility - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? child = null, - Object? replacement = freezed, - Object? visible = null, - Object? maintainState = null, - Object? maintainAnimation = null, - Object? maintainSize = null, - Object? maintainSemantics = null, - Object? maintainInteractivity = null, - }) { - return _then(_value.copyWith( - child: null == child - ? _value.child - : child // ignore: cast_nullable_to_non_nullable - as Map, - replacement: freezed == replacement - ? _value.replacement - : replacement // ignore: cast_nullable_to_non_nullable - as Map?, - visible: null == visible - ? _value.visible - : visible // ignore: cast_nullable_to_non_nullable - as bool, - maintainState: null == maintainState - ? _value.maintainState - : maintainState // ignore: cast_nullable_to_non_nullable - as bool, - maintainAnimation: null == maintainAnimation - ? _value.maintainAnimation - : maintainAnimation // ignore: cast_nullable_to_non_nullable - as bool, - maintainSize: null == maintainSize - ? _value.maintainSize - : maintainSize // ignore: cast_nullable_to_non_nullable - as bool, - maintainSemantics: null == maintainSemantics - ? _value.maintainSemantics - : maintainSemantics // ignore: cast_nullable_to_non_nullable - as bool, - maintainInteractivity: null == maintainInteractivity - ? _value.maintainInteractivity - : maintainInteractivity // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$MiraiVisibilityImplCopyWith<$Res> - implements $MiraiVisibilityCopyWith<$Res> { - factory _$$MiraiVisibilityImplCopyWith(_$MiraiVisibilityImpl value, - $Res Function(_$MiraiVisibilityImpl) then) = - __$$MiraiVisibilityImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {Map child, - Map? replacement, - bool visible, - bool maintainState, - bool maintainAnimation, - bool maintainSize, - bool maintainSemantics, - bool maintainInteractivity}); -} - -/// @nodoc -class __$$MiraiVisibilityImplCopyWithImpl<$Res> - extends _$MiraiVisibilityCopyWithImpl<$Res, _$MiraiVisibilityImpl> - implements _$$MiraiVisibilityImplCopyWith<$Res> { - __$$MiraiVisibilityImplCopyWithImpl( - _$MiraiVisibilityImpl _value, $Res Function(_$MiraiVisibilityImpl) _then) - : super(_value, _then); - - /// Create a copy of MiraiVisibility - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? child = null, - Object? replacement = freezed, - Object? visible = null, - Object? maintainState = null, - Object? maintainAnimation = null, - Object? maintainSize = null, - Object? maintainSemantics = null, - Object? maintainInteractivity = null, - }) { - return _then(_$MiraiVisibilityImpl( - child: null == child - ? _value._child - : child // ignore: cast_nullable_to_non_nullable - as Map, - replacement: freezed == replacement - ? _value._replacement - : replacement // ignore: cast_nullable_to_non_nullable - as Map?, - visible: null == visible - ? _value.visible - : visible // ignore: cast_nullable_to_non_nullable - as bool, - maintainState: null == maintainState - ? _value.maintainState - : maintainState // ignore: cast_nullable_to_non_nullable - as bool, - maintainAnimation: null == maintainAnimation - ? _value.maintainAnimation - : maintainAnimation // ignore: cast_nullable_to_non_nullable - as bool, - maintainSize: null == maintainSize - ? _value.maintainSize - : maintainSize // ignore: cast_nullable_to_non_nullable - as bool, - maintainSemantics: null == maintainSemantics - ? _value.maintainSemantics - : maintainSemantics // ignore: cast_nullable_to_non_nullable - as bool, - maintainInteractivity: null == maintainInteractivity - ? _value.maintainInteractivity - : maintainInteractivity // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$MiraiVisibilityImpl implements _MiraiVisibility { - const _$MiraiVisibilityImpl( - {required final Map child, - final Map? replacement, - this.visible = true, - this.maintainState = false, - this.maintainAnimation = false, - this.maintainSize = false, - this.maintainSemantics = false, - this.maintainInteractivity = false}) - : _child = child, - _replacement = replacement; - - factory _$MiraiVisibilityImpl.fromJson(Map json) => - _$$MiraiVisibilityImplFromJson(json); - - final Map _child; - @override - Map get child { - if (_child is EqualUnmodifiableMapView) return _child; - // ignore: implicit_dynamic_type - return EqualUnmodifiableMapView(_child); - } - - final Map? _replacement; - @override - Map? get replacement { - final value = _replacement; - if (value == null) return null; - if (_replacement is EqualUnmodifiableMapView) return _replacement; - // ignore: implicit_dynamic_type - return EqualUnmodifiableMapView(value); - } - - @override - @JsonKey() - final bool visible; - @override - @JsonKey() - final bool maintainState; - @override - @JsonKey() - final bool maintainAnimation; - @override - @JsonKey() - final bool maintainSize; - @override - @JsonKey() - final bool maintainSemantics; - @override - @JsonKey() - final bool maintainInteractivity; - - @override - String toString() { - return 'MiraiVisibility(child: $child, replacement: $replacement, visible: $visible, maintainState: $maintainState, maintainAnimation: $maintainAnimation, maintainSize: $maintainSize, maintainSemantics: $maintainSemantics, maintainInteractivity: $maintainInteractivity)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$MiraiVisibilityImpl && - const DeepCollectionEquality().equals(other._child, _child) && - const DeepCollectionEquality() - .equals(other._replacement, _replacement) && - (identical(other.visible, visible) || other.visible == visible) && - (identical(other.maintainState, maintainState) || - other.maintainState == maintainState) && - (identical(other.maintainAnimation, maintainAnimation) || - other.maintainAnimation == maintainAnimation) && - (identical(other.maintainSize, maintainSize) || - other.maintainSize == maintainSize) && - (identical(other.maintainSemantics, maintainSemantics) || - other.maintainSemantics == maintainSemantics) && - (identical(other.maintainInteractivity, maintainInteractivity) || - other.maintainInteractivity == maintainInteractivity)); - } - - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => Object.hash( - runtimeType, - const DeepCollectionEquality().hash(_child), - const DeepCollectionEquality().hash(_replacement), - visible, - maintainState, - maintainAnimation, - maintainSize, - maintainSemantics, - maintainInteractivity); - - /// Create a copy of MiraiVisibility - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$MiraiVisibilityImplCopyWith<_$MiraiVisibilityImpl> get copyWith => - __$$MiraiVisibilityImplCopyWithImpl<_$MiraiVisibilityImpl>( - this, _$identity); - - @override - Map toJson() { - return _$$MiraiVisibilityImplToJson( - this, - ); - } -} - -abstract class _MiraiVisibility implements MiraiVisibility { - const factory _MiraiVisibility( - {required final Map child, - final Map? replacement, - final bool visible, - final bool maintainState, - final bool maintainAnimation, - final bool maintainSize, - final bool maintainSemantics, - final bool maintainInteractivity}) = _$MiraiVisibilityImpl; - - factory _MiraiVisibility.fromJson(Map json) = - _$MiraiVisibilityImpl.fromJson; - - @override - Map get child; - @override - Map? get replacement; - @override - bool get visible; - @override - bool get maintainState; - @override - bool get maintainAnimation; - @override - bool get maintainSize; - @override - bool get maintainSemantics; - @override - bool get maintainInteractivity; - - /// Create a copy of MiraiVisibility - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$MiraiVisibilityImplCopyWith<_$MiraiVisibilityImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart deleted file mode 100644 index e9104b19..00000000 --- a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility.g.dart +++ /dev/null @@ -1,33 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'mirai_visibility.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$MiraiVisibilityImpl _$$MiraiVisibilityImplFromJson( - Map json) => - _$MiraiVisibilityImpl( - child: json['child'] as Map, - replacement: json['replacement'] as Map?, - visible: json['visible'] as bool? ?? true, - maintainState: json['maintainState'] as bool? ?? false, - maintainAnimation: json['maintainAnimation'] as bool? ?? false, - maintainSize: json['maintainSize'] as bool? ?? false, - maintainSemantics: json['maintainSemantics'] as bool? ?? false, - maintainInteractivity: json['maintainInteractivity'] as bool? ?? false, - ); - -Map _$$MiraiVisibilityImplToJson( - _$MiraiVisibilityImpl instance) => - { - 'child': instance.child, - 'replacement': instance.replacement, - 'visible': instance.visible, - 'maintainState': instance.maintainState, - 'maintainAnimation': instance.maintainAnimation, - 'maintainSize': instance.maintainSize, - 'maintainSemantics': instance.maintainSemantics, - 'maintainInteractivity': instance.maintainInteractivity, - }; diff --git a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart b/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart deleted file mode 100644 index c9e169f3..00000000 --- a/packages/mirai/lib/src/parsers/mirai_visibility/mirai_visibility_parser.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:mirai/src/framework/framework.dart'; -import 'package:mirai/src/parsers/mirai_visibility/mirai_visibility.dart'; -import 'package:mirai/src/utils/widget_type.dart'; -import 'package:mirai_framework/mirai_framework.dart'; - -class MiraiVisibilityParser extends MiraiParser { - const MiraiVisibilityParser(); - - @override - String get type => WidgetType.visibility.name; - - @override - MiraiVisibility getModel(Map json) => - MiraiVisibility.fromJson(json); - - @override - Widget parse(BuildContext context, MiraiVisibility model) { - return Visibility( - visible: model.visible, - maintainState: model.maintainState, - maintainAnimation: model.maintainAnimation, - maintainSize: model.maintainSize, - maintainSemantics: model.maintainSemantics, - maintainInteractivity: model.maintainInteractivity, - replacement: - Mirai.fromJson(model.replacement, context) ?? SizedBox.shrink(), - child: Mirai.fromJson(model.child, context) ?? SizedBox.shrink(), - ); - } -} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index 1d0968d2..304ab6be 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -90,4 +90,3 @@ export 'package:mirai/src/parsers/mirai_placeholder/mirai_placeholder.dart'; export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; export 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box.dart'; -export 'package:mirai/src/parsers/mirai_visibility/mirai_visibility.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index 59dc7ae9..2033b652 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -65,5 +65,4 @@ enum WidgetType { aspectRatio, fittedBox, limitedBox, - visibility, }