Skip to content

Commit

Permalink
feat: standardize parameters in buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanvaghani committed Jan 24, 2025
1 parent e41b1db commit 29868ae
Show file tree
Hide file tree
Showing 20 changed files with 574 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ part 'mirai_elevated_button.g.dart';
class MiraiElevatedButton with _$MiraiElevatedButton {
const factory MiraiElevatedButton({
Map<String, dynamic>? onPressed,
Map<String, dynamic>? onLongPress,
Map<String, dynamic>? onHover,
Map<String, dynamic>? onFocusChange,
MiraiButtonStyle? style,
@Default(false) bool autofocus,
@Default(Clip.none) Clip clipBehavior,
required Map<String, dynamic> child,
@Default(IconAlignment.start) IconAlignment iconAlignment,
}) = _MiraiElevatedButton;

factory MiraiElevatedButton.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ MiraiElevatedButton _$MiraiElevatedButtonFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$MiraiElevatedButton {
Map<String, dynamic>? get onPressed => throw _privateConstructorUsedError;
Map<String, dynamic>? get onLongPress => throw _privateConstructorUsedError;
Map<String, dynamic>? get onHover => throw _privateConstructorUsedError;
Map<String, dynamic>? get onFocusChange => throw _privateConstructorUsedError;
MiraiButtonStyle? get style => throw _privateConstructorUsedError;
bool get autofocus => throw _privateConstructorUsedError;
Clip get clipBehavior => throw _privateConstructorUsedError;
Map<String, dynamic> get child => throw _privateConstructorUsedError;
IconAlignment get iconAlignment => throw _privateConstructorUsedError;

/// Serializes this MiraiElevatedButton to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -44,10 +48,14 @@ abstract class $MiraiElevatedButtonCopyWith<$Res> {
@useResult
$Res call(
{Map<String, dynamic>? onPressed,
Map<String, dynamic>? onLongPress,
Map<String, dynamic>? onHover,
Map<String, dynamic>? onFocusChange,
MiraiButtonStyle? style,
bool autofocus,
Clip clipBehavior,
Map<String, dynamic> child});
Map<String, dynamic> child,
IconAlignment iconAlignment});

$MiraiButtonStyleCopyWith<$Res>? get style;
}
Expand All @@ -68,16 +76,32 @@ class _$MiraiElevatedButtonCopyWithImpl<$Res, $Val extends MiraiElevatedButton>
@override
$Res call({
Object? onPressed = freezed,
Object? onLongPress = freezed,
Object? onHover = freezed,
Object? onFocusChange = freezed,
Object? style = freezed,
Object? autofocus = null,
Object? clipBehavior = null,
Object? child = null,
Object? iconAlignment = null,
}) {
return _then(_value.copyWith(
onPressed: freezed == onPressed
? _value.onPressed
: onPressed // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
onLongPress: freezed == onLongPress
? _value.onLongPress
: onLongPress // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
onHover: freezed == onHover
? _value.onHover
: onHover // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
onFocusChange: freezed == onFocusChange
? _value.onFocusChange
: onFocusChange // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
style: freezed == style
? _value.style
: style // ignore: cast_nullable_to_non_nullable
Expand All @@ -94,6 +118,10 @@ class _$MiraiElevatedButtonCopyWithImpl<$Res, $Val extends MiraiElevatedButton>
? _value.child
: child // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,
iconAlignment: null == iconAlignment
? _value.iconAlignment
: iconAlignment // ignore: cast_nullable_to_non_nullable
as IconAlignment,
) as $Val);
}

Expand Down Expand Up @@ -122,10 +150,14 @@ abstract class _$$MiraiElevatedButtonImplCopyWith<$Res>
@useResult
$Res call(
{Map<String, dynamic>? onPressed,
Map<String, dynamic>? onLongPress,
Map<String, dynamic>? onHover,
Map<String, dynamic>? onFocusChange,
MiraiButtonStyle? style,
bool autofocus,
Clip clipBehavior,
Map<String, dynamic> child});
Map<String, dynamic> child,
IconAlignment iconAlignment});

@override
$MiraiButtonStyleCopyWith<$Res>? get style;
Expand All @@ -145,16 +177,32 @@ class __$$MiraiElevatedButtonImplCopyWithImpl<$Res>
@override
$Res call({
Object? onPressed = freezed,
Object? onLongPress = freezed,
Object? onHover = freezed,
Object? onFocusChange = freezed,
Object? style = freezed,
Object? autofocus = null,
Object? clipBehavior = null,
Object? child = null,
Object? iconAlignment = null,
}) {
return _then(_$MiraiElevatedButtonImpl(
onPressed: freezed == onPressed
? _value._onPressed
: onPressed // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
onLongPress: freezed == onLongPress
? _value._onLongPress
: onLongPress // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
onHover: freezed == onHover
? _value._onHover
: onHover // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
onFocusChange: freezed == onFocusChange
? _value._onFocusChange
: onFocusChange // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
style: freezed == style
? _value.style
: style // ignore: cast_nullable_to_non_nullable
Expand All @@ -171,6 +219,10 @@ class __$$MiraiElevatedButtonImplCopyWithImpl<$Res>
? _value._child
: child // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,
iconAlignment: null == iconAlignment
? _value.iconAlignment
: iconAlignment // ignore: cast_nullable_to_non_nullable
as IconAlignment,
));
}
}
Expand All @@ -180,11 +232,18 @@ class __$$MiraiElevatedButtonImplCopyWithImpl<$Res>
class _$MiraiElevatedButtonImpl implements _MiraiElevatedButton {
const _$MiraiElevatedButtonImpl(
{final Map<String, dynamic>? onPressed,
final Map<String, dynamic>? onLongPress,
final Map<String, dynamic>? onHover,
final Map<String, dynamic>? onFocusChange,
this.style,
this.autofocus = false,
this.clipBehavior = Clip.none,
required final Map<String, dynamic> child})
required final Map<String, dynamic> child,
this.iconAlignment = IconAlignment.start})
: _onPressed = onPressed,
_onLongPress = onLongPress,
_onHover = onHover,
_onFocusChange = onFocusChange,
_child = child;

factory _$MiraiElevatedButtonImpl.fromJson(Map<String, dynamic> json) =>
Expand All @@ -200,6 +259,36 @@ class _$MiraiElevatedButtonImpl implements _MiraiElevatedButton {
return EqualUnmodifiableMapView(value);
}

final Map<String, dynamic>? _onLongPress;
@override
Map<String, dynamic>? get onLongPress {
final value = _onLongPress;
if (value == null) return null;
if (_onLongPress is EqualUnmodifiableMapView) return _onLongPress;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}

final Map<String, dynamic>? _onHover;
@override
Map<String, dynamic>? get onHover {
final value = _onHover;
if (value == null) return null;
if (_onHover is EqualUnmodifiableMapView) return _onHover;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}

final Map<String, dynamic>? _onFocusChange;
@override
Map<String, dynamic>? get onFocusChange {
final value = _onFocusChange;
if (value == null) return null;
if (_onFocusChange is EqualUnmodifiableMapView) return _onFocusChange;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}

@override
final MiraiButtonStyle? style;
@override
Expand All @@ -216,9 +305,13 @@ class _$MiraiElevatedButtonImpl implements _MiraiElevatedButton {
return EqualUnmodifiableMapView(_child);
}

@override
@JsonKey()
final IconAlignment iconAlignment;

@override
String toString() {
return 'MiraiElevatedButton(onPressed: $onPressed, style: $style, autofocus: $autofocus, clipBehavior: $clipBehavior, child: $child)';
return 'MiraiElevatedButton(onPressed: $onPressed, onLongPress: $onLongPress, onHover: $onHover, onFocusChange: $onFocusChange, style: $style, autofocus: $autofocus, clipBehavior: $clipBehavior, child: $child, iconAlignment: $iconAlignment)';
}

@override
Expand All @@ -228,23 +321,34 @@ class _$MiraiElevatedButtonImpl implements _MiraiElevatedButton {
other is _$MiraiElevatedButtonImpl &&
const DeepCollectionEquality()
.equals(other._onPressed, _onPressed) &&
const DeepCollectionEquality()
.equals(other._onLongPress, _onLongPress) &&
const DeepCollectionEquality().equals(other._onHover, _onHover) &&
const DeepCollectionEquality()
.equals(other._onFocusChange, _onFocusChange) &&
(identical(other.style, style) || other.style == style) &&
(identical(other.autofocus, autofocus) ||
other.autofocus == autofocus) &&
(identical(other.clipBehavior, clipBehavior) ||
other.clipBehavior == clipBehavior) &&
const DeepCollectionEquality().equals(other._child, _child));
const DeepCollectionEquality().equals(other._child, _child) &&
(identical(other.iconAlignment, iconAlignment) ||
other.iconAlignment == iconAlignment));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_onPressed),
const DeepCollectionEquality().hash(_onLongPress),
const DeepCollectionEquality().hash(_onHover),
const DeepCollectionEquality().hash(_onFocusChange),
style,
autofocus,
clipBehavior,
const DeepCollectionEquality().hash(_child));
const DeepCollectionEquality().hash(_child),
iconAlignment);

/// Create a copy of MiraiElevatedButton
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -266,24 +370,36 @@ class _$MiraiElevatedButtonImpl implements _MiraiElevatedButton {
abstract class _MiraiElevatedButton implements MiraiElevatedButton {
const factory _MiraiElevatedButton(
{final Map<String, dynamic>? onPressed,
final Map<String, dynamic>? onLongPress,
final Map<String, dynamic>? onHover,
final Map<String, dynamic>? onFocusChange,
final MiraiButtonStyle? style,
final bool autofocus,
final Clip clipBehavior,
required final Map<String, dynamic> child}) = _$MiraiElevatedButtonImpl;
required final Map<String, dynamic> child,
final IconAlignment iconAlignment}) = _$MiraiElevatedButtonImpl;

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

@override
Map<String, dynamic>? get onPressed;
@override
Map<String, dynamic>? get onLongPress;
@override
Map<String, dynamic>? get onHover;
@override
Map<String, dynamic>? get onFocusChange;
@override
MiraiButtonStyle? get style;
@override
bool get autofocus;
@override
Clip get clipBehavior;
@override
Map<String, dynamic> get child;
@override
IconAlignment get iconAlignment;

/// Create a copy of MiraiElevatedButton
/// with the given fields replaced by the non-null parameter values.
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 @@ -20,9 +20,16 @@ class MiraiElevatedButtonParser extends MiraiParser<MiraiElevatedButton> {
onPressed: model.onPressed == null
? null
: () => Mirai.onCallFromJson(model.onPressed, context),
onLongPress: model.onLongPress == null
? null
: () => Mirai.onCallFromJson(model.onLongPress, context),
onHover: (bool value) => value == false ? null : model.onHover,
onFocusChange: (bool value) =>
value == false ? null : model.onFocusChange,
autofocus: model.autofocus,
style: model.style?.parseElevated(context),
clipBehavior: model.clipBehavior,
iconAlignment: model.iconAlignment,
child: Mirai.fromJson(model.child, context),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MiraiFilledButton with _$MiraiFilledButton {
@Default(false) bool autofocus,
@Default(Clip.none) Clip clipBehavior,
Map<String, dynamic>? child,
@Default(IconAlignment.start) IconAlignment iconAlignment,
}) = _MiraiFilledButton;

factory MiraiFilledButton.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit 29868ae

Please sign in to comment.