widgetToJson function

Map widgetToJson({
  1. required Widget widget,
  2. Widget? notSupportedWidget,
})

Implementation

Map widgetToJson({
  required material_widget.Widget widget,
  material_widget.Widget? notSupportedWidget,
}) {
  Map jsonData = {
    "@type": widget.runtimeType.toString(),
  };

  if (widget is material_widget.MaterialApp) {
    material_widget.MaterialApp widget_procces = widget;
    jsonData["home"] = widget_procces.home.toJson();
  } else if (widget is material_widget.Scaffold) {
    material_widget.Scaffold widget_procces = widget;

    jsonData["body"] = widget.body.toJson();
  } else if (widget is material_widget.Center) {
    material_widget.Center widget_procces = widget;
    jsonData["child"] = widget.child.toJson();
  } else if (widget is material_widget.Text) {
    material_widget.Text widget_procces = widget;
    jsonData["data"] = widget.data;
  } else if (widget is material_widget.Column ||
      widget is material_widget.Row) {
    List<Map> children = [];
    if (widget is material_widget.Column) {
      material_widget.Column widget_procces = widget;
      for (var element in widget_procces.children) {
        children.add(element.toJson());
      }
    } else if (widget is material_widget.Row) {
      material_widget.Row widget_procces = widget;
      for (var element in widget_procces.children) {
        children.add(element.toJson());
      }
    }
    jsonData["children"] = children;
  } else {
    if (notSupportedWidget != null) {
      notSupportedWidget.toJson().forEach((key, value) {
        jsonData[key] = value;
      });
    } else {
      widget.toMap().forEach((key, value) {
        jsonData[key] = value;
      });
    }
  }
  return jsonData;
}