remote_ui 0.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

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.8] - 17/06/2020 #

  • update deps

[0.0.7] - 26/03/2020 #

  • fix dropdown button

[0.0.6] - 05/10/2019 #

  • better parsing of string number values

[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/lib/main.dart

import 'package:flutter/material.dart';
import 'package:remote_ui/remote_ui.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Expanded(
              child: 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\$'}
                    ],
                  },
                ),
              ),
            ),
            Text(
              'You have pushed the button this many times:',
              textAlign: TextAlign.center,
            ),
            Text(
              '$_counter',
              textAlign: TextAlign.center,
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  remote_ui: ^0.0.8

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]
52
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [remote_ui] that is in a package requiring null.

Health suggestions

Fix lib/src/remote_widget.dart. (-1.49 points)

Analysis of lib/src/remote_widget.dart reported 3 hints:

line 111 col 7: 'hasFloatingPlaceholder' is deprecated and shouldn't be used. Use floatingLabelBehaviour instead. This feature was deprecated after v1.13.2..

line 208 col 20: 'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1..

line 243 col 20: 'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1..

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.

Fix additional 23 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/parsers/column.dart (Run flutter format to format lib/src/parsers/column.dart.)
  • 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/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 issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (flutter_hooks).

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.9.0 0.9.0 0.11.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test