Skip to content

Commit a1b55ff

Browse files
author
denny.deng
committed
add RotatedBox widget parser.
1 parent 29e3b95 commit a1b55ff

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

example/lib/main.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,16 @@ class _MyHomePageState extends State<MyHomePage> {
415415
CodeEditorPage(dividerJson)));
416416
},
417417
),
418+
RaisedButton(
419+
child: Text("RotatedBox"),
420+
onPressed: () {
421+
Navigator.push(
422+
context,
423+
MaterialPageRoute(
424+
builder: (context) =>
425+
CodeEditorPage(rotatedBoxJson)));
426+
},
427+
),
418428
]),
419429
),
420430
),

example/lib/widget_json.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,4 +1654,25 @@ var dividerJson = '''
16541654
16551655
''';
16561656

1657+
var rotatedBoxJson = '''
1658+
{
1659+
"type": "Container",
1660+
"color": "#FF00FF",
1661+
"alignment": "center",
1662+
"child": {
1663+
"type":"RotatedBox",
1664+
"quarterTurns": 3,
1665+
"child":{
1666+
"type": "Text",
1667+
"data": "Flutter dynamic widget",
1668+
"maxLines": 3,
1669+
"overflow": "ellipsis",
1670+
"style": {
1671+
"color": "#00FFFF",
1672+
"fontSize": 20.0
1673+
}
1674+
}
1675+
}
1676+
}
1677+
''';
16571678

lib/dynamic_widget.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import 'package:logging/logging.dart';
3838

3939
import 'dynamic_widget/basic/cliprrect_widget_parser.dart';
4040
import 'dynamic_widget/basic/overflowbox_widget_parser.dart';
41+
import 'dynamic_widget/basic/rotatedbox_widget_parser.dart';
4142

4243
class DynamicWidgetBuilder {
4344
static final Logger log = Logger('DynamicWidget');
@@ -81,6 +82,7 @@ class DynamicWidgetBuilder {
8182
OverflowBoxWidgetParser(),
8283
ElevatedButtonParser(),
8384
DividerWidgetParser(),
85+
RotatedBoxWidgetParser(),
8486
];
8587

8688
static final _widgetNameParserMap = <String, WidgetParser>{};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
import 'package:dynamic_widget/dynamic_widget.dart';
3+
import 'package:flutter/widgets.dart';
4+
5+
class RotatedBoxWidgetParser extends WidgetParser{
6+
@override
7+
Map<String, dynamic>? export(Widget? widget, BuildContext? buildContext) {
8+
var realWidget = widget as RotatedBox;
9+
return <String, dynamic>{
10+
"type": widgetName,
11+
"quarterTurns": realWidget.quarterTurns,
12+
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext),
13+
};
14+
}
15+
16+
@override
17+
Widget parse(Map<String, dynamic> map, BuildContext buildContext, ClickListener? listener) {
18+
return RotatedBox(
19+
quarterTurns: map['quarterTurns'],
20+
child: DynamicWidgetBuilder.buildFromMap(
21+
map["child"], buildContext, listener),
22+
);
23+
}
24+
25+
@override
26+
String get widgetName => "RotatedBox";
27+
28+
@override
29+
Type get widgetType => RotatedBox;
30+
31+
}

0 commit comments

Comments
 (0)