usesmileid_njia 0.0.1-SNAPSHOT.13
usesmileid_njia: ^0.0.1-SNAPSHOT.13 copied to clipboard
Smile ID's flow navigation engine for Flutter: a thin bridge to the native njia cores, which own the back stack. Only navigation crosses the bridge.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:usesmileid_njia/usesmileid_njia.dart';
/// usesmileid_njia's example: a two-step flow on the native engine, with next and back.
void main() => runApp(const MaterialApp(home: ExampleFlow()));
enum Kind { intro, capture }
enum Fact { seen }
final codec = NjiaCodec(kinds: NjiaWire.ofEnum(Kind.values), facts: NjiaWire.ofEnum(Fact.values));
const graph = NjiaGraph<Kind, Fact>(
nodes: [
NjiaStep(id: 'intro', kind: Kind.intro),
NjiaStep(id: 'capture', kind: Kind.capture),
],
);
/// The flow, drawn by NjiaHost, each step with buttons that move it from its own entry.
class ExampleFlow extends StatefulWidget {
/// The example's only screen.
const ExampleFlow({super.key});
@override
State<ExampleFlow> createState() => _ExampleFlowState();
}
class _ExampleFlowState extends State<ExampleFlow> {
NjiaEngine<Kind, Fact>? _engine;
@override
void initState() {
super.initState();
NjiaEngine.start(codec, graph).then((engine) {
// Gone before the engine started: release it rather than leak it in the bridge.
if (!mounted) {
engine.dispose();
return;
}
setState(() => _engine = engine);
});
}
@override
void dispose() {
_engine?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final engine = _engine;
return Scaffold(
appBar: AppBar(title: const Text('njia')),
body: engine == null
? const Center(child: CircularProgressIndicator())
: NjiaHost(
engine: engine,
builder: (context, scope) => Column(
children: [
Text('${scope.step.kind.name} · visit ${scope.entry.visit}'),
Row(
children: [
TextButton(onPressed: scope.navigator.next, child: const Text('next')),
TextButton(onPressed: scope.navigator.back, child: const Text('back')),
],
),
],
),
),
);
}
}