json_widget 0.1.0
json_widget: ^0.1.0 copied to clipboard

Generate widgets from json

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


    json_widget: any

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


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


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

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

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