Skip to content

Commit 7e07861

Browse files
Merge pull request #82 from Yash-Khattar/feature/hero
feat: Add Mirai parser for hero widget
2 parents 2978cc5 + 28deb06 commit 7e07861

File tree

12 files changed

+876
-1
lines changed

12 files changed

+876
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"type": "scaffold",
3+
"appBar": {
4+
"type": "appBar",
5+
"title": {
6+
"type": "text",
7+
"data": "Hero Example"
8+
}
9+
},
10+
"body": {
11+
"type": "center",
12+
"child": {
13+
"type": "column",
14+
"mainAxisAlignment": "center",
15+
"children": [
16+
{
17+
"type": "hero",
18+
"tag": "hero-icon",
19+
"createRectTween": {
20+
"type": "materialRectArcTween",
21+
"begin": {
22+
"rectType": "fromCenter",
23+
"center": {
24+
"dx": 120.0,
25+
"dy": 140.0
26+
},
27+
"width": 100.0,
28+
"height": 100.0
29+
},
30+
"end": {
31+
"rectType": "fromCenter",
32+
"center": {
33+
"dx": 200.0,
34+
"dy": 200.0
35+
},
36+
"width": 50.0,
37+
"height": 50.0
38+
}
39+
},
40+
"child": {
41+
"type": "icon",
42+
"iconType": "material",
43+
"icon": "flight_takeoff",
44+
"size": 150.0
45+
}
46+
},
47+
{
48+
"type": "sizedBox",
49+
"height": 24.0
50+
},
51+
{
52+
"type": "textButton",
53+
"child": {
54+
"type": "text",
55+
"data": "Tap to see Hero Animation"
56+
},
57+
"onPressed": {
58+
"actionType": "navigate",
59+
"navigationStyle": "push",
60+
"widgetJson": {
61+
"type": "scaffold",
62+
"appBar": {
63+
"type": "appBar",
64+
"title": {
65+
"type": "text",
66+
"data": "Flight Details"
67+
}
68+
},
69+
"body": {
70+
"type": "center",
71+
"child": {
72+
"type": "column",
73+
"mainAxisAlignment": "center",
74+
"children": [
75+
{
76+
"type": "hero",
77+
"tag": "hero-icon",
78+
"createRectTween": {
79+
"type": "materialRectArcTween",
80+
"begin": {
81+
"rectType": "fromCenter",
82+
"center": {
83+
"dx": 120.0,
84+
"dy": 140.0
85+
},
86+
"width": 100.0,
87+
"height": 100.0
88+
},
89+
"end": {
90+
"rectType": "fromCenter",
91+
"center": {
92+
"dx": 200.0,
93+
"dy": 200.0
94+
},
95+
"width": 50.0,
96+
"height": 50.0
97+
}
98+
},
99+
"child": {
100+
"type": "icon",
101+
"iconType": "material",
102+
"icon": "flight_takeoff",
103+
"size": 50.0
104+
}
105+
},
106+
{
107+
"type": "sizedBox",
108+
"height": 16.0
109+
},
110+
{
111+
"type": "text",
112+
"data": "Flight AB123",
113+
"style": {
114+
"fontSize": 24.0,
115+
"fontWeight": "w500"
116+
}
117+
}
118+
]
119+
}
120+
}
121+
}
122+
}
123+
}
124+
]
125+
}
126+
}
127+
}

examples/mirai_gallery/assets/json/home_screen.json

+34
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,40 @@
14211421
}
14221422
}
14231423
},
1424+
{
1425+
"type": "listTile",
1426+
"leading": {
1427+
"type": "icon",
1428+
"iconType": "material",
1429+
"icon": "flight_takeoff"
1430+
},
1431+
"title": {
1432+
"type": "text",
1433+
"data": "Mirai Hero",
1434+
"align": "center",
1435+
"style": {
1436+
"fontSize": 21
1437+
}
1438+
},
1439+
"subtitle": {
1440+
"type": "text",
1441+
"data": "A Hero Widget",
1442+
"align": "center",
1443+
"style": {
1444+
"fontSize": 12
1445+
}
1446+
},
1447+
"isThreeLine": true,
1448+
"style": "list",
1449+
"onTap": {
1450+
"actionType": "navigate",
1451+
"navigationStyle": "push",
1452+
"widgetJson": {
1453+
"type": "exampleScreen",
1454+
"assetPath": "assets/json/hero_example.json"
1455+
}
1456+
}
1457+
},
14241458
{
14251459
"type": "sizedBox",
14261460
"height": 24.0

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

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Mirai {
8686
const MiraiDividerParser(),
8787
const MiraiCircularProgressIndicatorParser(),
8888
const MiraiLinearProgressIndicatorParser(),
89+
const MiraiHeroParser(),
8990
];
9091

9192
static final _actionParsers = <MiraiActionParser>[
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:freezed_annotation/freezed_annotation.dart';
2+
import 'package:mirai/src/parsers/mirai_rect_tween/mirai_rect_tween.dart';
3+
export 'package:mirai/src/parsers/mirai_hero/mirai_hero_parser.dart';
4+
5+
part 'mirai_hero.freezed.dart';
6+
part 'mirai_hero.g.dart';
7+
8+
@freezed
9+
class MiraiHero with _$MiraiHero {
10+
const factory MiraiHero({
11+
required Object tag,
12+
required Map<String, dynamic> child,
13+
MiraiRectTween? createRectTween,
14+
Map<String, dynamic>? flightShuttleBuilder,
15+
Map<String, dynamic>? placeholderBuilder,
16+
@Default(false) bool transitionOnUserGestures,
17+
}) = _MiraiHero;
18+
19+
factory MiraiHero.fromJson(Map<String, dynamic> json) =>
20+
_$MiraiHeroFromJson(json);
21+
}

0 commit comments

Comments
 (0)