Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for the Divider widget #20

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/mirai_gallery/assets/json/divider_example.json
Original file line number Diff line number Diff line change
@@ -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"
}]
}
}
34 changes: 34 additions & 0 deletions examples/mirai_gallery/assets/json/home_screen.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/mirai/lib/src/framework/mirai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -82,6 +83,7 @@ class Mirai {
const MiraiTableCellParser(),
const MiraiCarouselViewParser(),
const MiraiColoredBoxParser(),
const MiraiDividerParser()
];

static final _actionParsers = <MiraiActionParser>[
Expand Down
16 changes: 16 additions & 0 deletions packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.dart
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +3 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 generated files are missing. We need to include them as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@divyanshub024 added this.


@freezed
class MiraiDivider with _$MiraiDivider {
const factory MiraiDivider({
double? thickness,
double? height,
String? color,
}) = _MiraiDivider;

factory MiraiDivider.fromJson(Map<String, dynamic> json) =>
_$MiraiDividerFromJson(json);
}
Original file line number Diff line number Diff line change
@@ -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>(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<String, dynamic> 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<String, dynamic> 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<MiraiDivider> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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;
}
21 changes: 21 additions & 0 deletions packages/mirai/lib/src/parsers/mirai_divider/mirai_divider.g.dart

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,24 @@
import 'package:flutter/material.dart';
import 'package:mirai/mirai.dart';
import 'package:mirai/src/utils/widget_type.dart';

class MiraiDividerParser extends MiraiParser<MiraiDivider> {
const MiraiDividerParser();

@override
MiraiDivider getModel(Map<String, dynamic> 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;
}
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 @@ -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';
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 @@ -53,4 +53,5 @@ enum WidgetType {
tableCell,
carouselView,
coloredBox,
divider
}
Loading