nocterm_unrouter 0.1.0
nocterm_unrouter: ^0.1.0 copied to clipboard
Nocterm adapter for the unrouter typed routing core.
nocterm_unrouter #
Nocterm adapter for unrouter.
Install #
dart pub add nocterm_unrouter
Entrypoint #
import 'package:nocterm_unrouter/nocterm_unrouter.dart';
What this adapter adds #
Unrouter<R>as a NoctermStatefulComponent- Nocterm route records with component builders
UnrouterScopeandBuildContexthelpers- Shell composition helpers (
branch()+shell())
Core route semantics are provided by unrouter.
Quick start #
import 'package:nocterm/nocterm.dart';
import 'package:nocterm_unrouter/nocterm_unrouter.dart';
sealed class AppRoute implements RouteData {
const AppRoute();
}
final class HomeRoute extends AppRoute {
const HomeRoute();
@override
Uri toUri() => Uri(path: '/');
}
Future<void> main() async {
await runApp(
NoctermApp(
title: 'Demo',
child: Unrouter<AppRoute>(
routes: <RouteRecord<AppRoute>>[
route<HomeRoute>(
path: '/',
parse: (_) => const HomeRoute(),
builder: (_, __) => const Text('Home'),
),
],
),
),
);
}
Runtime access in components #
final controller = context.unrouterAs<AppRoute>();
controller.go(const HomeRoute());
Fallback builders #
Unrouter supports:
unknown(BuildContext, Uri)blocked(BuildContext, Uri)loading(BuildContext, Uri)onError(BuildContext, Object, StackTrace)
resolveInitialRoute defaults to true in Nocterm adapter.
Keyboard-first shell apps #
Nocterm adapter works well with Focusable and key bindings to drive
controller.go, controller.back, shellState.goBranch, and
shellState.popBranch.
Example #
cd pub/nocterm_unrouter/example
dart pub get
dart run bin/main.dart
Example source:
example/bin/main.dart