From adc524ff9b93136e13b590eab63631ba42908254 Mon Sep 17 00:00:00 2001 From: Vinh Date: Wed, 30 Oct 2019 11:28:24 +0700 Subject: [PATCH] Implement basic TextFieldWidgetParser --- .gitignore | 15 +- example/lib/main.dart | 24 +- example/lib/widget_json.dart | 8 + lib/dynamic_widget.dart | 38 +++- lib/dynamic_widget/.DS_Store | Bin 0 -> 6148 bytes .../basic/align_widget_parser.dart | 4 +- .../basic/aspectratio_widget_parser.dart | 4 +- .../basic/baseline_widget_parser.dart | 4 +- .../basic/button_widget_parser.dart | 6 +- .../basic/center_widget_parser.dart | 4 +- .../basic/cliprrect_widget_parser.dart | 4 +- .../basic/container_widget_parser.dart | 8 +- .../basic/expanded_widget_parser.dart | 4 +- .../basic/fittedbox_widget_parser.dart | 4 +- .../basic/image_widget_parser.dart | 12 +- .../basic/indexedstack_widget_parser.dart | 4 +- .../basic/opacity_widget_parser.dart | 4 +- .../basic/padding_widget_parser.dart | 4 +- .../basic/placeholder_widget_parser.dart | 2 +- .../basic/row_column_widget_parser.dart | 8 +- .../basic/sizedbox_widget_parser.dart | 8 +- .../stack_positioned_widgets_parser.dart | 10 +- .../basic/text_field_widget_parser.dart | 23 ++ .../basic/text_widget_parser.dart | 14 +- .../basic/wrap_widget_parser.dart | 4 +- .../scrolling/gridview_widget_parser.dart | 4 +- .../scrolling/listview_widget_parser.dart | 4 +- .../scrolling/pageview_widget_parser.dart | 5 +- pubspec.lock | 209 ------------------ 29 files changed, 155 insertions(+), 287 deletions(-) create mode 100644 lib/dynamic_widget/.DS_Store create mode 100644 lib/dynamic_widget/basic/text_field_widget_parser.dart delete mode 100644 pubspec.lock diff --git a/.gitignore b/.gitignore index 446ed0d..9263e0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,19 @@ -.DS_Store -.dart_tool/ +# IntelliJ related +.idea/ + +# Visual Studio Code related +.vscode/ +# Flutter/Dart/Pub related +**/doc/api/ +.dart_tool/ +.flutter-plugins .packages +.pub-cache/ .pub/ +/build/ +pubspec.lock + build/ ios/.generated/ diff --git a/example/lib/main.dart b/example/lib/main.dart index a3f29c7..2aaa8cb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,4 +1,6 @@ import 'dart:async'; +import 'dart:collection'; +import 'dart:convert'; import 'package:dynamic_widget/dynamic_widget.dart'; import 'package:flutter/material.dart'; @@ -263,6 +265,15 @@ class _MyHomePageState extends State { builder: (context) => CodeEditorPage(cliprrectJson))); }, ), + RaisedButton( + child: Text("TextField"), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => CodeEditorPage(textFieldJson))); + }, + ), ], )); } @@ -332,6 +343,7 @@ class _CodeEditorPageState extends State { class PreviewPage extends StatelessWidget { final String jsonString; + final Map textEditingControllers = HashMap(); PreviewPage(this.jsonString); @@ -360,8 +372,16 @@ class PreviewPage extends StatelessWidget { } Future _buildWidget(BuildContext context) async { - return DynamicWidgetBuilder() - .build(jsonString, context, new DefaultClickListener()); + WidgetParserCompanion companion = WidgetParserCompanion(); + companion.clickListener = new DefaultClickListener(); + companion.onTextChange = (String id, String text) { + print("TextField id: $id, text $text"); + }; + companion.textEditingController = textEditingControllers; + var finalLayout = DynamicWidgetBuilder() + .build(jsonString, context, companion); + print("TextEditingController size ${textEditingControllers.length}"); + return finalLayout; } } diff --git a/example/lib/widget_json.dart b/example/lib/widget_json.dart index 3d0d998..a151823 100644 --- a/example/lib/widget_json.dart +++ b/example/lib/widget_json.dart @@ -886,3 +886,11 @@ var cliprrectJson = ''' } } '''; + +var textFieldJson = ''' +{ + "id": "text_field_test", + "type": "TextField", + "textColor": "#00FF00" +} +'''; diff --git a/lib/dynamic_widget.dart b/lib/dynamic_widget.dart index f999ec6..6c8ab49 100644 --- a/lib/dynamic_widget.dart +++ b/lib/dynamic_widget.dart @@ -1,5 +1,7 @@ library dynamic_widget; +import 'dart:convert'; + import 'package:dynamic_widget/dynamic_widget/basic/align_widget_parser.dart'; import 'package:dynamic_widget/dynamic_widget/basic/aspectratio_widget_parser.dart'; import 'package:dynamic_widget/dynamic_widget/basic/baseline_widget_parser.dart'; @@ -22,10 +24,10 @@ import 'package:dynamic_widget/dynamic_widget/scrolling/gridview_widget_parser.d import 'package:dynamic_widget/dynamic_widget/scrolling/listview_widget_parser.dart'; import 'package:dynamic_widget/dynamic_widget/scrolling/pageview_widget_parser.dart'; import 'package:flutter/widgets.dart'; -import 'dart:convert'; import 'package:logging/logging.dart'; import 'dynamic_widget/basic/cliprrect_widget_parser.dart'; +import 'dynamic_widget/basic/text_field_widget_parser.dart'; class DynamicWidgetBuilder { static final Logger log = Logger('DynamicWidget'); @@ -56,7 +58,8 @@ class DynamicWidgetBuilder { SizedBoxWidgetParser(), OpacityWidgetParser(), WrapWidgetParser(), - ClipRRectWidgetParser() + ClipRRectWidgetParser(), + TextFieldWidgetParser() ]; // use this method for adding your custom widget parser @@ -66,33 +69,34 @@ class DynamicWidgetBuilder { _parsers.add(parser); } - Widget build(String json, BuildContext buildContext, ClickListener listener) { + Widget build(String json, BuildContext buildContext, WidgetParserCompanion widgetParserCompanion) { + print("print widget 2"); var map = jsonDecode(json); - ClickListener _listener = - listener == null ? new NonResponseWidgetClickListener() : listener; - var widget = buildFromMap(map, buildContext, _listener); + if(widgetParserCompanion == null) widgetParserCompanion = WidgetParserCompanion(); + widgetParserCompanion.clickListener = + widgetParserCompanion.clickListener == null ? new NonResponseWidgetClickListener() : widgetParserCompanion.clickListener; + var widget = buildFromMap(map, buildContext, widgetParserCompanion); return widget; } static Widget buildFromMap(Map map, - BuildContext buildContext, ClickListener listener) { + BuildContext buildContext, WidgetParserCompanion widgetParserCompanion) { String widgetName = map['type']; for (var parser in _parsers) { if (parser.forWidget(widgetName)) { - return parser.parse(map, buildContext, listener); + return parser.parse(map, buildContext, widgetParserCompanion); } } - log.warning("Not support type: $widgetName"); return null; } static List buildWidgets( - List values, BuildContext buildContext, ClickListener listener) { + List values, BuildContext buildContext, WidgetParserCompanion widgetParserCompanion) { List rt = []; for (var value in values) { - rt.add(buildFromMap(value, buildContext, listener)); + rt.add(buildFromMap(value, buildContext, widgetParserCompanion)); } return rt; } @@ -102,7 +106,7 @@ class DynamicWidgetBuilder { abstract class WidgetParser { /// parse the json map into a flutter widget. Widget parse(Map map, BuildContext buildContext, - ClickListener listener); + WidgetParserCompanion widgetParserCompanion); /// check the matched widget type. for example: /// {"type" : "Text", "data" : "Denny"} @@ -116,6 +120,10 @@ abstract class ClickListener { void onClicked(String event); } +abstract class OnTextChangeListener { + void onTextChange(String textFieldId, String text); +} + class NonResponseWidgetClickListener implements ClickListener { static final Logger log = Logger('NonResponseWidgetClickListener'); @@ -125,3 +133,9 @@ class NonResponseWidgetClickListener implements ClickListener { print("receiver click event: " + event); } } + +class WidgetParserCompanion { + ClickListener clickListener; + Function(String,String) onTextChange; + Map textEditingController; +} \ No newline at end of file diff --git a/lib/dynamic_widget/.DS_Store b/lib/dynamic_widget/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8878035e580c57ac0eca10a6041249e36f9b5a12 GIT binary patch literal 6148 zcmeHK&1%~~5Z?7qDpgPvD71kd7JBH#hq$eit5D;d0tr=U4r%MIDp3oBWF$F07=y?I z~E>^GX7ne~1$J6gsV_s3C}F_$rBfg(0+82%tQ zkGdcY<3Z%A#`kbij>0q#7h=irZ!&=IuFXOwS;-Q1`~6*oqckb2)z#m;(QLJso>=x% z$9A4M_LpFoPl8HTG0}sl;HS_FXUjP6A literal 0 HcmV?d00001 diff --git a/lib/dynamic_widget/basic/align_widget_parser.dart b/lib/dynamic_widget/basic/align_widget_parser.dart index 077e05e..ce0e971 100644 --- a/lib/dynamic_widget/basic/align_widget_parser.dart +++ b/lib/dynamic_widget/basic/align_widget_parser.dart @@ -10,7 +10,7 @@ class AlignWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Align( alignment: map.containsKey("alignment") ? parseAlignment(map["alignment"]) @@ -19,7 +19,7 @@ class AlignWidgetParser extends WidgetParser { heightFactor: map.containsKey("heightFactor") ? map["heightFactor"] : null, child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/aspectratio_widget_parser.dart b/lib/dynamic_widget/basic/aspectratio_widget_parser.dart index b490f1c..10da35c 100644 --- a/lib/dynamic_widget/basic/aspectratio_widget_parser.dart +++ b/lib/dynamic_widget/basic/aspectratio_widget_parser.dart @@ -9,11 +9,11 @@ class AspectRatioWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return AspectRatio( aspectRatio: map["aspectRatio"], child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/baseline_widget_parser.dart b/lib/dynamic_widget/basic/baseline_widget_parser.dart index 4681cae..24522dd 100644 --- a/lib/dynamic_widget/basic/baseline_widget_parser.dart +++ b/lib/dynamic_widget/basic/baseline_widget_parser.dart @@ -9,14 +9,14 @@ class BaselineWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Baseline( baseline: map["baseline"], baselineType: map["baselineType"] == "alphabetic" ? TextBaseline.alphabetic : TextBaseline.ideographic, child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/button_widget_parser.dart b/lib/dynamic_widget/basic/button_widget_parser.dart index 738216c..9f5e496 100644 --- a/lib/dynamic_widget/basic/button_widget_parser.dart +++ b/lib/dynamic_widget/basic/button_widget_parser.dart @@ -10,7 +10,7 @@ class RaisedButtonParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { String clickEvent = map.containsKey("click_event") ? map['click_event'] : ""; @@ -34,9 +34,9 @@ class RaisedButtonParser extends WidgetParser { textColor: map.containsKey('textColor') ? parseHexColor(map['textColor']) : null, child: DynamicWidgetBuilder.buildFromMap( - map['child'], buildContext, listener), + map['child'], buildContext, widgetParserCompanion), onPressed: () { - listener.onClicked(clickEvent); + widgetParserCompanion.clickListener.onClicked(clickEvent); }, ); diff --git a/lib/dynamic_widget/basic/center_widget_parser.dart b/lib/dynamic_widget/basic/center_widget_parser.dart index e343380..e03db28 100644 --- a/lib/dynamic_widget/basic/center_widget_parser.dart +++ b/lib/dynamic_widget/basic/center_widget_parser.dart @@ -9,13 +9,13 @@ class CenterWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Center( widthFactor: map.containsKey("widthFactor") ? map["widthFactor"] : null, heightFactor: map.containsKey("heightFactor") ? map["heightFactor"] : null, child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/cliprrect_widget_parser.dart b/lib/dynamic_widget/basic/cliprrect_widget_parser.dart index 81fd7a2..535acee 100644 --- a/lib/dynamic_widget/basic/cliprrect_widget_parser.dart +++ b/lib/dynamic_widget/basic/cliprrect_widget_parser.dart @@ -10,7 +10,7 @@ class ClipRRectWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { var radius = map['borderRadius'].toString().split(","); double topLeft = double.parse(radius[0]); double topRight = double.parse(radius[1]); @@ -25,7 +25,7 @@ class ClipRRectWidgetParser extends WidgetParser { bottomRight: Radius.circular(bottomRight)), clipBehavior: parseClipBehavior(clipBehaviorString), child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/container_widget_parser.dart b/lib/dynamic_widget/basic/container_widget_parser.dart index 07c17b8..ab6c4bf 100644 --- a/lib/dynamic_widget/basic/container_widget_parser.dart +++ b/lib/dynamic_widget/basic/container_widget_parser.dart @@ -10,7 +10,7 @@ class ContainerWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { Alignment alignment = parseAlignment(map['alignment']); Color color = parseHexColor(map['color']); BoxConstraints constraints = parseBoxConstraints(map['constraints']); @@ -20,7 +20,7 @@ class ContainerWidgetParser extends WidgetParser { Map childMap = map['child']; Widget child = childMap == null ? null - : DynamicWidgetBuilder.buildFromMap(childMap, buildContext, listener); + : DynamicWidgetBuilder.buildFromMap(childMap, buildContext, widgetParserCompanion); String clickEvent = map.containsKey("click_event") ? map['click_event'] : ""; @@ -36,10 +36,10 @@ class ContainerWidgetParser extends WidgetParser { child: child, ); - if (listener != null && clickEvent != null) { + if (widgetParserCompanion.clickListener != null && clickEvent != null) { return GestureDetector( onTap: () { - listener.onClicked(clickEvent); + widgetParserCompanion.clickListener.onClicked(clickEvent); }, child: containerWidget, ); diff --git a/lib/dynamic_widget/basic/expanded_widget_parser.dart b/lib/dynamic_widget/basic/expanded_widget_parser.dart index 13e4705..29e5a95 100644 --- a/lib/dynamic_widget/basic/expanded_widget_parser.dart +++ b/lib/dynamic_widget/basic/expanded_widget_parser.dart @@ -9,10 +9,10 @@ class ExpandedWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Expanded( child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), flex: map.containsKey("flex") ? map["flex"] : 1, ); } diff --git a/lib/dynamic_widget/basic/fittedbox_widget_parser.dart b/lib/dynamic_widget/basic/fittedbox_widget_parser.dart index b790966..e4ad861 100644 --- a/lib/dynamic_widget/basic/fittedbox_widget_parser.dart +++ b/lib/dynamic_widget/basic/fittedbox_widget_parser.dart @@ -10,14 +10,14 @@ class FittedBoxWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return FittedBox( alignment: map.containsKey("alignment") ? parseAlignment(map["alignment"]) : Alignment.center, fit: map.containsKey("fit") ? parseBoxFit(map["fit"]) : BoxFit.contain, child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/image_widget_parser.dart b/lib/dynamic_widget/basic/image_widget_parser.dart index 4c4d868..a22f7e9 100644 --- a/lib/dynamic_widget/basic/image_widget_parser.dart +++ b/lib/dynamic_widget/basic/image_widget_parser.dart @@ -12,7 +12,7 @@ class AssetImageWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { String name = map['name']; String semanticLabel = map.containsKey('semanticLabel') ? map['semanticLabel'] : null; @@ -65,10 +65,10 @@ class AssetImageWidgetParser extends WidgetParser { filterQuality: filterQuality, ); - if (listener != null && (clickEvent != null && clickEvent.isNotEmpty)) { + if (widgetParserCompanion.clickListener != null && (clickEvent != null && clickEvent.isNotEmpty)) { return GestureDetector( onTap: () { - listener.onClicked(clickEvent); + widgetParserCompanion.clickListener.onClicked(clickEvent); }, child: widget, ); @@ -85,7 +85,7 @@ class NetworkImageWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { String src = map['src']; String semanticLabel = map.containsKey('semanticLabel') ? map['semanticLabel'] : null; @@ -138,10 +138,10 @@ class NetworkImageWidgetParser extends WidgetParser { filterQuality: filterQuality, ); - if (listener != null && (clickEvent != null && clickEvent.isNotEmpty)) { + if (widgetParserCompanion.clickListener != null && (clickEvent != null && clickEvent.isNotEmpty)) { return GestureDetector( onTap: () { - listener.onClicked(clickEvent); + widgetParserCompanion.clickListener.onClicked(clickEvent); }, child: widget, ); diff --git a/lib/dynamic_widget/basic/indexedstack_widget_parser.dart b/lib/dynamic_widget/basic/indexedstack_widget_parser.dart index 3f742e7..a5a10d3 100644 --- a/lib/dynamic_widget/basic/indexedstack_widget_parser.dart +++ b/lib/dynamic_widget/basic/indexedstack_widget_parser.dart @@ -10,7 +10,7 @@ class IndexedStackWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return IndexedStack( index: map.containsKey("index") ? map["index"] : 0, alignment: map.containsKey("alignment") @@ -20,7 +20,7 @@ class IndexedStackWidgetParser extends WidgetParser { ? parseTextDirection(map["textDirection"]) : null, children: DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener), + map['children'], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/opacity_widget_parser.dart b/lib/dynamic_widget/basic/opacity_widget_parser.dart index 37d724c..421b40c 100644 --- a/lib/dynamic_widget/basic/opacity_widget_parser.dart +++ b/lib/dynamic_widget/basic/opacity_widget_parser.dart @@ -9,14 +9,14 @@ class OpacityWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Opacity( opacity: map["opacity"], alwaysIncludeSemantics: map.containsKey("alwaysIncludeSemantics") ? map["alwaysIncludeSemantics"] : false, child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/padding_widget_parser.dart b/lib/dynamic_widget/basic/padding_widget_parser.dart index 072ccfb..f05e39c 100644 --- a/lib/dynamic_widget/basic/padding_widget_parser.dart +++ b/lib/dynamic_widget/basic/padding_widget_parser.dart @@ -10,13 +10,13 @@ class PaddingWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Padding( padding: map.containsKey("padding") ? parseEdgeInsetsGeometry(map["padding"]) : null, child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/placeholder_widget_parser.dart b/lib/dynamic_widget/basic/placeholder_widget_parser.dart index ca1d657..555943d 100644 --- a/lib/dynamic_widget/basic/placeholder_widget_parser.dart +++ b/lib/dynamic_widget/basic/placeholder_widget_parser.dart @@ -10,7 +10,7 @@ class PlaceholderWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Placeholder( color: map.containsKey('color') ? parseHexColor(map['color']) diff --git a/lib/dynamic_widget/basic/row_column_widget_parser.dart b/lib/dynamic_widget/basic/row_column_widget_parser.dart index d3cb979..0dd977e 100644 --- a/lib/dynamic_widget/basic/row_column_widget_parser.dart +++ b/lib/dynamic_widget/basic/row_column_widget_parser.dart @@ -10,7 +10,7 @@ class RowWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Row( crossAxisAlignment: map.containsKey('crossAxisAlignment') ? parseCrossAxisAlignment(map['crossAxisAlignment']) @@ -31,7 +31,7 @@ class RowWidgetParser extends WidgetParser { ? parseVerticalDirection(map['verticalDirection']) : VerticalDirection.down, children: DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener), + map['children'], buildContext, widgetParserCompanion), ); } } @@ -44,7 +44,7 @@ class ColumnWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Column( crossAxisAlignment: map.containsKey('crossAxisAlignment') ? parseCrossAxisAlignment(map['crossAxisAlignment']) @@ -65,7 +65,7 @@ class ColumnWidgetParser extends WidgetParser { ? parseVerticalDirection(map['verticalDirection']) : VerticalDirection.down, children: DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener), + map['children'], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/sizedbox_widget_parser.dart b/lib/dynamic_widget/basic/sizedbox_widget_parser.dart index cdb47db..52a0020 100644 --- a/lib/dynamic_widget/basic/sizedbox_widget_parser.dart +++ b/lib/dynamic_widget/basic/sizedbox_widget_parser.dart @@ -10,10 +10,10 @@ class ExpandedSizedBoxWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return SizedBox.expand( child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } @@ -26,12 +26,12 @@ class SizedBoxWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return SizedBox( width: map["width"], height: map["height"], child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/stack_positioned_widgets_parser.dart b/lib/dynamic_widget/basic/stack_positioned_widgets_parser.dart index bf5245e..ab6ece3 100644 --- a/lib/dynamic_widget/basic/stack_positioned_widgets_parser.dart +++ b/lib/dynamic_widget/basic/stack_positioned_widgets_parser.dart @@ -1,5 +1,5 @@ -import 'package:dynamic_widget/dynamic_widget/utils.dart'; import 'package:dynamic_widget/dynamic_widget.dart'; +import 'package:dynamic_widget/dynamic_widget/utils.dart'; import 'package:flutter/widgets.dart'; class PositionedWidgetParser extends WidgetParser { @@ -10,10 +10,10 @@ class PositionedWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Positioned( child: DynamicWidgetBuilder.buildFromMap( - map["child"], buildContext, listener), + map["child"], buildContext, widgetParserCompanion), top: map.containsKey("top") ? map["top"] : null, right: map.containsKey("right") ? map["right"] : null, bottom: map.containsKey("bottom") ? map["bottom"] : null, @@ -32,7 +32,7 @@ class StackWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Stack( alignment: map.containsKey("alignment") ? parseAlignment(map["alignment"]) @@ -45,7 +45,7 @@ class StackWidgetParser extends WidgetParser { ? parseOverflow(map["overflow"]) : Overflow.clip, children: DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener), + map['children'], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/basic/text_field_widget_parser.dart b/lib/dynamic_widget/basic/text_field_widget_parser.dart new file mode 100644 index 0000000..d574547 --- /dev/null +++ b/lib/dynamic_widget/basic/text_field_widget_parser.dart @@ -0,0 +1,23 @@ +import 'package:dynamic_widget/dynamic_widget.dart'; +import 'package:dynamic_widget/dynamic_widget/utils.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +class TextFieldWidgetParser implements WidgetParser { + Widget parse(Map map, BuildContext buildContext, + WidgetParserCompanion widgetParserCompanion) { + String id = map['id']; + TextEditingController textEditingController = TextEditingController(); + widgetParserCompanion.textEditingController.putIfAbsent(id, () { + return textEditingController; + }); + return TextField( + controller: widgetParserCompanion.textEditingController[id], + style: TextStyle(color: parseHexColor(map['textColor'])), + onChanged: (text) => widgetParserCompanion?.onTextChange(id, text)); + } + + bool forWidget(String widgetName) { + return "TextField" == widgetName; + } +} diff --git a/lib/dynamic_widget/basic/text_widget_parser.dart b/lib/dynamic_widget/basic/text_widget_parser.dart index 34aad5e..0fd4402 100644 --- a/lib/dynamic_widget/basic/text_widget_parser.dart +++ b/lib/dynamic_widget/basic/text_widget_parser.dart @@ -11,7 +11,7 @@ class TextWidgetParser implements WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { String data = map['data']; String textAlignString = map['textAlign']; String overflow = map['overflow']; @@ -23,7 +23,7 @@ class TextWidgetParser implements WidgetParser { var textSpan; var textSpanParser = TextSpanParser(); if (map.containsKey("textSpan")) { - textSpan = textSpanParser.parse(map['textSpan'], listener); + textSpan = textSpanParser.parse(map['textSpan'], widgetParserCompanion); } if (textSpan == null) { @@ -55,28 +55,28 @@ class TextWidgetParser implements WidgetParser { } class TextSpanParser { - TextSpan parse(Map map, ClickListener listener) { + TextSpan parse(Map map, WidgetParserCompanion widgetParserCompanion) { String clickEvent = map.containsKey("recognizer") ? map['recognizer'] : ""; var textSpan = TextSpan( text: map['text'], style: parseTextStyle(map['style']), recognizer: TapGestureRecognizer() ..onTap = () { - listener.onClicked(clickEvent); + widgetParserCompanion.clickListener.onClicked(clickEvent); }, children: []); if (map.containsKey('children')) { - parseChildren(textSpan, map['children'], listener); + parseChildren(textSpan, map['children'], widgetParserCompanion); } return textSpan; } void parseChildren( - TextSpan textSpan, List childrenSpan, ClickListener listener) { + TextSpan textSpan, List childrenSpan, WidgetParserCompanion widgetParserCompanion) { for (var childmap in childrenSpan) { - textSpan.children.add(parse(childmap, listener)); + textSpan.children.add(parse(childmap, widgetParserCompanion)); } } } diff --git a/lib/dynamic_widget/basic/wrap_widget_parser.dart b/lib/dynamic_widget/basic/wrap_widget_parser.dart index 4fc287c..8f813f3 100644 --- a/lib/dynamic_widget/basic/wrap_widget_parser.dart +++ b/lib/dynamic_widget/basic/wrap_widget_parser.dart @@ -10,7 +10,7 @@ class WrapWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { return Wrap( direction: map.containsKey("direction") ? parseAxis(map["direction"]) @@ -33,7 +33,7 @@ class WrapWidgetParser extends WidgetParser { ? parseVerticalDirection(map["verticalDirection"]) : VerticalDirection.down, children: DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener), + map['children'], buildContext, widgetParserCompanion), ); } } diff --git a/lib/dynamic_widget/scrolling/gridview_widget_parser.dart b/lib/dynamic_widget/scrolling/gridview_widget_parser.dart index c3a2428..55ffc66 100644 --- a/lib/dynamic_widget/scrolling/gridview_widget_parser.dart +++ b/lib/dynamic_widget/scrolling/gridview_widget_parser.dart @@ -15,7 +15,7 @@ class GridViewWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { var scrollDirection = Axis.vertical; if (map.containsKey("scrollDirection") && "horizontal" == map[""]) { scrollDirection = Axis.horizontal; @@ -35,7 +35,7 @@ class GridViewWidgetParser extends WidgetParser { double childAspectRatio = map.containsKey('childAspectRatio') ? map['childAspectRatio'] : 1.0; var children = DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener); + map['children'], buildContext, widgetParserCompanion); var pageSize = map.containsKey("pageSize") ? map["pageSize"] : 10; var loadMoreUrl = diff --git a/lib/dynamic_widget/scrolling/listview_widget_parser.dart b/lib/dynamic_widget/scrolling/listview_widget_parser.dart index 6cdee19..74a1486 100644 --- a/lib/dynamic_widget/scrolling/listview_widget_parser.dart +++ b/lib/dynamic_widget/scrolling/listview_widget_parser.dart @@ -15,7 +15,7 @@ class ListViewWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { var scrollDirection = Axis.vertical; if (map.containsKey("scrollDirection") && "horizontal" == map[""]) { scrollDirection = Axis.horizontal; @@ -29,7 +29,7 @@ class ListViewWidgetParser extends WidgetParser { : null; var itemExtent = map.containsKey("itemExtent") ? map["itemExtent"] : null; var children = DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener); + map['children'], buildContext, widgetParserCompanion); var pageSize = map.containsKey("pageSize") ? map["pageSize"] : 10; var loadMoreUrl = map.containsKey("loadMoreUrl") ? map["loadMoreUrl"] : null; diff --git a/lib/dynamic_widget/scrolling/pageview_widget_parser.dart b/lib/dynamic_widget/scrolling/pageview_widget_parser.dart index 0507d79..edee911 100644 --- a/lib/dynamic_widget/scrolling/pageview_widget_parser.dart +++ b/lib/dynamic_widget/scrolling/pageview_widget_parser.dart @@ -1,6 +1,7 @@ import 'package:dynamic_widget/dynamic_widget.dart'; import 'package:flutter/widgets.dart'; + class PageViewWidgetParser extends WidgetParser { @override bool forWidget(String widgetName) { @@ -9,7 +10,7 @@ class PageViewWidgetParser extends WidgetParser { @override Widget parse(Map map, BuildContext buildContext, - ClickListener listener) { + WidgetParserCompanion widgetParserCompanion) { var scrollDirection = Axis.horizontal; if (map.containsKey("scrollDirection")) { scrollDirection = map["scrollDirection"]; @@ -20,7 +21,7 @@ class PageViewWidgetParser extends WidgetParser { pageSnapping: map.containsKey("pageSnapping") ? map["pageSnapping"] : true, children: DynamicWidgetBuilder.buildWidgets( - map['children'], buildContext, listener), + map['children'], buildContext, widgetParserCompanion), ); } } diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 9a7121a..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,209 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.10" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.2" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.14.11" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - http: - dependency: "direct main" - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0+2" - http_parser: - dependency: transitive - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "3.1.3" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" - logging: - dependency: "direct main" - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+2" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.5" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.7" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.5" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.9.3" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.5" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.6" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" -sdks: - dart: ">=2.4.0 <3.0.0"