flutter_unrouter 0.1.0 copy "flutter_unrouter: ^0.1.0" to clipboard
flutter_unrouter: ^0.1.0 copied to clipboard

Flutter adapter for the unrouter typed routing core.

flutter_unrouter #

Status CI Platform Dart SDK

Flutter adapter for unrouter.

Install #

flutter pub add flutter_unrouter

Entrypoint #

import 'package:flutter_unrouter/flutter_unrouter.dart';

What this adapter adds #

  • Unrouter<R> implementing RouterConfig<HistoryLocation>
  • Flutter route records with widget/page/transition builders
  • UnrouterScope and BuildContext extensions (context.unrouter)
  • Shell composition helpers for branch-based UI

Core semantics (matching, guards, redirects, loaders, state model) are still owned by unrouter.

Quick start #

import 'package:flutter/material.dart';
import 'package:flutter_unrouter/flutter_unrouter.dart';

sealed class AppRoute implements RouteData {
  const AppRoute();
}

final class HomeRoute extends AppRoute {
  const HomeRoute();

  @override
  Uri toUri() => Uri(path: '/');
}

void main() {
  final router = Unrouter<AppRoute>(
    routes: <RouteRecord<AppRoute>>[
      route<HomeRoute>(
        path: '/',
        parse: (_) => const HomeRoute(),
        builder: (_, __) => const Scaffold(body: Center(child: Text('Home'))),
      ),
    ],
  );

  runApp(MaterialApp.router(routerConfig: router));
}

Route records #

  • RouteDefinition<T> via route<T>()
  • DataRouteDefinition<T, L> via dataRoute<T, L>()
  • Optional per-route page configuration:
    • pageBuilder
    • transitionBuilder
    • transitionDuration
    • reverseTransitionDuration

Runtime access in widgets #

final controller = context.unrouterAs<AppRoute>();
controller.go(const HomeRoute());

Also available:

  • context.unrouter (untyped)
  • controller.stateListenable for ValueListenable<StateSnapshot<T>>

Fallback builders #

Unrouter supports optional fallback UI:

  • unknown(BuildContext, Uri)
  • blocked(BuildContext, Uri)
  • loading(BuildContext, Uri)
  • onError(BuildContext, Object, StackTrace)

resolveInitialRoute defaults to false in Flutter adapter.

Shell routing #

Use branch() + shell() to compose branch-aware UI while sharing one controller/runtime state.

Example #

cd pub/flutter_unrouter/example
flutter pub get
flutter run -d chrome

Example source:

  • example/lib/main.dart
1
likes
150
points
26
downloads

Documentation

Documentation
API reference

Publisher

verified publishermedz.dev

Weekly Downloads

Flutter adapter for the unrouter typed routing core.

Repository (GitHub)
View/report issues

Topics

#flutter #router #navigation #routing #typed

License

MIT (license)

Dependencies

flutter, roux, unrouter, unstory

More

Packages that depend on flutter_unrouter