Skip to content

Commit

Permalink
add RotatedBox widget parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
denny.deng committed Aug 13, 2021
1 parent 29e3b95 commit a1b55ff
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ class _MyHomePageState extends State<MyHomePage> {
CodeEditorPage(dividerJson)));
},
),
RaisedButton(
child: Text("RotatedBox"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
CodeEditorPage(rotatedBoxJson)));
},
),
]),
),
),
Expand Down
21 changes: 21 additions & 0 deletions example/lib/widget_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1654,4 +1654,25 @@ var dividerJson = '''
''';

var rotatedBoxJson = '''
{
"type": "Container",
"color": "#FF00FF",
"alignment": "center",
"child": {
"type":"RotatedBox",
"quarterTurns": 3,
"child":{
"type": "Text",
"data": "Flutter dynamic widget",
"maxLines": 3,
"overflow": "ellipsis",
"style": {
"color": "#00FFFF",
"fontSize": 20.0
}
}
}
}
''';

2 changes: 2 additions & 0 deletions lib/dynamic_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import 'package:logging/logging.dart';

import 'dynamic_widget/basic/cliprrect_widget_parser.dart';
import 'dynamic_widget/basic/overflowbox_widget_parser.dart';
import 'dynamic_widget/basic/rotatedbox_widget_parser.dart';

class DynamicWidgetBuilder {
static final Logger log = Logger('DynamicWidget');
Expand Down Expand Up @@ -81,6 +82,7 @@ class DynamicWidgetBuilder {
OverflowBoxWidgetParser(),
ElevatedButtonParser(),
DividerWidgetParser(),
RotatedBoxWidgetParser(),
];

static final _widgetNameParserMap = <String, WidgetParser>{};
Expand Down
31 changes: 31 additions & 0 deletions lib/dynamic_widget/basic/rotatedbox_widget_parser.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import 'package:dynamic_widget/dynamic_widget.dart';
import 'package:flutter/widgets.dart';

class RotatedBoxWidgetParser extends WidgetParser{
@override
Map<String, dynamic>? export(Widget? widget, BuildContext? buildContext) {
var realWidget = widget as RotatedBox;
return <String, dynamic>{
"type": widgetName,
"quarterTurns": realWidget.quarterTurns,
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext),
};
}

@override
Widget parse(Map<String, dynamic> map, BuildContext buildContext, ClickListener? listener) {
return RotatedBox(
quarterTurns: map['quarterTurns'],
child: DynamicWidgetBuilder.buildFromMap(
map["child"], buildContext, listener),
);
}

@override
String get widgetName => "RotatedBox";

@override
Type get widgetType => RotatedBox;

}

0 comments on commit a1b55ff

Please sign in to comment.