juice_routing 0.7.0 copy "juice_routing: ^0.7.0" to clipboard
juice_routing: ^0.7.0 copied to clipboard

Declarative, state-driven navigation for Juice applications with Navigator 2.0 integration, route guards, and deep linking support.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:juice/juice.dart';
import 'package:juice_routing/juice_routing.dart';

import 'routes.dart';
import 'auth_bloc.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final RoutingBloc _routingBloc;
  late final JuiceRouterDelegate _routerDelegate;

  @override
  void initState() {
    super.initState();

    // Register AuthBloc globally
    BlocScope.register<AuthBloc>(
      () => AuthBloc(),
      lifecycle: BlocLifecycle.permanent,
    );

    // Register RoutingBloc globally
    BlocScope.register<RoutingBloc>(
      () => RoutingBloc(),
      lifecycle: BlocLifecycle.permanent,
    );

    // Get instances
    _routingBloc = BlocScope.get<RoutingBloc>();

    // Initialize routing with config
    _routingBloc.send(InitializeRoutingEvent(config: appRoutes));

    // Create router delegate
    _routerDelegate = JuiceRouterDelegate(routingBloc: _routingBloc);
  }

  @override
  void dispose() {
    _routerDelegate.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Juice Routing Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      routerDelegate: _routerDelegate,
      routeInformationParser: const JuiceRouteInformationParser(),
    );
  }
}
1
likes
150
points
154
downloads

Publisher

unverified uploader

Weekly Downloads

Declarative, state-driven navigation for Juice applications with Navigator 2.0 integration, route guards, and deep linking support.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#navigation #routing #bloc #state-management #flutter

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, juice

More

Packages that depend on juice_routing