NStack Flutter, provided as a plugin package, is a companion software development kit to the NStack backend.
See NStack documentation for more information.
To use NStack, you will need your typical build_runner setup.
First, install build_runner and NStack by adding them to your pubspec.yaml
file:
dependencies:
nstack:
git:
url: https://github.com/nstack-io/flutter-sdk.git
ref: v0.5.1
dev_dependencies:
build_runner:
This installs two packages:
- build_runner, the tool to run code-generators
- NStack SDK, which includes a code generator
Create a nstack.json
file under /lib
that holds your NStack details:
{
"version": 1,
"nstack_project_id": "YOUR_PROJECT_ID",
"nstack_api_key": "YOUR_REST_API_KEY"
}
Now, depending on your use case you have two possibilities to run the generator:
If your package depends on Flutter execute:
foo@bar:~$ flutter pub run build_runner build
Otherwise execute:
foo@bar:~$ pub run build_runner build
A successful execution generates your project tailored nstack.dart
file.
See example below on how to use your NStack instance.
To run a persistent build server that watches nstack.json
to automatically trigger rebuilds execute:
foo@bar:~$ flutter pub run build_runner watch --delete-conflicting-outputs
Now increment the "version"
number and save (⌘s) to trigger an update.
Import your nstack.dart
file and plant your NStackWidget
in the builder of your application.
import 'package:flutter/material.dart';
import 'package:nstack_example/nstack.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (context, child) {
return NStackWidget(
child: child!,
);
},
home: Scaffold(
appBar: AppBar(
title: Text(context.localization.test.title),
),
),
);
}
}