dynamic_widget 1.0.6

Pub  Awesome Flutter

Flutter Dynamic Widget #

A Backend-Driven UI toolkit, build your dynamic UI with json, and the json format is very similar with flutter widget code.

From 1.0.4 version, it supports flutter web application.

Table of contents #

General info #

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 protocal. The json string is very similar with the Flutter widget dart code. All widget type and widget properties are the same.

Widget 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.

Currently support flutter widgets and properties

Screenshots #

Install #

1. Depend on it #

Add this to your package's pubspec.yaml file:

  dynamic_widget: ^0.0.3

2. Install it #

You can install packages from the command line:

with Flutter:

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it #

Now in your Dart code, you can use:

import 'package:dynamic_widget/dynamic_widget.dart';

Get started #

You 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.

import 'package:dynamic_widget/dynamic_widget.dart';
class PreviewPage extends StatelessWidget {
  final String jsonString;


  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text("Preview"),
      body: FutureBuilder<Widget>(
        future: _buildWidget(context),
        builder: (BuildContext context, AsyncSnapshot<Widget> snapshot) {
          if (snapshot.hasError) {
          return snapshot.hasData
              ? SizedBox.expand(
                  child: snapshot.data,
              : Text("Loading...");

  Future<Widget> _buildWidget(BuildContext context) async {
    return DynamicWidgetBuilder().build(jsonString, context, new DefaultClickListener());

How to implement a WidgetParser #

  1. You need to implement the WidgetParser abstract class.
  2. Add new created WidgetParser by DynamicWidgetBuilder.addParser(WidgetParser parser) method.

This is a RaisedButton widget parser.

import 'package:dynamic_widget/dynamic_widget/utils.dart';
import 'package:dynamic_widget/dynamic_widget.dart';
import 'package:flutter/material.dart';

class RaisedButtonParser extends WidgetParser {
  bool forWidget(String widgetName) {
    return "RaisedButton" == widgetName;

  Widget parse(Map<String, dynamic> map, BuildContext buildContext, ClickListener listener) {
    String clickEvent =
        map.containsKey("click_event") ? map['click_event'] : "";

    var raisedButton = RaisedButton(
      color: map.containsKey('color') ? parseHexColor(map['color']) : null,
      disabledColor: map.containsKey('disabledColor')
          ? parseHexColor(map['disabledColor'])
          : null,
          map.containsKey('disabledElevation') ? map['disabledElevation'] : 0.0,
      disabledTextColor: map.containsKey('disabledTextColor')
          ? parseHexColor(map['disabledTextColor'])
          : null,
      elevation: map.containsKey('elevation') ? map['elevation'] : 0.0,
      padding: map.containsKey('padding')
          ? parseEdgeInsetsGeometry(map['padding'])
          : null,
      splashColor: map.containsKey('splashColor')
          ? parseHexColor(map['splashColor'])
          : null,
          map.containsKey('textColor') ? parseHexColor(map['textColor']) : null,
      child: DynamicWidgetBuilder.buildFromMap(map['child'], buildContext, listener),
      onPressed: () {

    return raisedButton;

Add it to parsers list.


How to add a click listener #

Add "click_event" property to your widget json definition. for example:

var raisedButton_json =
  "type": "Container",
  "alignment": "center",
  "child": {
    "type": "RaisedButton",
    "color": "##FF00FF",
    "padding": "8,8,8,8",
    "textColor": "#00FF00",
    "elevation" : 8.0,
    "splashColor" : "#00FF00",
    "click_event" : "route://productDetail?goods_id=123",
    "child" : {
      "type": "Text",
      "data": "I am a button"

We 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.

Then, define a ClickListener

class DefaultClickListener implements ClickListener{
  void onClicked(String event) {
    print("Receive click event: " + event);


Finally, pass the listener to build method.

  Future<Widget> _buildWidget() async{

    return DynamicWidgetBuilder().build(jsonString, buildContext, new DefaultClickListener());

Widget Documents #

Already completed widgets:

You can view Currently support widgets and properties here.

Setup #

Checkout this project and run demo.

Code Examples #

Checkout this project and run demo.

Contact #

Created by @deng.yin@gmail.com - feel free to contact me

[0.0.1] - init release

  • initial release.

[0.0.2] - Add more flutter widgets

  • Add more flutter widgets

[0.0.3] - ListView & GridView add "auto load more" feature.

  • ListView & GridView add "auto load more" feature.

[1.0.2] - Add more widgets support.

  • Add more flutter widgets

[1.0.2] - Add click listener and more widgets support.

  • Add Click listener support
  • Add more flutter widgets

[1.0.3] - WidgetParser.parse add BuildContext param.

  • WidgetParser.parse add BuildContext param.

[1.0.4] - Support web application

  • Support web application

[1.0.5] - fix bugs

  • fix bugs

[1.0.6] - Add SafeArea and ListTile widgets.

  • Add SafeArea and ListTile widgets


demo #

Dynamic widget demo

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dynamic_widget: ^1.0.6

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dynamic_widget/dynamic_widget.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 18, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Fix lib/dynamic_widget/basic/listtile_widget_parser.dart. (-0.50 points)

Analysis of lib/dynamic_widget/basic/listtile_widget_parser.dart reported 1 hint:

line 3 col 8: Don't import implementation files from another package.

Fix lib/dynamic_widget/basic/safearea_widget_parser.dart. (-0.50 points)

Analysis of lib/dynamic_widget/basic/safearea_widget_parser.dart reported 1 hint:

line 3 col 8: Don't import implementation files from another package.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
http ^0.12.0+2 0.12.0+4
logging ^0.11.3+2 0.11.4
Transitive dependencies
async 2.4.0
charcode 1.1.3
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies