Skip to content

Commit

Permalink
Merge pull request #8 from BuildMirai/dv/colored-box
Browse files Browse the repository at this point in the history
feat: Add Mirai colored box parser
  • Loading branch information
divyanshub024 authored Dec 25, 2024
2 parents 9ccc88d + 04d160d commit 9fc5a30
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/mirai/lib/src/framework/mirai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Mirai {
const MiraiTableParser(),
const MiraiTableCellParser(),
const MiraiCarouselViewParser(),
const MiraiColoredBoxParser(),
];

static final _actionParsers = <MiraiActionParser>[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:freezed_annotation/freezed_annotation.dart';

export 'mirai_colored_box_parser.dart';

part 'mirai_colored_box.freezed.dart';
part 'mirai_colored_box.g.dart';

@freezed
class MiraiColoredBox with _$MiraiColoredBox {
const factory MiraiColoredBox({
required String color,
Map<String, dynamic>? child,
}) = _MiraiColoredBox;

factory MiraiColoredBox.fromJson(Map<String, dynamic> json) =>
_$MiraiColoredBoxFromJson(json);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// 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_colored_box.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(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');

MiraiColoredBox _$MiraiColoredBoxFromJson(Map<String, dynamic> json) {
return _MiraiColoredBox.fromJson(json);
}

/// @nodoc
mixin _$MiraiColoredBox {
String get color => throw _privateConstructorUsedError;
Map<String, dynamic>? get child => throw _privateConstructorUsedError;

/// Serializes this MiraiColoredBox to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;

/// Create a copy of MiraiColoredBox
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$MiraiColoredBoxCopyWith<MiraiColoredBox> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $MiraiColoredBoxCopyWith<$Res> {
factory $MiraiColoredBoxCopyWith(
MiraiColoredBox value, $Res Function(MiraiColoredBox) then) =
_$MiraiColoredBoxCopyWithImpl<$Res, MiraiColoredBox>;
@useResult
$Res call({String color, Map<String, dynamic>? child});
}

/// @nodoc
class _$MiraiColoredBoxCopyWithImpl<$Res, $Val extends MiraiColoredBox>
implements $MiraiColoredBoxCopyWith<$Res> {
_$MiraiColoredBoxCopyWithImpl(this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

/// Create a copy of MiraiColoredBox
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? color = null,
Object? child = freezed,
}) {
return _then(_value.copyWith(
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as String,
child: freezed == child
? _value.child
: child // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
) as $Val);
}
}

/// @nodoc
abstract class _$$MiraiColoredBoxImplCopyWith<$Res>
implements $MiraiColoredBoxCopyWith<$Res> {
factory _$$MiraiColoredBoxImplCopyWith(_$MiraiColoredBoxImpl value,
$Res Function(_$MiraiColoredBoxImpl) then) =
__$$MiraiColoredBoxImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String color, Map<String, dynamic>? child});
}

/// @nodoc
class __$$MiraiColoredBoxImplCopyWithImpl<$Res>
extends _$MiraiColoredBoxCopyWithImpl<$Res, _$MiraiColoredBoxImpl>
implements _$$MiraiColoredBoxImplCopyWith<$Res> {
__$$MiraiColoredBoxImplCopyWithImpl(
_$MiraiColoredBoxImpl _value, $Res Function(_$MiraiColoredBoxImpl) _then)
: super(_value, _then);

/// Create a copy of MiraiColoredBox
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? color = null,
Object? child = freezed,
}) {
return _then(_$MiraiColoredBoxImpl(
color: null == color
? _value.color
: color // ignore: cast_nullable_to_non_nullable
as String,
child: freezed == child
? _value._child
: child // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
));
}
}

/// @nodoc
@JsonSerializable()
class _$MiraiColoredBoxImpl implements _MiraiColoredBox {
const _$MiraiColoredBoxImpl(
{required this.color, final Map<String, dynamic>? child})
: _child = child;

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

@override
final String color;
final Map<String, dynamic>? _child;
@override
Map<String, dynamic>? 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 'MiraiColoredBox(color: $color, child: $child)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$MiraiColoredBoxImpl &&
(identical(other.color, color) || other.color == color) &&
const DeepCollectionEquality().equals(other._child, _child));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType, color, const DeepCollectionEquality().hash(_child));

/// Create a copy of MiraiColoredBox
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$MiraiColoredBoxImplCopyWith<_$MiraiColoredBoxImpl> get copyWith =>
__$$MiraiColoredBoxImplCopyWithImpl<_$MiraiColoredBoxImpl>(
this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$MiraiColoredBoxImplToJson(
this,
);
}
}

abstract class _MiraiColoredBox implements MiraiColoredBox {
const factory _MiraiColoredBox(
{required final String color,
final Map<String, dynamic>? child}) = _$MiraiColoredBoxImpl;

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

@override
String get color;
@override
Map<String, dynamic>? get child;

/// Create a copy of MiraiColoredBox
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$MiraiColoredBoxImplCopyWith<_$MiraiColoredBoxImpl> get copyWith =>
throw _privateConstructorUsedError;
}

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
@@ -0,0 +1,23 @@
import 'package:flutter/cupertino.dart';
import 'package:mirai/mirai.dart';
import 'package:mirai/src/parsers/mirai_colored_box/mirai_colored_box.dart';
import 'package:mirai/src/utils/widget_type.dart';

class MiraiColoredBoxParser extends MiraiParser<MiraiColoredBox> {
const MiraiColoredBoxParser();

@override
String get type => WidgetType.coloredBox.name;

@override
MiraiColoredBox getModel(Map<String, dynamic> json) =>
MiraiColoredBox.fromJson(json);

@override
Widget parse(BuildContext context, MiraiColoredBox model) {
return ColoredBox(
color: model.color.toColor(context)!,
child: Mirai.fromJson(model.child, context),
);
}
}
1 change: 1 addition & 0 deletions packages/mirai/lib/src/parsers/parsers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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_chip/mirai_chip.dart';
export 'package:mirai/src/parsers/mirai_circle_avatar/mirai_circle_avatar.dart';
export 'package:mirai/src/parsers/mirai_colored_box/mirai_colored_box.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_default_bottom_navigation_controller/mirai_default_bottom_navigation_controller.dart';
Expand Down
1 change: 1 addition & 0 deletions packages/mirai/lib/src/utils/widget_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ enum WidgetType {
table,
tableCell,
carouselView,
coloredBox,
}

0 comments on commit 9fc5a30

Please sign in to comment.