diff --git a/examples/mirai_gallery/assets/json/divider_example.json b/examples/mirai_gallery/assets/json/divider_example.json new file mode 100644 index 00000000..26f20a94 --- /dev/null +++ b/examples/mirai_gallery/assets/json/divider_example.json @@ -0,0 +1,39 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "Divider" + } + }, + "body": { + "type": "listView", + "children": [{ + "type": "divider", + "thickness": 5, + "height": 5, + "color": "#672BFF" + }, + { + "type": "sizedBox", + "height": 20 + }, + { + "type": "divider", + "thickness": 3, + "height": 3, + "color": "#FC5632" + }, + { + "type": "sizedBox", + "height": 20 + }, + { + "type": "divider", + "thickness": 2, + "height": 2, + "color": "#32FC88" + }] + } +} \ 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 f2250a64..8b2b65b1 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -1319,6 +1319,40 @@ } } }, + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "star" + }, + "title": { + "type": "text", + "data": "Mirai Divider", + "align": "center", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Divider widget", + "align": "center", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": false, + "style": "list", + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/divider_example.json" + } + } + }, { "type": "sizedBox", "height": 24.0 diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index eecc963c..403acd7e 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -7,6 +7,7 @@ import 'package:flutter/services.dart'; import 'package:mirai/src/action_parsers/action_parsers.dart'; import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart'; import 'package:mirai/src/framework/mirai_registry.dart'; +import 'package:mirai/src/parsers/mirai_divider/mirai_divider_parser.dart'; import 'package:mirai/src/parsers/parsers.dart'; import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/log.dart'; @@ -82,6 +83,7 @@ class Mirai { const MiraiTableCellParser(), const MiraiCarouselViewParser(), const MiraiColoredBoxParser(), + const MiraiDividerParser() ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.dart b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.dart new file mode 100644 index 00000000..58831f37 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.dart @@ -0,0 +1,16 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'mirai_divider.freezed.dart'; // Auto-generated Freezed file +part 'mirai_divider.g.dart'; // Auto-generated JSON serialization file + +@freezed +class MiraiDivider with _$MiraiDivider { + const factory MiraiDivider({ + double? thickness, + double? height, + String? color, + }) = _MiraiDivider; + + factory MiraiDivider.fromJson(Map json) => + _$MiraiDividerFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.freezed.dart b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.freezed.dart new file mode 100644 index 00000000..a098e2ee --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.freezed.dart @@ -0,0 +1,200 @@ +// 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_divider.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'); + +MiraiDivider _$MiraiDividerFromJson(Map json) { + return _MiraiDivider.fromJson(json); +} + +/// @nodoc +mixin _$MiraiDivider { + double? get thickness => throw _privateConstructorUsedError; + double? get height => throw _privateConstructorUsedError; + String? get color => throw _privateConstructorUsedError; + + /// Serializes this MiraiDivider to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiDivider + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiDividerCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiDividerCopyWith<$Res> { + factory $MiraiDividerCopyWith( + MiraiDivider value, $Res Function(MiraiDivider) then) = + _$MiraiDividerCopyWithImpl<$Res, MiraiDivider>; + @useResult + $Res call({double? thickness, double? height, String? color}); +} + +/// @nodoc +class _$MiraiDividerCopyWithImpl<$Res, $Val extends MiraiDivider> + implements $MiraiDividerCopyWith<$Res> { + _$MiraiDividerCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiDivider + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? thickness = freezed, + Object? height = freezed, + Object? color = freezed, + }) { + return _then(_value.copyWith( + thickness: freezed == thickness + ? _value.thickness + : thickness // ignore: cast_nullable_to_non_nullable + as double?, + height: freezed == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as double?, + color: freezed == color + ? _value.color + : color // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiDividerImplCopyWith<$Res> + implements $MiraiDividerCopyWith<$Res> { + factory _$$MiraiDividerImplCopyWith( + _$MiraiDividerImpl value, $Res Function(_$MiraiDividerImpl) then) = + __$$MiraiDividerImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double? thickness, double? height, String? color}); +} + +/// @nodoc +class __$$MiraiDividerImplCopyWithImpl<$Res> + extends _$MiraiDividerCopyWithImpl<$Res, _$MiraiDividerImpl> + implements _$$MiraiDividerImplCopyWith<$Res> { + __$$MiraiDividerImplCopyWithImpl( + _$MiraiDividerImpl _value, $Res Function(_$MiraiDividerImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiDivider + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? thickness = freezed, + Object? height = freezed, + Object? color = freezed, + }) { + return _then(_$MiraiDividerImpl( + thickness: freezed == thickness + ? _value.thickness + : thickness // ignore: cast_nullable_to_non_nullable + as double?, + height: freezed == height + ? _value.height + : height // ignore: cast_nullable_to_non_nullable + as double?, + color: freezed == color + ? _value.color + : color // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiDividerImpl implements _MiraiDivider { + const _$MiraiDividerImpl({this.thickness, this.height, this.color}); + + factory _$MiraiDividerImpl.fromJson(Map json) => + _$$MiraiDividerImplFromJson(json); + + @override + final double? thickness; + @override + final double? height; + @override + final String? color; + + @override + String toString() { + return 'MiraiDivider(thickness: $thickness, height: $height, color: $color)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiDividerImpl && + (identical(other.thickness, thickness) || + other.thickness == thickness) && + (identical(other.height, height) || other.height == height) && + (identical(other.color, color) || other.color == color)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, thickness, height, color); + + /// Create a copy of MiraiDivider + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiDividerImplCopyWith<_$MiraiDividerImpl> get copyWith => + __$$MiraiDividerImplCopyWithImpl<_$MiraiDividerImpl>(this, _$identity); + + @override + Map toJson() { + return _$$MiraiDividerImplToJson( + this, + ); + } +} + +abstract class _MiraiDivider implements MiraiDivider { + const factory _MiraiDivider( + {final double? thickness, + final double? height, + final String? color}) = _$MiraiDividerImpl; + + factory _MiraiDivider.fromJson(Map json) = + _$MiraiDividerImpl.fromJson; + + @override + double? get thickness; + @override + double? get height; + @override + String? get color; + + /// Create a copy of MiraiDivider + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiDividerImplCopyWith<_$MiraiDividerImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.g.dart b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.g.dart new file mode 100644 index 00000000..4f43031d --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_divider.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiDividerImpl _$$MiraiDividerImplFromJson(Map json) => + _$MiraiDividerImpl( + thickness: (json['thickness'] as num?)?.toDouble(), + height: (json['height'] as num?)?.toDouble(), + color: json['color'] as String?, + ); + +Map _$$MiraiDividerImplToJson(_$MiraiDividerImpl instance) => + { + 'thickness': instance.thickness, + 'height': instance.height, + 'color': instance.color, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider_parser.dart b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider_parser.dart new file mode 100644 index 00000000..79a1a2ad --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_divider/mirai_divider_parser.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/mirai.dart'; +import 'package:mirai/src/utils/widget_type.dart'; + +class MiraiDividerParser extends MiraiParser { + const MiraiDividerParser(); + + @override + MiraiDivider getModel(Map json) { + return MiraiDivider.fromJson(json); + } + + @override + Widget parse(BuildContext context, MiraiDivider model) { + return Divider( + thickness: model.thickness, + color: model.color.toColor(context), + height: model.height, + ); + } + + @override + String get type => WidgetType.divider.name; +} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index f3067864..c5d7220b 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -28,6 +28,7 @@ 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'; export 'package:mirai/src/parsers/mirai_default_tab_controller/mirai_default_tab_controller.dart'; export 'package:mirai/src/parsers/mirai_dialog_theme/mirai_dialog_theme.dart'; +export 'package:mirai/src/parsers/mirai_divider/mirai_divider.dart'; export 'package:mirai/src/parsers/mirai_edge_insets/mirai_edge_insets.dart'; export 'package:mirai/src/parsers/mirai_elevated_button/mirai_elevated_button.dart'; export 'package:mirai/src/parsers/mirai_expanded/mirai_expanded.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index a1b7daa9..1277b0e1 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -53,4 +53,5 @@ enum WidgetType { tableCell, carouselView, coloredBox, + divider }