remote_ui 0.0.4

remote_ui #

Flutter widget to manage UI from a JSON definition

How it works #

So all you need is to have a JSON definition of a widget tree, then parse it and give it to RemoteWidget, it will take care of creating all your tree.

Example of a JSON widget tree representation:

{
  "type": "column",
  "children": [
    {
      "type": "row",
      "flex": 3,
      "children": [
        {
          "type": "spacer",
          "flex": 1
        },
        {
          "type": "image_button",
          "id": "onoff",
          "flex": 2,
          "mainIndicator": true,
          "values": { "on": "http://test/on.png", "off": "http://test/off.png"},
          "value": "on"
        },
        {
          "type": "spacer",
          "flex": 1
        }
      ]
    },
    {
      "type": "slider",
      "id": "dim",
      "flex": 1,
      "min": 0,
      "divisions": 100,
      "max": 100,
      "value": 50
    }
  ]
}

Some widget fields are enums, for those just set them to the integer index of that enum and they'll be used correctly.

Usage #

Once you have you're parse JSON data it's really easy, just do:

RemoteWidget(
    definition: parsedJsonData,
),

Dynamic data #

Might be useful to bind data in case our tree contains form fields, no problem.

All you need is to modify a bit your JSON and wrap dynamic data between $ like $varName$.

Then you can pass this data to RemoteWidget:

RemoteWidget(
    definition: parsedJsonData,
    data: {"varName": "myValue"},
),

Interactivity #

If you have buttons or form field, you probably want to get the events back somehow ^^

You can do this with the RemoteManagerWidget, his job is to forward all the changes of your interactive widget under him.

Interactive widget need an id field to be able to recognize them. Once the user click on the button or slide the slider you'll get the changes under onChanges callback

Example:

RemoteManagerWidget(
    onChanges: (key, value, {associatedData}) => debugPrint('$key change to $value'),
    child: RemoteWidget(
      data: {
        'myColor': 0xFFFF00FF,
        'sliderData': {
          'sliderValue': .2,
        }
      },
      definition: {
        'type': 'column',
        'crossAxisAlignment': CrossAxisAlignment.stretch.index,
        'children': [
          {
            'type': 'row',
            'flex': 1,
            'crossAxisAlignment': CrossAxisAlignment.stretch.index,
            'children': [
              {
                'type': 'container',
                'color': '\$myColor\$',
                'width': 80.0,
              },
              {
                'type': 'expanded',
                'child': {
                  'type': 'container',
                  'color': 0xFF00FFFF,
                }
              },
              {
                'type': 'container',
                'color': 0xFFFFFF00,
                'width': 80.0,
              },
            ]
          },
          {'type': 'slider', 'id': 'brightness', 'value': '\$sliderData.sliderValue\$'}
        ],
      },
    ),
),

Widget compatibility #

Here is the list of currently supported flutter widget:

  • Center
  • Padding
  • Row
  • Column
  • Stack
  • Expended
  • FlatButton (partially)
  • RaisedButton (partially)
  • Slider
  • Container
  • Spacer
  • Text (partially)

Addons #

Existing addons #

  • image_button : Button based on remote images
  • color_picker : Color picker widget, inline or with button

Use an addons #

To use an addons all you need to do is to pass the factory to the RemoteManagerWidget.

Example:

RemoteManagerWidget(
    parsers: [RemoteImageButtonFactory()],
    child: RemoteWidget(...)
)

Create an addons #

I suggest you take a look at the existing addons on how to make a new one.

[0.0.4] - 01/08/2019

  • Fix same parsing issue and colors

[0.0.3] - 10/07/2019

  • Compatibility with last flutter stable

[0.0.2] - 16/06/2019

  • add color helper.

[0.0.1] - 05/06/2019

  • initial release.

example/README.md

example #

A new Flutter project.

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:


dependencies:
  remote_ui: ^0.0.4

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:remote_ui/remote_ui.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
21
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
57
Learn more about scoring.

We analyzed this package on Sep 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/parsers/center.dart.

Run flutter format to format lib/src/parsers/center.dart.

Format lib/src/parsers/checkbox.dart.

Run flutter format to format lib/src/parsers/checkbox.dart.

Format lib/src/parsers/column.dart.

Run flutter format to format lib/src/parsers/column.dart.

Fix additional 23 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/parsers/container.dart (Run flutter format to format lib/src/parsers/container.dart.)
  • lib/src/parsers/default_parser.dart (Run flutter format to format lib/src/parsers/default_parser.dart.)
  • lib/src/parsers/dropdown_button.dart (Run flutter format to format lib/src/parsers/dropdown_button.dart.)
  • lib/src/parsers/expanded.dart (Run flutter format to format lib/src/parsers/expanded.dart.)
  • lib/src/parsers/flat_button.dart (Run flutter format to format lib/src/parsers/flat_button.dart.)
  • lib/src/parsers/padding.dart (Run flutter format to format lib/src/parsers/padding.dart.)
  • lib/src/parsers/radio.dart (Run flutter format to format lib/src/parsers/radio.dart.)
  • lib/src/parsers/raised_button.dart (Run flutter format to format lib/src/parsers/raised_button.dart.)
  • lib/src/parsers/row.dart (Run flutter format to format lib/src/parsers/row.dart.)
  • lib/src/parsers/slider.dart (Run flutter format to format lib/src/parsers/slider.dart.)
  • lib/src/parsers/spacer.dart (Run flutter format to format lib/src/parsers/spacer.dart.)
  • lib/src/parsers/stack.dart (Run flutter format to format lib/src/parsers/stack.dart.)
  • lib/src/parsers/switch.dart (Run flutter format to format lib/src/parsers/switch.dart.)
  • lib/src/parsers/text.dart (Run flutter format to format lib/src/parsers/text.dart.)
  • lib/src/parsers/text_field.dart (Run flutter format to format lib/src/parsers/text_field.dart.)
  • lib/src/remote_widget.dart (Run flutter format to format lib/src/remote_widget.dart.)
  • lib/src/utils/mixin.dart (Run flutter format to format lib/src/utils/mixin.dart.)
  • lib/src/widgets/remote_checkbox.dart (Run flutter format to format lib/src/widgets/remote_checkbox.dart.)
  • lib/src/widgets/remote_dropdown_button.dart (Run flutter format to format lib/src/widgets/remote_dropdown_button.dart.)
  • lib/src/widgets/remote_radio.dart (Run flutter format to format lib/src/widgets/remote_radio.dart.)
  • lib/src/widgets/remote_slider.dart (Run flutter format to format lib/src/widgets/remote_slider.dart.)
  • lib/src/widgets/remote_switch.dart (Run flutter format to format lib/src/widgets/remote_switch.dart.)
  • lib/src/widgets/remote_text_field.dart (Run flutter format to format lib/src/widgets/remote_text_field.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-10 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_hooks ^0.6.0 0.6.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test