Skip to content

Commit

Permalink
add divider widget parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
denny.deng committed Jul 23, 2021
1 parent 6a30509 commit 29e3b95
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ Already completed widgets:
* [LimitedBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#limitedbox-widget)
* [Offstage](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#offstage-widget)
* [OverflowBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#overflowbox-widget)
* [Divider](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#divider-widget)


You can view [Currently support widgets and properties](WIDGETS.md) here.
Expand Down
13 changes: 13 additions & 0 deletions WIDGETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- [LimitedBox Widget](#limitedbox-widget)
- [Offstage Widget](#offstage-widget)
- [OverflowBox Widget](#overflowbox-widget)
- [Divider Widget](#divider-widget)

## Container Widget

Expand Down Expand Up @@ -583,3 +584,15 @@ OverflowBox, here to see flutter [OverflowBox](https://api.flutter.dev/flutter/w
| minWidth | The minimum width constraint to give the child. Set this to null (the default) to use the constraint from the parent instead. | double | | |
| child | The widget below this widget in the tree. | Widget | | |

## Divider Widget

Divider, here to see flutter [Divider](https://api.flutter.dev/flutter/material/Divider-class.html) definition. Supported json properties:

| property | definition | type | value | sample |
| ------------- | ------------------------------------------------------ | ------ | ----------------------------------------------------- | -------------------------------------------------------------------------- |
| height | The divider's height extent. | double | 8.0 | |
| thickness | The thickness of the line drawn within the divider. | double | 2.0 | |
| indent | The amount of empty space to the leading edge of the divider. | double | 8.0 | |
| endIndent | The amount of empty space to the trailing edge of the divider. | double | 8.0 | |
| color | The color to use when painting the line. | String | "#AARRGGBB" or "#RRGGBB" | "#FF00FF"<br>"#00FF00FF" |

10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ class _MyHomePageState extends State<MyHomePage> {
CodeEditorPage(overflowboxJson)));
},
),
RaisedButton(
child: Text("Divider"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
CodeEditorPage(dividerJson)));
},
),
]),
),
),
Expand Down
192 changes: 192 additions & 0 deletions example/lib/widget_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1463,3 +1463,195 @@ var overflowboxJson = '''
}
''';

var dividerJson = '''
{
"type": "ListView",
"padding": "10, 10, 10, 10",
"children":[
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
},
{
"type": "AssetImage",
"name": "assets/vip.png"
},
{
"type": "Divider",
"height": 8.0,
"color": "##FF00FF",
"indent": 100.0,
"endIndent": 100.0,
"thickness": 20.0
}
]
}
''';


4 changes: 3 additions & 1 deletion lib/dynamic_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:dynamic_widget/dynamic_widget/basic/baseline_widget_parser.dart'
import 'package:dynamic_widget/dynamic_widget/basic/button_widget_parser.dart';
import 'package:dynamic_widget/dynamic_widget/basic/center_widget_parser.dart';
import 'package:dynamic_widget/dynamic_widget/basic/container_widget_parser.dart';
import 'package:dynamic_widget/dynamic_widget/basic/divider_widget_parser.dart';
import 'package:dynamic_widget/dynamic_widget/basic/dropcaptext_widget_parser.dart';
import 'package:dynamic_widget/dynamic_widget/basic/expanded_widget_parser.dart';
import 'package:dynamic_widget/dynamic_widget/basic/fittedbox_widget_parser.dart';
Expand Down Expand Up @@ -78,7 +79,8 @@ class DynamicWidgetBuilder {
LimitedBoxWidgetParser(),
OffstageWidgetParser(),
OverflowBoxWidgetParser(),
ElevatedButtonParser()
ElevatedButtonParser(),
DividerWidgetParser(),
];

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

import 'package:dynamic_widget/dynamic_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';

import '../utils.dart';

class DividerWidgetParser extends WidgetParser{
@override
Map<String, dynamic>? export(Widget? widget, BuildContext? buildContext) {
Divider realWidget = widget as Divider;
return <String, dynamic>{
"type": widgetName,
"height": realWidget.height,
"thickness": realWidget.thickness,
"indent": realWidget.indent,
"endIndent": realWidget.endIndent,
"color": realWidget.color != null
? realWidget.color!.value.toRadixString(16): null,
};

}

@override
Widget parse(Map<String, dynamic> map, BuildContext buildContext, ClickListener? listener) {

return Divider(
height: map["height"],
thickness: map["thickness"],
indent: map["indent"],
endIndent: map["endIndent"],
color: parseHexColor(map['color']),
);
}

@override
String get widgetName => "Divider";

@override
Type get widgetType => Divider;

}

0 comments on commit 29e3b95

Please sign in to comment.