Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.
/ json_widget Public archive

Compile time conversion from json to widgets (For some reason...)

License

Notifications You must be signed in to change notification settings

jonahwilliams/json_widget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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(),
          ]
        ),
      ),
    );
  }
}

About

Compile time conversion from json to widgets (For some reason...)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages