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 to the Wrap widget #277

Merged
merged 1 commit into from
Feb 29, 2024
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
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 @@ -1145,6 +1145,40 @@
"assetPath": "assets/json/chip_example.json"
}
}
},
{
"type": "listTile",
"leading": {
"type": "icon",
"iconType": "material",
"icon": "wrap_text"
},
"title": {
"type": "text",
"data": "Wrap",
"align": "center",
"style": {
"fontSize": 21
}
},
"subtitle": {
"type": "text",
"data": "A widget to creates a wrap layout",
"align": "center",
"style": {
"fontSize": 12
}
},
"isThreeLine": true,
"style": "list",
"onTap": {
"actionType": "navigate",
"navigationStyle": "push",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/wrap_example.json"
}
}
}
]
}
Expand Down
180 changes: 180 additions & 0 deletions examples/mirai_gallery/assets/json/wrap_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"type": "scaffold",
"appBar": {
"type": "appBar",
"title": {
"type": "text",
"data": "Wrap Demo"
}
},
"body": {
"type": "center",
"child": {
"type": "wrap",
"spacing": 8.0,
"runSpacing": 4.0,
"children": [
{
"type": "container",
"color": "#FFCDD2",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "1",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#F8BBD0",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "2",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#E1BEE7",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "3",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#D1C4E9",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "4",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#C5CAE9",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "5",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#BBDEFB",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "6",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#B3E5FC",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "7",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#B2EBF2",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "8",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#B2DFDB",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "9",
"style": {
"color": "#FFFFFF"
}
}
}
},
{
"type": "container",
"color": "#C8E6C9",
"width": 100,
"height": 100,
"child": {
"type": "center",
"child": {
"type": "text",
"data": "10",
"style": {
"color": "#FFFFFF"
}
}
}
}
]
}
}
}
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_wrap/mirai_wrap.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 @@ -67,6 +68,7 @@ class Mirai {
const MiraiGridViewParser(),
const MiraiBottomNavigationViewParser(),
const MiraiDefaultBottomNavigationControllerParser(),
const MiraiWrapParser(),
];

static final _actionParsers = <MiraiActionParser>[
Expand Down
26 changes: 26 additions & 0 deletions packages/mirai/lib/src/parsers/mirai_wrap/mirai_wrap.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

export 'mirai_wrap_parser.dart';

part 'mirai_wrap.freezed.dart';
part 'mirai_wrap.g.dart';

@freezed
class MiraiWrap with _$MiraiWrap {
const factory MiraiWrap({
@Default(Axis.horizontal) Axis direction,
@Default(WrapAlignment.start) WrapAlignment alignment,
@Default(0.0) double spacing,
@Default(WrapAlignment.start) WrapAlignment runAlignment,
@Default(0.0) double runSpacing,
@Default(WrapCrossAlignment.start) WrapCrossAlignment crossAxisAlignment,
TextDirection? textDirection,
@Default(VerticalDirection.down) VerticalDirection verticalDirection,
@Default(Clip.none) Clip clipBehavior,
@Default([]) List<Map<String, dynamic>> children,
}) = _MiraiWrap;

factory MiraiWrap.fromJson(Map<String, dynamic> json) =>
_$MiraiWrapFromJson(json);
}
Loading
Loading