{"id":13552166,"url":"https://github.com/dengyin2000/dynamic_widget","last_synced_at":"2025-05-14T04:08:18.400Z","repository":{"id":37547769,"uuid":"167918394","full_name":"dengyin2000/dynamic_widget","owner":"dengyin2000","description":"A Backend-Driven UI toolkit, build your dynamic UI with json, and the json format is very similar with flutter widget code.","archived":false,"fork":false,"pushed_at":"2025-05-12T04:13:08.000Z","size":22626,"stargazers_count":1609,"open_issues_count":48,"forks_count":321,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-05-12T04:34:51.452Z","etag":null,"topics":["dynamic","dynamicwidget","flutter","widget"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dengyin2000.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-28T07:31:39.000Z","updated_at":"2025-05-12T04:13:12.000Z","dependencies_parsed_at":"2024-08-01T12:20:02.307Z","dependency_job_id":"9517cb08-2b33-49a6-974c-69f5663b507b","html_url":"https://github.com/dengyin2000/dynamic_widget","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengyin2000%2Fdynamic_widget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengyin2000%2Fdynamic_widget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengyin2000%2Fdynamic_widget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dengyin2000%2Fdynamic_widget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dengyin2000","download_url":"https://codeload.github.com/dengyin2000/dynamic_widget/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254069688,"owners_count":22009558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic","dynamicwidget","flutter","widget"],"created_at":"2024-08-01T12:01:59.995Z","updated_at":"2025-05-14T04:08:13.374Z","avatar_url":"https://github.com/dengyin2000.png","language":"Dart","readme":"[![Pub](https://img.shields.io/pub/v/dynamic_widget.svg?color=orange)](https://pub.dev/packages/dynamic_widget)\u0026nbsp;\n\u003ca href=\"https://github.com/Solido/awesome-flutter\"\u003e\n    \u003cimg alt=\"Awesome Flutter\" src=\"https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true\u0026style=flat-square\" /\u003e\n\u003c/a\u003e\n# Flutter Dynamic Widget\n\u003eA Backend-Driven UI toolkit, build your dynamic UI with json, and the json format is very similar with flutter widget code.\n\n**From 4.0.0-nullsafety.1 version, it supports null-safety.**\n\n**From 3.0.0 version, it supports exporting your flutter code to json code. please check [How to write the json code](#how-to-write-the-json-code)**\n\n**From 1.0.4 version, it supports flutter web application.**\n\n\n\n\n## Table of contents\n* [General info](#general-info)\n* [Screenshots](#screenshots)\n* [Install](#install)\n* [Get started](#get-started)\n* [How to implement a WidgetParser](#how-to-implement-a-widgetparser)\n* [How to add a click listener](#how-to-add-a-click-listener)\n* [How to write the json code](#how-to-write-the-json-code)\n* [Widget Documents](#widget-documents)\n* [Setup](#setup)\n* [Contact](#contact)\n\n## General info\n\n\u003e I work for an e-commerce company. We need to build flexible pages. So we define a light UI protocol, and implement on Android and iOS. We can dynamic update App UIs by pushing a json file. With this ability, we can do some UI A/B testing without publishing App to app store. Flutter allows you to build beautiful native apps on iOS and Android from a single codebase, it can allow you to build web app later. Flutter's hot reload helps you quickly and easily experiment, build UIs, add features, and fix bugs faster. But it still build native app, the UIs can't be dynamic updated. If you want to modify the UIs, you need to publish the updated app to app store. With this project, you can build your UIs from a json string, which is the UI protocol. The json string is very similar with the Flutter widget dart code. All widget type and widget properties are the same.\n\n\u003cimg src=\"https://github.com/dengyin2000/dynamic_widget/raw/master/img/Sample.png\" width=\"800\"\u003e\n\nWidget type will be a type property, and widget's properties will be the json properties too. All properties and their values will be almost the same. You can checkout the following document.\n\n[Currently support flutter widgets and properties](WIDGETS.md)\n\n## Screenshots\n\u003cimg src=\"https://github.com/dengyin2000/dynamic_widget/raw/master/img/demo1.gif\" width=\"400\"\u003e\n\n## Install\n#### 1. Depend on it\nAdd this to your package's pubspec.yaml file:\n```\ndependencies:\n  dynamic_widget: ^3.0.3\n```\n\n#### 2. Install it\nYou can install packages from the command line:\n\nwith Flutter:\n```\n$ flutter packages get\n```\n\nAlternatively, your editor might support `flutter packages get`. Check the docs for your editor to learn more.\n\n#### 3. Import it\nNow in your Dart code, you can use:\n```dart\nimport 'package:dynamic_widget/dynamic_widget.dart';\n```\n\n## Get started\nYou should use `DynamicWidgetBuilder().build` method to covert a json string into flutter widget. It will be time-consuming. so you'd better using `FutureBuilder` to build the UI.\n\n```dart\nimport 'package:dynamic_widget/dynamic_widget.dart';\nclass PreviewPage extends StatelessWidget {\n  final String jsonString;\n\n  PreviewPage(this.jsonString);\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        // Here we take the value from the MyHomePage object that was created by\n        // the App.build method, and use it to set our appbar title.\n        title: Text(\"Preview\"),\n      ),\n      body: FutureBuilder\u003cWidget\u003e(\n        future: _buildWidget(context),\n        builder: (BuildContext context, AsyncSnapshot\u003cWidget\u003e snapshot) {\n          if (snapshot.hasError) {\n            print(snapshot.error);\n          }\n          return snapshot.hasData\n              ? SizedBox.expand(\n                  child: snapshot.data,\n                )\n              : Text(\"Loading...\");\n        },\n      ),\n    );\n  }\n\n  Future\u003cWidget\u003e _buildWidget(BuildContext context) async {\n    return DynamicWidgetBuilder.build(jsonString, context, new DefaultClickListener());\n  }\n}\n```\n## How to implement a WidgetParser\n1. You need to implement the `WidgetParser` abstract class.\n2. Add new created WidgetParser by `DynamicWidgetBuilder.addParser(WidgetParser parser)` method.\n\nThis is a RaisedButton widget parser.\n```dart\nimport 'package:dynamic_widget/dynamic_widget/utils.dart';\nimport 'package:dynamic_widget/dynamic_widget.dart';\nimport 'package:flutter/material.dart';\n\nclass RaisedButtonParser extends WidgetParser {\n  @override\n  String get widgetName =\u003e \"RaisedButton\";\n\n  @override\n  Widget parse(Map\u003cString, dynamic\u003e map, BuildContext buildContext, ClickListener listener) {\n    String clickEvent =\n        map.containsKey(\"click_event\") ? map['click_event'] : \"\";\n\n    var raisedButton = RaisedButton(\n      color: map.containsKey('color') ? parseHexColor(map['color']) : null,\n      disabledColor: map.containsKey('disabledColor')\n          ? parseHexColor(map['disabledColor'])\n          : null,\n      disabledElevation:\n          map.containsKey('disabledElevation') ? map['disabledElevation']?.toDouble() : 0.0,\n      disabledTextColor: map.containsKey('disabledTextColor')\n          ? parseHexColor(map['disabledTextColor'])\n          : null,\n      elevation: map.containsKey('elevation') ? map['elevation']?.toDouble() : 0.0,\n      padding: map.containsKey('padding')\n          ? parseEdgeInsetsGeometry(map['padding'])\n          : null,\n      splashColor: map.containsKey('splashColor')\n          ? parseHexColor(map['splashColor'])\n          : null,\n      textColor:\n          map.containsKey('textColor') ? parseHexColor(map['textColor']) : null,\n      child: DynamicWidgetBuilder.buildFromMap(map['child'], buildContext, listener),\n      onPressed: () {\n        listener.onClicked(clickEvent);\n      },\n    );\n\n    return raisedButton;\n  }\n}\n```\n\nAdd it to parsers list.\n```dart\nDynamicWidgetBuilder.addParser(RaisedButtonParser());\n```\n## How to add a click listener\nAdd \"click_event\" property to your widget json definition. for example:\n```dart\nvar raisedButton_json =\n'''\n{\n  \"type\": \"Container\",\n  \"alignment\": \"center\",\n  \"child\": {\n    \"type\": \"RaisedButton\",\n    \"color\": \"##FF00FF\",\n    \"padding\": \"8,8,8,8\",\n    \"textColor\": \"#00FF00\",\n    \"elevation\" : 8.0,\n    \"splashColor\" : \"#00FF00\",\n    \"click_event\" : \"route://productDetail?goods_id=123\",\n    \"child\" : {\n      \"type\": \"Text\",\n      \"data\": \"I am a button\"\n    }\n  }\n}\n```\n\nWe suggest you'd better to use an URI to define the event, as the exmaple, it's a event for going to a product detail page.\n\nThen, define a ClickListener\n```dart\nclass DefaultClickListener implements ClickListener{\n  @override\n  void onClicked(String event) {\n    print(\"Receive click event: \" + event);\n  }\n\n}\n```\n\nFinally, pass the listener to build method.\n```dart\n  Future\u003cWidget\u003e _buildWidget() async{\n\n    return DynamicWidgetBuilder.build(jsonString, buildContext, new DefaultClickListener());\n  }\n```\n\n## How to write the json code\nYou don't need to write the json code by hand, you can export your flutter code to json code efficiently with DynamicWidgetJsonExportor widget. You just need to wrap your flutter code with DynamicWidgetJsonExportor widget, then invoke its `exportJsonString()` method, look at following example, click the \"export\" button, it will find the DynamicWidgetJsonExportor widget, and export its child to json code efficiently.\n\n```dart\nclass _JSONExporterState extends State\u003cJSONExporter\u003e {\n  GlobalKey key = GlobalKey();\n\n  @override\n  Widget build(BuildContext context) {\n    return Scaffold(\n      appBar: AppBar(\n        // Here we take the value from the MyHomePage object that was created by\n        // the App.build method, and use it to set our appbar title.\n        title: Text(\"export example\"),\n      ),\n      body: Builder(\n        builder: (context) =\u003e Column(\n          children: [\n            Expanded(\n              child: DynamicWidgetJsonExportor(\n                key: key,\n                child: Container(\n                  child: GridViewWidget(\n                      GridViewParams(\n                          mainAxisSpacing: 2.0,\n                          crossAxisSpacing: 2.0,\n                          crossAxisCount: 2,\n                          childAspectRatio: 1.6,\n                          padding: EdgeInsets.all(10.0),\n                          pageSize: 10,\n                          children: [\n                            ListTile(\n                              leading: Text(\"Leading text\"),\n                              title: Text(\"title\"),\n                              subtitle: Text(\"subtitle\"),\n                            ),\n                            ListTile(\n                              leading: Text(\"Leading text\"),\n                              title: Text(\"title\"),\n                              subtitle: Text(\"subtitle\"),\n                            )\n                          ]),\n                      context),\n                ),\n              ),\n            ),\n            RaisedButton(\n              child: Text(\"Export\"),\n              onPressed: () {\n                var exportor = key.currentWidget as DynamicWidgetJsonExportor;\n                var exportJsonString = exportor.exportJsonString();\n                Scaffold.of(context).showSnackBar(SnackBar(\n                    content: Text(\"json string was exported to editor page.\")));\n                Future.delayed(Duration(seconds: 3), (){\n                  Navigator.push(\n                      context,\n                      MaterialPageRoute(\n                          builder: (context) =\u003e\n                              CodeEditorPage(exportJsonString)));\n                });\n              },\n            )\n          ],\n        ),\n      ),\n    );\n  }\n}\n```\nYou can use whatever your favorite IDE to build the UI, then use DynamicWidgetJsonExportor to export to json code. For detail, please check the Dynamic Widget Demo source code.\n\n\u003cimg src=\"./img/export.gif\" width=\"320\"\u003e\n\n\n## Widget Documents\nAlready completed widgets:\n* [Container](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#container-widget)\n* [Text](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#text-widget)\n* [TextSpan](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#textspan)\n* [TextStyle](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#textstyle)\n* [RaisedButton](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#raisedbutton-widget)\n* [ElevatedButton](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#elevatedbutton-widget)\n* [TextButton](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#textbutton-widget)\n* [Row](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#row-widget)\n* [Column](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#column-widget)\n* [AssetImage](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#assetimage-widget)\n* [NetworkImage](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#networkimage-widget)\n* [FileImage](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#fileimage-widget)\n* [Placeholder](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#placeholder-widget)\n* [GridView](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#gridview-widget)\n* [ListView](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#listview-widget)\n* [PageView](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#pageview-widget)\n* [Expanded](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#expanded-widget)\n* [Padding](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#padding-widget)\n* [Center](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#center-widget)\n* [Align](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#align-widget)\n* [AspectRatio](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#aspectratio-widget)\n* [FittedBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#fittedbox-widget)\n* [Baseline](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#baseline-widget)\n* [Stack](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#stack-widget)\n* [Positioned](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#positioned-widget)\n* [IndexedStack](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#indexedstack-widget)\n* [ExpandedSizedBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#expandedsizedbox-widget)\n* [SizedBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#sizedbox-widget)\n* [Opacity](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#opacity-widget)\n* [Wrap](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#wrap-widget)\n* [ClipRRect](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#cliprrect-widget)\n* [SafeArea](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#safearea-widget)\n* [SelectableText](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#selectabletext-widget)\n* [Icon](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#icon-widget)\n* [DropCapText](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#dropcaptext-widget)\n* [Scaffold](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#scaffold-widget)\n* [AppBar](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#appbar-widget)\n* [LimitedBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#limitedbox-widget)\n* [Offstage](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#offstage-widget)\n* [OverflowBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#overflowbox-widget)\n* [Divider](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#divider-widget)\n* [RotatedBox](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#rotatedbox-widget)\n* [SingleChildScrollView](https://github.com/dengyin2000/dynamic_widget/blob/master/WIDGETS.md#singlechildscrollview-widget)\n\nYou can view [Currently support widgets and properties](WIDGETS.md) here.\n\n## Setup\nCheckout this project and run demo.\n\n## Code Examples\nCheckout this project and run demo.\n\n## Contact\nCreated by [@deng.yin@gmail.com](https://www.jianshu.com/u/efa51344ce61) - feel free to contact me","funding_links":[],"categories":["组件","Dart","UI [🔝](#readme)","Components"],"sub_categories":["UI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdengyin2000%2Fdynamic_widget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdengyin2000%2Fdynamic_widget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdengyin2000%2Fdynamic_widget/lists"}