Skip to content

Commit

Permalink
Merge pull request #48 from Revitate/master
Browse files Browse the repository at this point in the history
Fix Bug that I found in parser
  • Loading branch information
dengyin2000 authored Dec 31, 2020
2 parents f9c1024 + 05759a0 commit bd3f6b4
Show file tree
Hide file tree
Showing 22 changed files with 580 additions and 508 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ class RaisedButtonParser extends WidgetParser {
? parseHexColor(map['disabledColor'])
: null,
disabledElevation:
map.containsKey('disabledElevation') ? map['disabledElevation'] : 0.0,
map.containsKey('disabledElevation') ? map['disabledElevation']?.toDouble() : 0.0,
disabledTextColor: map.containsKey('disabledTextColor')
? parseHexColor(map['disabledTextColor'])
: null,
elevation: map.containsKey('elevation') ? map['elevation'] : 0.0,
elevation: map.containsKey('elevation') ? map['elevation']?.toDouble() : 0.0,
padding: map.containsKey('padding')
? parseEdgeInsetsGeometry(map['padding'])
: null,
Expand Down
698 changes: 366 additions & 332 deletions WIDGETS.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/dynamic_widget/basic/align_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class AlignWidgetParser extends WidgetParser {
alignment: map.containsKey("alignment")
? parseAlignment(map["alignment"])
: Alignment.center,
widthFactor: map.containsKey("widthFactor") ? map["widthFactor"] : null,
widthFactor: map.containsKey("widthFactor") ? map["widthFactor"]?.toDouble() : null,
heightFactor:
map.containsKey("heightFactor") ? map["heightFactor"] : null,
map.containsKey("heightFactor") ? map["heightFactor"]?.toDouble() : null,
child: DynamicWidgetBuilder.buildFromMap(
map["child"], buildContext, listener),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic_widget/basic/aspectratio_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AspectRatioWidgetParser extends WidgetParser {
Widget parse(Map<String, dynamic> map, BuildContext buildContext,
ClickListener listener) {
return AspectRatio(
aspectRatio: map["aspectRatio"],
aspectRatio: map["aspectRatio"]?.toDouble(),
child: DynamicWidgetBuilder.buildFromMap(
map["child"], buildContext, listener),
);
Expand Down
8 changes: 5 additions & 3 deletions lib/dynamic_widget/basic/baseline_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BaselineWidgetParser extends WidgetParser {
Widget parse(Map<String, dynamic> map, BuildContext buildContext,
ClickListener listener) {
return Baseline(
baseline: map["baseline"],
baseline: map["baseline"]?.toDouble(),
baselineType: map["baselineType"] == "alphabetic"
? TextBaseline.alphabetic
: TextBaseline.ideographic,
Expand All @@ -24,8 +24,10 @@ class BaselineWidgetParser extends WidgetParser {
return <String, dynamic>{
"type": widgetName,
"baseline": realWidget.baseline,
"baselineType" : realWidget.baselineType == TextBaseline.alphabetic ? "alphabetic":"ideographic",
"child":DynamicWidgetBuilder.export(realWidget.child, buildContext)
"baselineType": realWidget.baselineType == TextBaseline.alphabetic
? "alphabetic"
: "ideographic",
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};
}

Expand Down
35 changes: 24 additions & 11 deletions lib/dynamic_widget/basic/button_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ class RaisedButtonParser extends WidgetParser {
disabledColor: map.containsKey('disabledColor')
? parseHexColor(map['disabledColor'])
: null,
disabledElevation:
map.containsKey('disabledElevation') ? map['disabledElevation'] : 0.0,
disabledElevation: map.containsKey('disabledElevation')
? map['disabledElevation']?.toDouble()
: 0.0,
disabledTextColor: map.containsKey('disabledTextColor')
? parseHexColor(map['disabledTextColor'])
: null,
elevation: map.containsKey('elevation') ? map['elevation'] : 0.0,
elevation:
map.containsKey('elevation') ? map['elevation']?.toDouble() : 0.0,
padding: map.containsKey('padding')
? parseEdgeInsetsGeometry(map['padding'])
: null,
Expand Down Expand Up @@ -48,16 +50,27 @@ class RaisedButtonParser extends WidgetParser {

return <String, dynamic>{
"type": widgetName,
"color": realWidget.color != null ? realWidget.color.value.toRadixString(16):null,
"disabledColor" : realWidget.disabledColor !=null? realWidget.disabledColor.value.toRadixString(16):null,
"color": realWidget.color != null
? realWidget.color.value.toRadixString(16)
: null,
"disabledColor": realWidget.disabledColor != null
? realWidget.disabledColor.value.toRadixString(16)
: null,
"disabledElevation": realWidget.disabledElevation,
"disabledTextColor": realWidget.disabledTextColor!=null ?realWidget.disabledTextColor.value.toRadixString(16):null,
"disabledTextColor": realWidget.disabledTextColor != null
? realWidget.disabledTextColor.value.toRadixString(16)
: null,
"elevation": realWidget.elevation,
"padding": padding !=null ? "${padding.left},${padding.top},${padding.right},${padding.bottom}" : null,
"splashColor": realWidget.splashColor!=null ? realWidget.splashColor.value.toRadixString(16) : null,
"textColor": realWidget.textColor!=null?realWidget.textColor.value.toRadixString(16):null,
"child":DynamicWidgetBuilder.export(realWidget.child, buildContext)

"padding": padding != null
? "${padding.left},${padding.top},${padding.right},${padding.bottom}"
: null,
"splashColor": realWidget.splashColor != null
? realWidget.splashColor.value.toRadixString(16)
: null,
"textColor": realWidget.textColor != null
? realWidget.textColor.value.toRadixString(16)
: null,
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};
}

Expand Down
4 changes: 2 additions & 2 deletions lib/dynamic_widget/basic/center_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class CenterWidgetParser extends WidgetParser {
Widget parse(Map<String, dynamic> map, BuildContext buildContext,
ClickListener listener) {
return Center(
widthFactor: map.containsKey("widthFactor") ? map["widthFactor"] : null,
widthFactor: map.containsKey("widthFactor") ? map["widthFactor"]?.toDouble() : null,
heightFactor:
map.containsKey("heightFactor") ? map["heightFactor"] : null,
map.containsKey("heightFactor") ? map["heightFactor"]?.toDouble() : null,
child: DynamicWidgetBuilder.buildFromMap(
map["child"], buildContext, listener),
);
Expand Down
6 changes: 3 additions & 3 deletions lib/dynamic_widget/basic/cliprrect_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class ClipRRectWidgetParser extends WidgetParser {
var borderRadius = realWidget.borderRadius;
return <String, dynamic>{
"type": widgetName,
"borderRadius": "${borderRadius.topLeft},${borderRadius.topRight},${borderRadius.bottomLeft},${borderRadius.bottomRight}",
"borderRadius":
"${borderRadius.topLeft.x},${borderRadius.topRight.x},${borderRadius.bottomLeft.x},${borderRadius.bottomRight.x}",
"clipBehavior": exportClipBehavior(realWidget.clipBehavior),
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};

}

@override
Type get widgetType => ClipRect;
Type get widgetType => ClipRRect;
}
26 changes: 18 additions & 8 deletions lib/dynamic_widget/basic/container_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ContainerWidgetParser extends WidgetParser {
padding: padding,
color: color,
margin: margin,
width: map['width'],
height: map['height'],
width: map['width']?.toDouble(),
height: map['height']?.toDouble(),
constraints: constraints,
child: child,
);
Expand All @@ -51,14 +51,24 @@ class ContainerWidgetParser extends WidgetParser {
var realWidget = widget as Container;
var padding = realWidget.padding as EdgeInsets;
var margin = realWidget.margin as EdgeInsets;
var constraints = realWidget.constraints;
return <String, dynamic>{
"type": widgetName,
"alignment": realWidget.alignment !=null ? exportAlignment(realWidget.alignment) : null,
"padding" : padding!=null? "${padding.left},${padding.top},${padding.right},${padding.bottom}":null,
"color": realWidget.color!=null ? realWidget.color.value.toRadixString(16) : null,
"margin": margin != null? "${margin.left},${margin.top},${margin.right},${margin.bottom}":null,
//TODO: Container don't expose the width and height properties, so I don't know
// how to export width and height properties.
"alignment": realWidget.alignment != null
? exportAlignment(realWidget.alignment)
: null,
"padding": padding != null
? "${padding.left},${padding.top},${padding.right},${padding.bottom}"
: null,
"color": realWidget.color != null
? realWidget.color.value.toRadixString(16)
: null,
"margin": margin != null
? "${margin.left},${margin.top},${margin.right},${margin.bottom}"
: null,
"constraints": constraints!= null
? exportConstraints(constraints)
: null,
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic_widget/basic/expanded_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ExpandedWidgetParser extends WidgetParser {
return <String, dynamic>{
"type": widgetName,
"flex": realWidget.flex,
"child": DynamicWidgetBuilder.export(realWidget, buildContext)
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic_widget/basic/fittedbox_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FittedBoxWidgetParser extends WidgetParser {
"type": widgetName,
"alignment": realWidget.alignment != null? exportAlignment(realWidget.alignment):null,
"fit": realWidget.fit!=null? exportBoxFit(realWidget.fit):BoxFit.contain,
"child": DynamicWidgetBuilder.export(realWidget, buildContext)
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};
}

Expand Down
10 changes: 7 additions & 3 deletions lib/dynamic_widget/basic/icon_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class IconWidgetParser extends WidgetParser {
map.containsKey('data')
? getIconUsingPrefix(name: map['data'])
: Icons.android,
size: map.containsKey("size") ? map['size'] : null,
size: map.containsKey("size") ? map['size']?.toDouble() : null,
color: map.containsKey('color') ? parseHexColor(map['color']) : null,
semanticLabel:
map.containsKey('semanticLabel') ? map['semanticLabel'] : null,
Expand All @@ -31,9 +31,13 @@ class IconWidgetParser extends WidgetParser {
"type": widgetName,
"data": exportIconGuessFavorMaterial(realWidget.icon),
"size": realWidget.size,
"color": realWidget.color!=null?realWidget.color.value.toRadixString(16):null,
"color": realWidget.color != null
? realWidget.color.value.toRadixString(16)
: null,
"semanticLabel": realWidget.semanticLabel,
"textDirection": realWidget.textDirection!=null? exportTextDirection(realWidget.textDirection):null,
"textDirection": realWidget.textDirection != null
? exportTextDirection(realWidget.textDirection)
: null,
};
}

Expand Down
12 changes: 6 additions & 6 deletions lib/dynamic_widget/basic/image_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class AssetImageWidgetParser extends WidgetParser {
bool excludeFromSemantics = map.containsKey('excludeFromSemantics')
? map['excludeFromSemantics']
: false;
double scale = map.containsKey("scale") ? map['scale'] : null;
double width = map.containsKey('width') ? map['width'] : null;
double height = map.containsKey('height') ? map['height'] : null;
double scale = map.containsKey("scale") ? map['scale']?.toDouble() : null;
double width = map.containsKey('width') ? map['width']?.toDouble() : null;
double height = map.containsKey('height') ? map['height']?.toDouble() : null;
Color color = map.containsKey('color') ? parseHexColor(map['color']) : null;
BlendMode blendMode =
map.containsKey('blendMode') ? parseBlendMode(map['blendMode']) : null;
Expand Down Expand Up @@ -184,9 +184,9 @@ class NetworkImageWidgetParser extends WidgetParser {
bool excludeFromSemantics = map.containsKey('excludeFromSemantics')
? map['excludeFromSemantics']
: false;
double scale = map.containsKey("scale") ? map['scale'] : 1.0;
double width = map.containsKey('width') ? map['width'] : null;
double height = map.containsKey('height') ? map['height'] : null;
double scale = map.containsKey("scale") ? map['scale']?.toDouble() : 1.0;
double width = map.containsKey('width') ? map['width']?.toDouble() : null;
double height = map.containsKey('height') ? map['height']?.toDouble() : null;
Color color = map.containsKey('color') ? parseHexColor(map['color']) : null;
BlendMode blendMode =
map.containsKey('blendMode') ? parseBlendMode(map['blendMode']) : null;
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic_widget/basic/opacity_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OpacityWidgetParser extends WidgetParser {
Widget parse(Map<String, dynamic> map, BuildContext buildContext,
ClickListener listener) {
return Opacity(
opacity: map["opacity"],
opacity: map["opacity"]?.toDouble(),
alwaysIncludeSemantics: map.containsKey("alwaysIncludeSemantics")
? map["alwaysIncludeSemantics"]
: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic_widget/basic/padding_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PaddingWidgetParser extends WidgetParser {
return <String, dynamic>{
"type": widgetName,
"padding": padding!=null? "${padding.left},${padding.top},${padding.right},${padding.bottom}":null,
"child": DynamicWidgetBuilder.export(realWidget, buildContext)
"child": DynamicWidgetBuilder.export(realWidget.child, buildContext)
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/dynamic_widget/basic/placeholder_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class PlaceholderWidgetParser extends WidgetParser {
color: map.containsKey('color')
? parseHexColor(map['color'])
: const Color(0xFF455A64),
strokeWidth: map.containsKey('strokeWidth') ? map['strokeWidth'] : 2.0,
strokeWidth: map.containsKey('strokeWidth') ? map['strokeWidth']?.toDouble() : 2.0,
fallbackWidth:
map.containsKey('fallbackWidth') ? map['fallbackWidth'] : 400.0,
map.containsKey('fallbackWidth') ? map['fallbackWidth']?.toDouble() : 400.0,
fallbackHeight:
map.containsKey('fallbackHeight') ? map['fallbackHeight'] : 400.0,
map.containsKey('fallbackHeight') ? map['fallbackHeight']?.toDouble() : 400.0,
);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/dynamic_widget/basic/stack_positioned_widgets_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class PositionedWidgetParser extends WidgetParser {
return Positioned(
child: DynamicWidgetBuilder.buildFromMap(
map["child"], buildContext, listener),
top: map.containsKey("top") ? map["top"] : null,
right: map.containsKey("right") ? map["right"] : null,
bottom: map.containsKey("bottom") ? map["bottom"] : null,
left: map.containsKey("left") ? map["left"] : null,
width: map.containsKey("width") ? map["width"] : null,
height: map.containsKey("height") ? map["height"] : null,
top: map.containsKey("top") ? map["top"]?.toDouble() : null,
right: map.containsKey("right") ? map["right"]?.toDouble() : null,
bottom: map.containsKey("bottom") ? map["bottom"]?.toDouble() : null,
left: map.containsKey("left") ? map["left"]?.toDouble() : null,
width: map.containsKey("width") ? map["width"]?.toDouble() : null,
height: map.containsKey("height") ? map["height"]?.toDouble() : null,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/dynamic_widget/basic/text_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TextWidgetParser implements WidgetParser {
String semanticsLabel = map['semanticsLabel'];
bool softWrap = map['softWrap'];
String textDirectionString = map['textDirection'];
double textScaleFactor = map['textScaleFactor'];
double textScaleFactor = map['textScaleFactor']?.toDouble();
var textSpan;
var textSpanParser = TextSpanParser();
if (map.containsKey("textSpan")) {
Expand Down
4 changes: 2 additions & 2 deletions lib/dynamic_widget/basic/wrap_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class WrapWidgetParser extends WidgetParser {
alignment: map.containsKey("alignment")
? parseWrapAlignment(map["alignment"])
: WrapAlignment.start,
spacing: map.containsKey("spacing") ? map["spacing"] : 0.0,
spacing: map.containsKey("spacing") ? map["spacing"]?.toDouble() : 0.0,
runAlignment: map.containsKey("runAlignment")
? parseWrapAlignment(map["runAlignment"])
: WrapAlignment.start,
runSpacing: map.containsKey("runSpacing") ? map["runSpacing"] : 0.0,
runSpacing: map.containsKey("runSpacing") ? map["runSpacing"]?.toDouble() : 0.0,
crossAxisAlignment: map.containsKey("crossAxisAlignment")
? parseWrapCrossAlignment(map["crossAxisAlignment"])
: WrapCrossAlignment.start,
Expand Down
8 changes: 4 additions & 4 deletions lib/dynamic_widget/scrolling/gridview_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class GridViewWidgetParser extends WidgetParser {
bool reverse = map.containsKey("reverse") ? map['reverse'] : false;
bool shrinkWrap = map.containsKey("shrinkWrap") ? map["shrinkWrap"] : false;
double cacheExtent =
map.containsKey("cacheExtent") ? map["cacheExtent"] : 0.0;
map.containsKey("cacheExtent") ? map["cacheExtent"]?.toDouble() : 0.0;
EdgeInsetsGeometry padding = map.containsKey('padding')
? parseEdgeInsetsGeometry(map['padding'])
: null;
double mainAxisSpacing =
map.containsKey('mainAxisSpacing') ? map['mainAxisSpacing'] : 0.0;
map.containsKey('mainAxisSpacing') ? map['mainAxisSpacing']?.toDouble() : 0.0;
double crossAxisSpacing =
map.containsKey('crossAxisSpacing') ? map['crossAxisSpacing'] : 0.0;
map.containsKey('crossAxisSpacing') ? map['crossAxisSpacing']?.toDouble() : 0.0;
double childAspectRatio =
map.containsKey('childAspectRatio') ? map['childAspectRatio'] : 1.0;
map.containsKey('childAspectRatio') ? map['childAspectRatio']?.toDouble() : 1.0;
var children = DynamicWidgetBuilder.buildWidgets(
map['children'], buildContext, listener);

Expand Down
4 changes: 2 additions & 2 deletions lib/dynamic_widget/scrolling/listview_widget_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class ListViewWidgetParser extends WidgetParser {

var reverse = map.containsKey("reverse") ? map['reverse'] : false;
var shrinkWrap = map.containsKey("shrinkWrap") ? map["shrinkWrap"] : false;
var cacheExtent = map.containsKey("cacheExtent") ? map["cacheExtent"] : 0.0;
var cacheExtent = map.containsKey("cacheExtent") ? map["cacheExtent"]?.toDouble() : 0.0;
var padding = map.containsKey('padding')
? parseEdgeInsetsGeometry(map['padding'])
: null;
var itemExtent = map.containsKey("itemExtent") ? map["itemExtent"] : null;
var itemExtent = map.containsKey("itemExtent") ? map["itemExtent"]?.toDouble() : null;
var children = DynamicWidgetBuilder.buildWidgets(
map['children'], buildContext, listener);
var pageSize = map.containsKey("pageSize") ? map["pageSize"] : 10;
Expand Down
Loading

0 comments on commit bd3f6b4

Please sign in to comment.