Skip to content

Commit

Permalink
move the default values to the MiraiPlaceholder model?
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedAbd0 committed Jan 16, 2025
1 parent 53638eb commit 82fcfe0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ part 'mirai_placeholder.g.dart';
@freezed
class MiraiPlaceholder with _$MiraiPlaceholder {
const factory MiraiPlaceholder({
double? fallbackWidth,
double? fallbackHeight,
double? strokeWidth,
String? color,
@Default(2.0) double fallbackWidth,
@Default(400.0) double fallbackHeight,
@Default(400.0) double strokeWidth,
@Default('#455A64') String color,
Map<String, dynamic>? child,
}) = _MiraiPlaceholder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ MiraiPlaceholder _$MiraiPlaceholderFromJson(Map<String, dynamic> json) {

/// @nodoc
mixin _$MiraiPlaceholder {
double? get fallbackWidth => throw _privateConstructorUsedError;
double? get fallbackHeight => throw _privateConstructorUsedError;
double? get strokeWidth => throw _privateConstructorUsedError;
String? get color => throw _privateConstructorUsedError;
double get fallbackWidth => throw _privateConstructorUsedError;
double get fallbackHeight => throw _privateConstructorUsedError;
double get strokeWidth => throw _privateConstructorUsedError;
String get color => throw _privateConstructorUsedError;
Map<String, dynamic>? get child => throw _privateConstructorUsedError;

/// Serializes this MiraiPlaceholder to a JSON map.
Expand All @@ -43,10 +43,10 @@ abstract class $MiraiPlaceholderCopyWith<$Res> {
_$MiraiPlaceholderCopyWithImpl<$Res, MiraiPlaceholder>;
@useResult
$Res call(
{double? fallbackWidth,
double? fallbackHeight,
double? strokeWidth,
String? color,
{double fallbackWidth,
double fallbackHeight,
double strokeWidth,
String color,
Map<String, dynamic>? child});
}

Expand All @@ -65,29 +65,29 @@ class _$MiraiPlaceholderCopyWithImpl<$Res, $Val extends MiraiPlaceholder>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? fallbackWidth = freezed,
Object? fallbackHeight = freezed,
Object? strokeWidth = freezed,
Object? color = freezed,
Object? fallbackWidth = null,
Object? fallbackHeight = null,
Object? strokeWidth = null,
Object? color = null,
Object? child = freezed,
}) {
return _then(_value.copyWith(
fallbackWidth: freezed == fallbackWidth
fallbackWidth: null == fallbackWidth
? _value.fallbackWidth
: fallbackWidth // ignore: cast_nullable_to_non_nullable
as double?,
fallbackHeight: freezed == fallbackHeight
as double,
fallbackHeight: null == fallbackHeight
? _value.fallbackHeight
: fallbackHeight // ignore: cast_nullable_to_non_nullable
as double?,
strokeWidth: freezed == strokeWidth
as double,
strokeWidth: null == strokeWidth
? _value.strokeWidth
: strokeWidth // ignore: cast_nullable_to_non_nullable
as double?,
color: freezed == color
as double,
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as String?,
as String,
child: freezed == child
? _value.child
: child // ignore: cast_nullable_to_non_nullable
Expand All @@ -105,10 +105,10 @@ abstract class _$$MiraiPlaceholderImplCopyWith<$Res>
@override
@useResult
$Res call(
{double? fallbackWidth,
double? fallbackHeight,
double? strokeWidth,
String? color,
{double fallbackWidth,
double fallbackHeight,
double strokeWidth,
String color,
Map<String, dynamic>? child});
}

Expand All @@ -125,29 +125,29 @@ class __$$MiraiPlaceholderImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? fallbackWidth = freezed,
Object? fallbackHeight = freezed,
Object? strokeWidth = freezed,
Object? color = freezed,
Object? fallbackWidth = null,
Object? fallbackHeight = null,
Object? strokeWidth = null,
Object? color = null,
Object? child = freezed,
}) {
return _then(_$MiraiPlaceholderImpl(
fallbackWidth: freezed == fallbackWidth
fallbackWidth: null == fallbackWidth
? _value.fallbackWidth
: fallbackWidth // ignore: cast_nullable_to_non_nullable
as double?,
fallbackHeight: freezed == fallbackHeight
as double,
fallbackHeight: null == fallbackHeight
? _value.fallbackHeight
: fallbackHeight // ignore: cast_nullable_to_non_nullable
as double?,
strokeWidth: freezed == strokeWidth
as double,
strokeWidth: null == strokeWidth
? _value.strokeWidth
: strokeWidth // ignore: cast_nullable_to_non_nullable
as double?,
color: freezed == color
as double,
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as String?,
as String,
child: freezed == child
? _value._child
: child // ignore: cast_nullable_to_non_nullable
Expand All @@ -160,24 +160,28 @@ class __$$MiraiPlaceholderImplCopyWithImpl<$Res>
@JsonSerializable()
class _$MiraiPlaceholderImpl implements _MiraiPlaceholder {
const _$MiraiPlaceholderImpl(
{this.fallbackWidth,
this.fallbackHeight,
this.strokeWidth,
this.color,
{this.fallbackWidth = 2.0,
this.fallbackHeight = 400.0,
this.strokeWidth = 400.0,
this.color = '#455A64',
final Map<String, dynamic>? child})
: _child = child;

factory _$MiraiPlaceholderImpl.fromJson(Map<String, dynamic> json) =>
_$$MiraiPlaceholderImplFromJson(json);

@override
final double? fallbackWidth;
@JsonKey()
final double fallbackWidth;
@override
final double? fallbackHeight;
@JsonKey()
final double fallbackHeight;
@override
final double? strokeWidth;
@JsonKey()
final double strokeWidth;
@override
final String? color;
@JsonKey()
final String color;
final Map<String, dynamic>? _child;
@override
Map<String, dynamic>? get child {
Expand Down Expand Up @@ -232,23 +236,23 @@ class _$MiraiPlaceholderImpl implements _MiraiPlaceholder {

abstract class _MiraiPlaceholder implements MiraiPlaceholder {
const factory _MiraiPlaceholder(
{final double? fallbackWidth,
final double? fallbackHeight,
final double? strokeWidth,
final String? color,
{final double fallbackWidth,
final double fallbackHeight,
final double strokeWidth,
final String color,
final Map<String, dynamic>? child}) = _$MiraiPlaceholderImpl;

factory _MiraiPlaceholder.fromJson(Map<String, dynamic> json) =
_$MiraiPlaceholderImpl.fromJson;

@override
double? get fallbackWidth;
double get fallbackWidth;
@override
double? get fallbackHeight;
double get fallbackHeight;
@override
double? get strokeWidth;
double get strokeWidth;
@override
String? get color;
String get color;
@override
Map<String, dynamic>? get child;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class MiraiPlaceholderParser extends MiraiParser<MiraiPlaceholder> {
@override
Widget parse(BuildContext context, MiraiPlaceholder model) {
return Placeholder(
fallbackWidth: model.fallbackWidth ?? 400.0,
fallbackHeight: model.fallbackHeight ?? 400.0,
strokeWidth: model.strokeWidth ?? 2.0,
color: model.color?.toColor(context) ?? const Color(0xFF455A64),
fallbackWidth: model.fallbackWidth,
fallbackHeight: model.fallbackHeight,
strokeWidth: model.strokeWidth,
color: model.color.toColor(context) ?? Color(0xFF455A64),
child: Mirai.fromJson(model.child, context),
);
}
Expand Down

0 comments on commit 82fcfe0

Please sign in to comment.