-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace WidgetGenerator sample with NStack sample
- Generates a NStack instance - Generate bundled translations
- Loading branch information
maru
committed
Apr 26, 2020
1 parent
fa54060
commit 8f6bac3
Showing
10 changed files
with
76 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
# 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"] | ||
nstackBuilder: | ||
import: "package:nstack/builder.dart" | ||
builder_factories: ["nstackBuilder"] | ||
build_extensions: {".json": [".dart"]} | ||
build_to: source | ||
auto_apply: dependents |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"nstack_project_id": "123123123", | ||
"nstack_api_key": "abcabcabc" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'package:build/build.dart'; | ||
import 'package:nstack/src/nstack_builder.dart'; | ||
|
||
/// Creates a [NstackBuilder] | ||
Builder nstackBuilder(BuilderOptions builderOptions) => const NstackBuilder(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
|
||
import 'package:build/build.dart'; | ||
|
||
/// A builder which outputs widgets from json. | ||
class NstackBuilder implements Builder { | ||
const NstackBuilder(); | ||
|
||
@override | ||
FutureOr<void> build(BuildStep buildStep) async { | ||
/// Read the input source and parse it as JSON. | ||
Map<String, Object> input; | ||
String rojectId; | ||
String apiKey; | ||
final AssetId outputId = buildStep.inputId.changeExtension('.dart'); | ||
try { | ||
input = json.decode(await buildStep.readAsString(buildStep.inputId)); | ||
rojectId = input["nstack_project_id"]; // TODO: Validate. | ||
apiKey = input["nstack_api_key"]; // TODO: Validate. | ||
} catch (err) { | ||
// TODO: Inform SDK user about error. | ||
} | ||
final StringBuffer output = StringBuffer(); | ||
output.writeln("// Generated by NStack, do not modify this file."); | ||
output.writeln("import 'package:nstack/nstack.dart';"); | ||
output.writeln(""); | ||
output.writeln("final NStack nstack = NStack.instance(\"$rojectId\", \"$apiKey\", _bundledTranslations);"); | ||
output.writeln(""); | ||
output.writeln(''' | ||
final _bundledTranslations = { | ||
'en_EN':'{"data":{"section1":{"key1":"value80493753","key2":"value2"}},"meta":{"language":{"id":56,"name":"English","locale":"en_EN","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":447,"slug":"mobile"}}}', | ||
'fr-BE': '{"data":{"section1":{"key1":"valeur1","key2":"valeur2"}},"meta":{"language":{"id":54,"name":"French (Belgian)","locale":"fr-BE","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":447,"slug":"mobile"}}}', | ||
}; | ||
'''); | ||
await buildStep.writeAsString(outputId, output.toString()); | ||
} | ||
|
||
@override | ||
Map<String, List<String>> get buildExtensions => const { | ||
'.json': ['.dart'] | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters