Skip to content

Commit fa54060

Browse files
author
maru
committed
Add experimental code generator
See https://github.com/flutter/flutter/wiki/Code-generation-in-Flutter - Generates a .dart widget class based on a .json file
1 parent 1f77467 commit fa54060

File tree

9 files changed

+636
-5
lines changed

9 files changed

+636
-5
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@
44

55
# NStack Flutter
66

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

9-
See [NStack documentation](https://nstack-io.github.io/docs/docs/guides/flutter/flutter.html) for more information.
9+
See [NStack documentation](https://nstack-io.github.io/docs/docs/guides/flutter/flutter.html) for more information.
10+
11+
# How to use
12+
13+
## Install
14+
15+
To use [NStack], you will need your typical [build_runner]/code-generator setup.\
16+
First, install [build_runner] and [NStack] by adding them to your `pubspec.yaml` file:
17+
18+
```yaml
19+
# pubspec.yaml
20+
dependencies:
21+
nstack:
22+
23+
dev_dependencies:
24+
build_runner:
25+
```
26+
27+
This installs two packages:
28+
29+
- build_runner, the tool to run code-generators
30+
- [NStack] SDK, which includes a code generator
31+
32+
## Run the generator
33+
34+
Depending on your use case you have two possibilities:
35+
36+
- `flutter pub pub run build_runner build`, if your package depends on Flutter
37+
- `pub run build_runner build` otherwise

build.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Read about `build.yaml` at https://pub.dartlang.org/packages/build_config
2+
targets:
3+
$default:
4+
builders:
5+
freezed:
6+
enabled: true
7+
generate_for:
8+
exclude:
9+
- test
10+
- example
11+
include:
12+
- test
13+
14+
builders:
15+
jsonWidgetBuilder:
16+
import: "package:nstack/json_widget.dart"
17+
builder_factories: ["jsonWidgetBuilder"]
18+
build_extensions: {".json": [".dart"]}
19+
build_to: source
20+
auto_apply: dependents

example/lib/example.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "Container",
3+
"params": {
4+
"color": "#Color(0xFF22DD11)",
5+
"child": {
6+
"name": "Text",
7+
"params": {
8+
"0": "Hello, World"
9+
}
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)