Skip to content

Commit

Permalink
Add experimental code generator
Browse files Browse the repository at this point in the history
See https://github.com/flutter/flutter/wiki/Code-generation-in-Flutter

- Generates a .dart widget class based on a .json file
  • Loading branch information
maru committed Apr 25, 2020
1 parent 1f77467 commit fa54060
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 5 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@

# NStack Flutter

NStack Flutter, provided as a Plugin Package, is the companion software development kit to the [NStack](https://nstack.io) backend.
[NStack] Flutter, provided as a plugin package, is a companion software development kit to the [NStack](https://nstack.io) backend.

See [NStack documentation](https://nstack-io.github.io/docs/docs/guides/flutter/flutter.html) for more information.
See [NStack documentation](https://nstack-io.github.io/docs/docs/guides/flutter/flutter.html) for more information.

# How to use

## Install

To use [NStack], you will need your typical [build_runner]/code-generator setup.\
First, install [build_runner] and [NStack] by adding them to your `pubspec.yaml` file:

```yaml
# pubspec.yaml
dependencies:
nstack:

dev_dependencies:
build_runner:
```
This installs two packages:
- build_runner, the tool to run code-generators
- [NStack] SDK, which includes a code generator
## Run the generator
Depending on your use case you have two possibilities:
- `flutter pub pub run build_runner build`, if your package depends on Flutter
- `pub run build_runner build` otherwise
20 changes: 20 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config
targets:
$default:
builders:
freezed:
enabled: true
generate_for:
exclude:
- test
- example
include:
- test

builders:
jsonWidgetBuilder:
import: "package:nstack/json_widget.dart"
builder_factories: ["jsonWidgetBuilder"]
build_extensions: {".json": [".dart"]}
build_to: source
auto_apply: dependents
12 changes: 12 additions & 0 deletions example/lib/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "Container",
"params": {
"color": "#Color(0xFF22DD11)",
"child": {
"name": "Text",
"params": {
"0": "Hello, World"
}
}
}
}
Loading

0 comments on commit fa54060

Please sign in to comment.