From 7cdf0b369d8852fdc42f826e0ca22adc889fdaf4 Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Tue, 20 Feb 2024 15:08:58 +0400 Subject: [PATCH 1/4] Add circle avatar parser --- examples/mirai_gallery/devtools_options.yaml | 1 + .../app/example/example_screen.freezed.dart | 46 +-- .../lib/app/example/example_screen.g.dart | 6 +- .../mirai_circle_avatar.dart | 23 ++ .../mirai_circle_avatar.freezed.dart | 386 ++++++++++++++++++ .../mirai_circle_avatar.g.dart | 39 ++ .../mirai_circle_avatar_parser.dart | 29 ++ packages/mirai/lib/src/utils/widget_type.dart | 1 + 8 files changed, 505 insertions(+), 26 deletions(-) create mode 100644 examples/mirai_gallery/devtools_options.yaml create mode 100644 packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.freezed.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.g.dart create mode 100644 packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart diff --git a/examples/mirai_gallery/devtools_options.yaml b/examples/mirai_gallery/devtools_options.yaml new file mode 100644 index 00000000..7e7e7f67 --- /dev/null +++ b/examples/mirai_gallery/devtools_options.yaml @@ -0,0 +1 @@ +extensions: diff --git a/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart b/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart index 7a3de3b6..ff4cc94d 100644 --- a/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart +++ b/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart @@ -12,7 +12,7 @@ part of 'example_screen.dart'; 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#custom-getters-and-methods'); + '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'); ExampleScreen _$ExampleScreenFromJson(Map json) { return _ExampleScreen.fromJson(json); @@ -62,22 +62,22 @@ class _$ExampleScreenCopyWithImpl<$Res, $Val extends ExampleScreen> } /// @nodoc -abstract class _$$_ExampleScreenCopyWith<$Res> +abstract class _$$ExampleScreenImplCopyWith<$Res> implements $ExampleScreenCopyWith<$Res> { - factory _$$_ExampleScreenCopyWith( - _$_ExampleScreen value, $Res Function(_$_ExampleScreen) then) = - __$$_ExampleScreenCopyWithImpl<$Res>; + factory _$$ExampleScreenImplCopyWith( + _$ExampleScreenImpl value, $Res Function(_$ExampleScreenImpl) then) = + __$$ExampleScreenImplCopyWithImpl<$Res>; @override @useResult $Res call({String assetPath}); } /// @nodoc -class __$$_ExampleScreenCopyWithImpl<$Res> - extends _$ExampleScreenCopyWithImpl<$Res, _$_ExampleScreen> - implements _$$_ExampleScreenCopyWith<$Res> { - __$$_ExampleScreenCopyWithImpl( - _$_ExampleScreen _value, $Res Function(_$_ExampleScreen) _then) +class __$$ExampleScreenImplCopyWithImpl<$Res> + extends _$ExampleScreenCopyWithImpl<$Res, _$ExampleScreenImpl> + implements _$$ExampleScreenImplCopyWith<$Res> { + __$$ExampleScreenImplCopyWithImpl( + _$ExampleScreenImpl _value, $Res Function(_$ExampleScreenImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -85,7 +85,7 @@ class __$$_ExampleScreenCopyWithImpl<$Res> $Res call({ Object? assetPath = null, }) { - return _then(_$_ExampleScreen( + return _then(_$ExampleScreenImpl( assetPath: null == assetPath ? _value.assetPath : assetPath // ignore: cast_nullable_to_non_nullable @@ -96,11 +96,11 @@ class __$$_ExampleScreenCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$_ExampleScreen implements _ExampleScreen { - const _$_ExampleScreen({required this.assetPath}); +class _$ExampleScreenImpl implements _ExampleScreen { + const _$ExampleScreenImpl({required this.assetPath}); - factory _$_ExampleScreen.fromJson(Map json) => - _$$_ExampleScreenFromJson(json); + factory _$ExampleScreenImpl.fromJson(Map json) => + _$$ExampleScreenImplFromJson(json); @override final String assetPath; @@ -111,10 +111,10 @@ class _$_ExampleScreen implements _ExampleScreen { } @override - bool operator ==(dynamic other) { + bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$_ExampleScreen && + other is _$ExampleScreenImpl && (identical(other.assetPath, assetPath) || other.assetPath == assetPath)); } @@ -126,12 +126,12 @@ class _$_ExampleScreen implements _ExampleScreen { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$_ExampleScreenCopyWith<_$_ExampleScreen> get copyWith => - __$$_ExampleScreenCopyWithImpl<_$_ExampleScreen>(this, _$identity); + _$$ExampleScreenImplCopyWith<_$ExampleScreenImpl> get copyWith => + __$$ExampleScreenImplCopyWithImpl<_$ExampleScreenImpl>(this, _$identity); @override Map toJson() { - return _$$_ExampleScreenToJson( + return _$$ExampleScreenImplToJson( this, ); } @@ -139,15 +139,15 @@ class _$_ExampleScreen implements _ExampleScreen { abstract class _ExampleScreen implements ExampleScreen { const factory _ExampleScreen({required final String assetPath}) = - _$_ExampleScreen; + _$ExampleScreenImpl; factory _ExampleScreen.fromJson(Map json) = - _$_ExampleScreen.fromJson; + _$ExampleScreenImpl.fromJson; @override String get assetPath; @override @JsonKey(ignore: true) - _$$_ExampleScreenCopyWith<_$_ExampleScreen> get copyWith => + _$$ExampleScreenImplCopyWith<_$ExampleScreenImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/examples/mirai_gallery/lib/app/example/example_screen.g.dart b/examples/mirai_gallery/lib/app/example/example_screen.g.dart index e05d6bc5..49fa1de9 100644 --- a/examples/mirai_gallery/lib/app/example/example_screen.g.dart +++ b/examples/mirai_gallery/lib/app/example/example_screen.g.dart @@ -6,12 +6,12 @@ part of 'example_screen.dart'; // JsonSerializableGenerator // ************************************************************************** -_$_ExampleScreen _$$_ExampleScreenFromJson(Map json) => - _$_ExampleScreen( +_$ExampleScreenImpl _$$ExampleScreenImplFromJson(Map json) => + _$ExampleScreenImpl( assetPath: json['assetPath'] as String, ); -Map _$$_ExampleScreenToJson(_$_ExampleScreen instance) => +Map _$$ExampleScreenImplToJson(_$ExampleScreenImpl instance) => { 'assetPath': instance.assetPath, }; diff --git a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart new file mode 100644 index 00000000..2720745f --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart @@ -0,0 +1,23 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'mirai_circle_avatar.freezed.dart'; +part 'mirai_circle_avatar.g.dart'; + +@freezed +class MiraiCircleAvatar with _$MiraiCircleAvatar { + const factory MiraiCircleAvatar({ + Map? child, + String? backgroundColor, + String? backgroundImage, + String? foregroundImage, + Map? onBackgroundImageError, + Map? onForegroundImageError, + String? foregroundColor, + double? radius, + double? minRadius, + double? maxRadius, + }) = _MiraiCircleAvatar; + + factory MiraiCircleAvatar.fromJson(Map json) => + _$MiraiCircleAvatarFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.freezed.dart b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.freezed.dart new file mode 100644 index 00000000..98bc48a5 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.freezed.dart @@ -0,0 +1,386 @@ +// 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_circle_avatar.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'); + +MiraiCircleAvatar _$MiraiCircleAvatarFromJson(Map json) { + return _MiraiCircleAvatar.fromJson(json); +} + +/// @nodoc +mixin _$MiraiCircleAvatar { + Map? get child => throw _privateConstructorUsedError; + String? get backgroundColor => throw _privateConstructorUsedError; + String? get backgroundImage => throw _privateConstructorUsedError; + String? get foregroundImage => throw _privateConstructorUsedError; + Map? get onBackgroundImageError => + throw _privateConstructorUsedError; + Map? get onForegroundImageError => + throw _privateConstructorUsedError; + String? get foregroundColor => throw _privateConstructorUsedError; + double? get radius => throw _privateConstructorUsedError; + double? get minRadius => throw _privateConstructorUsedError; + double? get maxRadius => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MiraiCircleAvatarCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiCircleAvatarCopyWith<$Res> { + factory $MiraiCircleAvatarCopyWith( + MiraiCircleAvatar value, $Res Function(MiraiCircleAvatar) then) = + _$MiraiCircleAvatarCopyWithImpl<$Res, MiraiCircleAvatar>; + @useResult + $Res call( + {Map? child, + String? backgroundColor, + String? backgroundImage, + String? foregroundImage, + Map? onBackgroundImageError, + Map? onForegroundImageError, + String? foregroundColor, + double? radius, + double? minRadius, + double? maxRadius}); +} + +/// @nodoc +class _$MiraiCircleAvatarCopyWithImpl<$Res, $Val extends MiraiCircleAvatar> + implements $MiraiCircleAvatarCopyWith<$Res> { + _$MiraiCircleAvatarCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? child = freezed, + Object? backgroundColor = freezed, + Object? backgroundImage = freezed, + Object? foregroundImage = freezed, + Object? onBackgroundImageError = freezed, + Object? onForegroundImageError = freezed, + Object? foregroundColor = freezed, + Object? radius = freezed, + Object? minRadius = freezed, + Object? maxRadius = freezed, + }) { + return _then(_value.copyWith( + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + backgroundColor: freezed == backgroundColor + ? _value.backgroundColor + : backgroundColor // ignore: cast_nullable_to_non_nullable + as String?, + backgroundImage: freezed == backgroundImage + ? _value.backgroundImage + : backgroundImage // ignore: cast_nullable_to_non_nullable + as String?, + foregroundImage: freezed == foregroundImage + ? _value.foregroundImage + : foregroundImage // ignore: cast_nullable_to_non_nullable + as String?, + onBackgroundImageError: freezed == onBackgroundImageError + ? _value.onBackgroundImageError + : onBackgroundImageError // ignore: cast_nullable_to_non_nullable + as Map?, + onForegroundImageError: freezed == onForegroundImageError + ? _value.onForegroundImageError + : onForegroundImageError // ignore: cast_nullable_to_non_nullable + as Map?, + foregroundColor: freezed == foregroundColor + ? _value.foregroundColor + : foregroundColor // ignore: cast_nullable_to_non_nullable + as String?, + radius: freezed == radius + ? _value.radius + : radius // ignore: cast_nullable_to_non_nullable + as double?, + minRadius: freezed == minRadius + ? _value.minRadius + : minRadius // ignore: cast_nullable_to_non_nullable + as double?, + maxRadius: freezed == maxRadius + ? _value.maxRadius + : maxRadius // ignore: cast_nullable_to_non_nullable + as double?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiCircleAvatarImplCopyWith<$Res> + implements $MiraiCircleAvatarCopyWith<$Res> { + factory _$$MiraiCircleAvatarImplCopyWith(_$MiraiCircleAvatarImpl value, + $Res Function(_$MiraiCircleAvatarImpl) then) = + __$$MiraiCircleAvatarImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {Map? child, + String? backgroundColor, + String? backgroundImage, + String? foregroundImage, + Map? onBackgroundImageError, + Map? onForegroundImageError, + String? foregroundColor, + double? radius, + double? minRadius, + double? maxRadius}); +} + +/// @nodoc +class __$$MiraiCircleAvatarImplCopyWithImpl<$Res> + extends _$MiraiCircleAvatarCopyWithImpl<$Res, _$MiraiCircleAvatarImpl> + implements _$$MiraiCircleAvatarImplCopyWith<$Res> { + __$$MiraiCircleAvatarImplCopyWithImpl(_$MiraiCircleAvatarImpl _value, + $Res Function(_$MiraiCircleAvatarImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? child = freezed, + Object? backgroundColor = freezed, + Object? backgroundImage = freezed, + Object? foregroundImage = freezed, + Object? onBackgroundImageError = freezed, + Object? onForegroundImageError = freezed, + Object? foregroundColor = freezed, + Object? radius = freezed, + Object? minRadius = freezed, + Object? maxRadius = freezed, + }) { + return _then(_$MiraiCircleAvatarImpl( + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + backgroundColor: freezed == backgroundColor + ? _value.backgroundColor + : backgroundColor // ignore: cast_nullable_to_non_nullable + as String?, + backgroundImage: freezed == backgroundImage + ? _value.backgroundImage + : backgroundImage // ignore: cast_nullable_to_non_nullable + as String?, + foregroundImage: freezed == foregroundImage + ? _value.foregroundImage + : foregroundImage // ignore: cast_nullable_to_non_nullable + as String?, + onBackgroundImageError: freezed == onBackgroundImageError + ? _value._onBackgroundImageError + : onBackgroundImageError // ignore: cast_nullable_to_non_nullable + as Map?, + onForegroundImageError: freezed == onForegroundImageError + ? _value._onForegroundImageError + : onForegroundImageError // ignore: cast_nullable_to_non_nullable + as Map?, + foregroundColor: freezed == foregroundColor + ? _value.foregroundColor + : foregroundColor // ignore: cast_nullable_to_non_nullable + as String?, + radius: freezed == radius + ? _value.radius + : radius // ignore: cast_nullable_to_non_nullable + as double?, + minRadius: freezed == minRadius + ? _value.minRadius + : minRadius // ignore: cast_nullable_to_non_nullable + as double?, + maxRadius: freezed == maxRadius + ? _value.maxRadius + : maxRadius // ignore: cast_nullable_to_non_nullable + as double?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiCircleAvatarImpl implements _MiraiCircleAvatar { + const _$MiraiCircleAvatarImpl( + {final Map? child, + this.backgroundColor, + this.backgroundImage, + this.foregroundImage, + final Map? onBackgroundImageError, + final Map? onForegroundImageError, + this.foregroundColor, + this.radius, + this.minRadius, + this.maxRadius}) + : _child = child, + _onBackgroundImageError = onBackgroundImageError, + _onForegroundImageError = onForegroundImageError; + + factory _$MiraiCircleAvatarImpl.fromJson(Map json) => + _$$MiraiCircleAvatarImplFromJson(json); + + 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 + final String? backgroundColor; + @override + final String? backgroundImage; + @override + final String? foregroundImage; + final Map? _onBackgroundImageError; + @override + Map? get onBackgroundImageError { + final value = _onBackgroundImageError; + if (value == null) return null; + if (_onBackgroundImageError is EqualUnmodifiableMapView) + return _onBackgroundImageError; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + final Map? _onForegroundImageError; + @override + Map? get onForegroundImageError { + final value = _onForegroundImageError; + if (value == null) return null; + if (_onForegroundImageError is EqualUnmodifiableMapView) + return _onForegroundImageError; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + final String? foregroundColor; + @override + final double? radius; + @override + final double? minRadius; + @override + final double? maxRadius; + + @override + String toString() { + return 'MiraiCircleAvatar(child: $child, backgroundColor: $backgroundColor, backgroundImage: $backgroundImage, foregroundImage: $foregroundImage, onBackgroundImageError: $onBackgroundImageError, onForegroundImageError: $onForegroundImageError, foregroundColor: $foregroundColor, radius: $radius, minRadius: $minRadius, maxRadius: $maxRadius)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiCircleAvatarImpl && + const DeepCollectionEquality().equals(other._child, _child) && + (identical(other.backgroundColor, backgroundColor) || + other.backgroundColor == backgroundColor) && + (identical(other.backgroundImage, backgroundImage) || + other.backgroundImage == backgroundImage) && + (identical(other.foregroundImage, foregroundImage) || + other.foregroundImage == foregroundImage) && + const DeepCollectionEquality().equals( + other._onBackgroundImageError, _onBackgroundImageError) && + const DeepCollectionEquality().equals( + other._onForegroundImageError, _onForegroundImageError) && + (identical(other.foregroundColor, foregroundColor) || + other.foregroundColor == foregroundColor) && + (identical(other.radius, radius) || other.radius == radius) && + (identical(other.minRadius, minRadius) || + other.minRadius == minRadius) && + (identical(other.maxRadius, maxRadius) || + other.maxRadius == maxRadius)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, + const DeepCollectionEquality().hash(_child), + backgroundColor, + backgroundImage, + foregroundImage, + const DeepCollectionEquality().hash(_onBackgroundImageError), + const DeepCollectionEquality().hash(_onForegroundImageError), + foregroundColor, + radius, + minRadius, + maxRadius); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$MiraiCircleAvatarImplCopyWith<_$MiraiCircleAvatarImpl> get copyWith => + __$$MiraiCircleAvatarImplCopyWithImpl<_$MiraiCircleAvatarImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiCircleAvatarImplToJson( + this, + ); + } +} + +abstract class _MiraiCircleAvatar implements MiraiCircleAvatar { + const factory _MiraiCircleAvatar( + {final Map? child, + final String? backgroundColor, + final String? backgroundImage, + final String? foregroundImage, + final Map? onBackgroundImageError, + final Map? onForegroundImageError, + final String? foregroundColor, + final double? radius, + final double? minRadius, + final double? maxRadius}) = _$MiraiCircleAvatarImpl; + + factory _MiraiCircleAvatar.fromJson(Map json) = + _$MiraiCircleAvatarImpl.fromJson; + + @override + Map? get child; + @override + String? get backgroundColor; + @override + String? get backgroundImage; + @override + String? get foregroundImage; + @override + Map? get onBackgroundImageError; + @override + Map? get onForegroundImageError; + @override + String? get foregroundColor; + @override + double? get radius; + @override + double? get minRadius; + @override + double? get maxRadius; + @override + @JsonKey(ignore: true) + _$$MiraiCircleAvatarImplCopyWith<_$MiraiCircleAvatarImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.g.dart b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.g.dart new file mode 100644 index 00000000..1ff1f23d --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.g.dart @@ -0,0 +1,39 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_circle_avatar.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiCircleAvatarImpl _$$MiraiCircleAvatarImplFromJson( + Map json) => + _$MiraiCircleAvatarImpl( + child: json['child'] as Map?, + backgroundColor: json['backgroundColor'] as String?, + backgroundImage: json['backgroundImage'] as String?, + foregroundImage: json['foregroundImage'] as String?, + onBackgroundImageError: + json['onBackgroundImageError'] as Map?, + onForegroundImageError: + json['onForegroundImageError'] as Map?, + foregroundColor: json['foregroundColor'] as String?, + radius: (json['radius'] as num?)?.toDouble(), + minRadius: (json['minRadius'] as num?)?.toDouble(), + maxRadius: (json['maxRadius'] as num?)?.toDouble(), + ); + +Map _$$MiraiCircleAvatarImplToJson( + _$MiraiCircleAvatarImpl instance) => + { + 'child': instance.child, + 'backgroundColor': instance.backgroundColor, + 'backgroundImage': instance.backgroundImage, + 'foregroundImage': instance.foregroundImage, + 'onBackgroundImageError': instance.onBackgroundImageError, + 'onForegroundImageError': instance.onForegroundImageError, + 'foregroundColor': instance.foregroundColor, + 'radius': instance.radius, + 'minRadius': instance.minRadius, + 'maxRadius': instance.maxRadius, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart new file mode 100644 index 00000000..33c76012 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/mirai.dart'; +import 'package:mirai/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart'; +import 'package:mirai/src/utils/widget_type.dart'; + +class MiraiCircleAvatarParser extends MiraiParser { + const MiraiCircleAvatarParser(); + + @override + String get type => WidgetType.circleAvatar.name; + + @override + MiraiCircleAvatar getModel(Map json) => + MiraiCircleAvatar.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiCircleAvatar model) { + return CircleAvatar( + backgroundColor: model.backgroundColor.toColor(context), + backgroundImage: NetworkImage(model.backgroundImage ?? ''), + foregroundImage: NetworkImage(model.foregroundImage ?? ''), + foregroundColor: model.foregroundColor.toColor(context), + radius: model.radius, + minRadius: model.minRadius, + maxRadius: model.maxRadius, + child: Mirai.fromJson(model.child, context), + ); + } +} diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index e28b3f50..614d4bfc 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -41,4 +41,5 @@ enum WidgetType { pageView, refreshIndicator, networkWidget, + circleAvatar, } From eb70d05dc1e2aacf30a411ea9c0812f9caf86fae Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Tue, 20 Feb 2024 15:21:57 +0400 Subject: [PATCH 2/4] Enable network access in MacOS --- examples/mirai_gallery/macos/Runner/DebugProfile.entitlements | 2 ++ examples/mirai_gallery/macos/Runner/Release.entitlements | 2 ++ 2 files changed, 4 insertions(+) diff --git a/examples/mirai_gallery/macos/Runner/DebugProfile.entitlements b/examples/mirai_gallery/macos/Runner/DebugProfile.entitlements index dddb8a30..c946719a 100644 --- a/examples/mirai_gallery/macos/Runner/DebugProfile.entitlements +++ b/examples/mirai_gallery/macos/Runner/DebugProfile.entitlements @@ -8,5 +8,7 @@ com.apple.security.network.server + com.apple.security.network.client + diff --git a/examples/mirai_gallery/macos/Runner/Release.entitlements b/examples/mirai_gallery/macos/Runner/Release.entitlements index 852fa1a4..48271acc 100644 --- a/examples/mirai_gallery/macos/Runner/Release.entitlements +++ b/examples/mirai_gallery/macos/Runner/Release.entitlements @@ -4,5 +4,7 @@ com.apple.security.app-sandbox + com.apple.security.network.client + From 59cf583af013b5f38e65c434675fd288e7e92e57 Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Tue, 20 Feb 2024 15:22:28 +0400 Subject: [PATCH 3/4] Add null check for backgroundImage & foregroundImage --- .../mirai_circle_avatar/mirai_circle_avatar_parser.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart index 33c76012..b47ad286 100644 --- a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar_parser.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:mirai/mirai.dart'; -import 'package:mirai/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart'; import 'package:mirai/src/utils/widget_type.dart'; class MiraiCircleAvatarParser extends MiraiParser { @@ -17,8 +16,12 @@ class MiraiCircleAvatarParser extends MiraiParser { Widget parse(BuildContext context, MiraiCircleAvatar model) { return CircleAvatar( backgroundColor: model.backgroundColor.toColor(context), - backgroundImage: NetworkImage(model.backgroundImage ?? ''), - foregroundImage: NetworkImage(model.foregroundImage ?? ''), + backgroundImage: model.backgroundImage != null + ? NetworkImage(model.backgroundImage!) + : null, + foregroundImage: model.foregroundImage != null + ? NetworkImage(model.foregroundImage!) + : null, foregroundColor: model.foregroundColor.toColor(context), radius: model.radius, minRadius: model.minRadius, From d9f2d7937d03ec237b327a3d2a277e073994e141 Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Tue, 20 Feb 2024 15:22:43 +0400 Subject: [PATCH 4/4] Expor the parser --- packages/mirai/lib/src/framework/mirai.dart | 1 + .../src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart | 2 ++ packages/mirai/lib/src/parsers/parsers.dart | 1 + 3 files changed, 4 insertions(+) diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index e066beff..723b05d3 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -63,6 +63,7 @@ class Mirai { const MiraiPageViewParser(), const MiraiRefreshIndicatorParser(), const MiraiNetworkWidgetParser(), + const MiraiCircleAvatarParser(), ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart index 2720745f..346a2cf2 100644 --- a/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart +++ b/packages/mirai/lib/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart @@ -1,5 +1,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; +export 'mirai_circle_avatar_parser.dart'; + part 'mirai_circle_avatar.freezed.dart'; part 'mirai_circle_avatar.g.dart'; diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index 6b55a48b..8c482a57 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -19,6 +19,7 @@ export 'package:mirai/src/parsers/mirai_card/mirai_card.dart'; export 'package:mirai/src/parsers/mirai_card_theme_data/mirai_card_theme_data.dart'; export 'package:mirai/src/parsers/mirai_center/mirai_center.dart'; export 'package:mirai/src/parsers/mirai_check_box_widget/mirai_check_box_widget.dart'; +export 'package:mirai/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart'; export 'package:mirai/src/parsers/mirai_column/mirai_column.dart'; export 'package:mirai/src/parsers/mirai_container/mirai_container.dart'; export 'package:mirai/src/parsers/mirai_container_image/mirai_container_image.dart';