json_widget 0.1.0

json_widget #

Generate widgets from JSON. This is only a simple demonstration of how to write code generation in Dart. To use in a flutter project, add to the builders section of the pubspec.yaml.

name: example

...

builders:
    json_widget: any

Then you can generate Widgets from JSON blobs (Silly, I know) during a flutter run. For example:

example.json

{
    "name": "Container",
    "params": {
        "color": "#Color(0xFF22DD11)",
        "child": {
            "name": "Text",
            "params": {
                "0": "Hello, World"
            }
        }
    }
}

Then import this example file into your main and flutter run. There may be an analyzer warning that example.dart (NB: example.json) doesn't exist.

main.dart

import 'package:flutter/material.dart';
import 'example.dart' as generated; // May not exist, it is okay!

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: ListView(
          children: [
            // use our generated widget
            generated.GeneratedWidget(),
          ]
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  json_widget: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:json_widget/json_widget.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
65
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, other

Primary library: package:json_widget/json_widget.dart with components: io, build.

Health suggestions

Format lib/json_widget.dart.

Run dartfmt to format lib/json_widget.dart.

Format lib/src/builder.dart.

Run dartfmt to format lib/src/builder.dart.

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 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.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and json_widget.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
build ^1.1.4 1.2.0
build_config ^0.4.0 0.4.1+1
dart_style ^1.2.8 1.3.1
meta ^1.1.6 1.1.7
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
front_end 0.1.27
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
json_annotation 3.0.0
kernel 0.3.27
logging 0.11.3+2
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
test 1.6.4