Skip to content

Commit f83031a

Browse files
Merge pull request #114 from loud-at-heart/feature/feat_Add_flutter_Stack_support_in_Mirai
feat: Add `Stack` and `positioned` widget support
2 parents 3598aa8 + 215a040 commit f83031a

19 files changed

+1610
-0
lines changed

examples/mirai_gallery/assets/json/home_screen.json

+32
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,38 @@
201201
}
202202
}
203203
},
204+
{
205+
"type": "listTile",
206+
"leading": {
207+
"type": "icon",
208+
"iconType": "material",
209+
"icon": "layers"
210+
},
211+
"title": {
212+
"type": "text",
213+
"data": "Mirai Stack",
214+
"style": {
215+
"fontSize": 21
216+
}
217+
},
218+
"subtitle": {
219+
"type": "text",
220+
"data": "This is a mirai stack widget.",
221+
"style": {
222+
"fontSize": 12
223+
}
224+
},
225+
"isThreeLine": true,
226+
"onTap": {
227+
"actionType": "navigate",
228+
"navigationStyle": "push",
229+
"navigationType": "screen",
230+
"widgetJson": {
231+
"type": "exampleScreen",
232+
"assetPath": "assets/json/stack_example.json"
233+
}
234+
}
235+
},
204236
{
205237
"type": "listTile",
206238
"leading": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"type": "scaffold",
3+
"appBar": {
4+
"type": "appBar",
5+
"title": {
6+
"type": "text",
7+
"data": "Stack"
8+
}
9+
},
10+
"body": {
11+
"type": "stack",
12+
"alignment": "center",
13+
"clipBehavior": "antiAlias",
14+
"children": [
15+
{
16+
"type": "positioned",
17+
"top": 30,
18+
"left": 30,
19+
"height": 150,
20+
"width": 150,
21+
"child": {
22+
"type": "container",
23+
"width": 75,
24+
"height": 75,
25+
"color": "#81C784",
26+
"child": {
27+
"type": "text",
28+
"data": "Green",
29+
"align": "center",
30+
"style": {
31+
"fontSize": 20,
32+
"color": "#FFFFFF"
33+
}
34+
}
35+
}
36+
},
37+
{
38+
"type": "positioned",
39+
"top": 70,
40+
"left": 60,
41+
"height": 150,
42+
"width": 150,
43+
"child": {
44+
"type": "container",
45+
"width": 75,
46+
"height": 75,
47+
"color": "#EF5350",
48+
"child": {
49+
"type": "text",
50+
"data": "Red",
51+
"align": "center",
52+
"style": {
53+
"fontSize": 20,
54+
"color": "#FFFFFF"
55+
}
56+
}
57+
}
58+
},
59+
{
60+
"type": "positioned",
61+
"positionedType": "fill",
62+
"top": 130,
63+
"left": 90,
64+
"height": 150,
65+
"width": 150,
66+
"child": {
67+
"type": "container",
68+
"width": 75,
69+
"height": 75,
70+
"color": "#BA68C8",
71+
"child": {
72+
"type": "text",
73+
"data": "Purple",
74+
"align": "center",
75+
"style": {
76+
"fontSize": 20,
77+
"color": "#FFFFFF"
78+
}
79+
}
80+
}
81+
}
82+
]
83+
}
84+
}

packages/mirai/lib/src/framework/mirai.dart

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Mirai {
3131
const MiraiCenterParser(),
3232
const MiraiRowParser(),
3333
const MiraiColumnParser(),
34+
const MiraiStackParser(),
35+
const MiraiPositionedParser(),
3436
const MiraiIconButtonParser(),
3537
const MiraiFloatingActionButtonParser(),
3638
const MiraiOutlinedButtonParser(),

packages/mirai/lib/src/parsers/mirai_alignment/mirai_alignment.dart

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ enum MiraiAlignment {
3131
return Alignment.bottomCenter;
3232
case MiraiAlignment.bottomRight:
3333
return Alignment.bottomRight;
34+
default:
35+
return Alignment.topLeft;
3436
}
3537
}
3638
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:flutter/cupertino.dart';
2+
3+
enum MiraiAlignmentDirectional {
4+
topStart,
5+
topCenter,
6+
topEnd,
7+
centerStart,
8+
center,
9+
centerEnd,
10+
bottomStart,
11+
bottomCenter,
12+
bottomEnd;
13+
14+
AlignmentDirectional get value {
15+
switch (this) {
16+
case MiraiAlignmentDirectional.topStart:
17+
return AlignmentDirectional.topStart;
18+
case MiraiAlignmentDirectional.topCenter:
19+
return AlignmentDirectional.topCenter;
20+
case MiraiAlignmentDirectional.topEnd:
21+
return AlignmentDirectional.topEnd;
22+
case MiraiAlignmentDirectional.centerStart:
23+
return AlignmentDirectional.centerStart;
24+
case MiraiAlignmentDirectional.center:
25+
return AlignmentDirectional.center;
26+
case MiraiAlignmentDirectional.centerEnd:
27+
return AlignmentDirectional.centerEnd;
28+
case MiraiAlignmentDirectional.bottomStart:
29+
return AlignmentDirectional.bottomStart;
30+
case MiraiAlignmentDirectional.bottomCenter:
31+
return AlignmentDirectional.bottomCenter;
32+
case MiraiAlignmentDirectional.bottomEnd:
33+
return AlignmentDirectional.bottomEnd;
34+
default:
35+
return AlignmentDirectional.topStart;
36+
}
37+
}
38+
}

packages/mirai/lib/src/parsers/mirai_gradient/mirai_gradient.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:math' as math;
2+
23
import 'package:flutter/material.dart';
34
import 'package:freezed_annotation/freezed_annotation.dart';
45
import 'package:mirai/src/parsers/parsers.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:freezed_annotation/freezed_annotation.dart';
3+
import 'package:mirai/src/parsers/mirai_rect/mirai_rect.dart';
4+
5+
export 'package:mirai/src/parsers/mirai_positioned/mirai_positioned_parser.dart';
6+
7+
part 'mirai_positioned.freezed.dart';
8+
part 'mirai_positioned.g.dart';
9+
10+
/*
11+
* TODO :: Add support for fromRelativeRect
12+
* enum MiraiPositionedType { directional, fill, fromRect, fromRelativeRect}
13+
*/
14+
15+
enum MiraiPositionedType { directional, fill, fromRect }
16+
17+
@freezed
18+
class MiraiPositioned with _$MiraiPositioned {
19+
const factory MiraiPositioned({
20+
MiraiPositionedType? positionedType,
21+
double? left,
22+
double? top,
23+
double? right,
24+
double? bottom,
25+
double? width,
26+
double? height,
27+
double? start,
28+
double? end,
29+
@Default(TextDirection.ltr) TextDirection textDirection,
30+
MiraiRect? rect,
31+
Map<String, dynamic>? child,
32+
}) = _MiraiPositioned;
33+
34+
factory MiraiPositioned.fromJson(Map<String, dynamic> json) =>
35+
_$MiraiPositionedFromJson(json);
36+
}

0 commit comments

Comments
 (0)