Skip to main content

adaptive_router_behavior 0.0.1 copy "adaptive_router_behavior: ^0.0.1" to clipboard
adaptive_router_behavior: ^0.0.1 copied to clipboard

A clean, lightweight, and type-safe routing library for Flutter that handles adaptive page transitions (Material/Cupertino) and stack tracking automatically.

example/lib/main.dart

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

void main() {
  // Configure settings
  AdaptiveRouterBehavior.settings = const AdaptiveRouterSettings(
    enableLogging: true,
    platformStyle: AppPlatformStyle.adaptive,
  );
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Adaptive Router Example',
      theme: ThemeData(
        useMaterial3: true,
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      navigatorKey: AdaptiveRouterBehavior.navigatorKey,
      navigatorObservers: [AdaptiveRouterBehavior.observer],
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Adaptive Router Example'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    children: [
                      Text(
                        'Active Platform Style',
                        style: Theme.of(context).textTheme.titleMedium,
                      ),
                      const SizedBox(height: 8),
                      Text(
                        AdaptiveRouterBehavior.settings.platformStyle.toString(),
                        style: Theme.of(context).textTheme.bodyLarge,
                      ),
                      const SizedBox(height: 8),
                      const Text(
                        'Check the debug console to view real-time transition logs.',
                        textAlign: TextAlign.center,
                        style: TextStyle(fontSize: 12, color: Colors.grey),
                      ),
                    ],
                  ),
                ),
              ),
              const SizedBox(height: 24),
              ElevatedButton.icon(
                icon: const Icon(Icons.arrow_forward),
                label: const Text('Go to Details (Default Transition)'),
                onPressed: () {
                  context.push(DetailsRoute(itemId: 'Item 42'));
                },
              ),
              const SizedBox(height: 12),
              ElevatedButton.icon(
                icon: const Icon(Icons.blur_on),
                label: const Text('Go with Fade Transition'),
                onPressed: () {
                  context.push(FadeTransitionRoute());
                },
              ),
              const SizedBox(height: 12),
              ElevatedButton.icon(
                icon: const Icon(Icons.zoom_in),
                label: const Text('Go with Zoom Transition'),
                onPressed: () {
                  context.push(ZoomTransitionRoute());
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// 1. Details Route using standard Adaptive Transition (Material on Android, Cupertino on iOS)
class DetailsRoute extends AppRoute {
  final String itemId;

  DetailsRoute({required this.itemId});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Details: $itemId'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Details Page for $itemId'),
            const SizedBox(height: 24),
            Text(
              'Currently active stack length: ${AdaptiveRouterBehavior.stack.history.length}',
              style: const TextStyle(color: Colors.grey),
            ),
            const SizedBox(height: 24),
            ElevatedButton(
              onPressed: () => context.pop(),
              child: const Text('Go Back'),
            ),
          ],
        ),
      ),
    );
  }
}

// 2. Custom Fade Transition Route
class FadeTransitionRoute extends AppRoute {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Fade Transition'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('This page transitions using a Custom Fade effect.'),
            const SizedBox(height: 24),
            ElevatedButton(
              onPressed: () => context.pop(),
              child: const Text('Go Back'),
            ),
          ],
        ),
      ),
    );
  }

  @override
  TransitionType get transitionType => TransitionType.fade;

  @override
  Duration get transitionDuration => const Duration(milliseconds: 500);
}

// 3. Custom Zoom Transition Route
class ZoomTransitionRoute extends AppRoute {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Zoom Transition'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('This page transitions using a Custom Zoom effect.'),
            const SizedBox(height: 24),
            ElevatedButton(
              onPressed: () => context.pop(),
              child: const Text('Go Back'),
            ),
          ],
        ),
      ),
    );
  }

  @override
  TransitionType get transitionType => TransitionType.zoom;

  @override
  Duration get transitionDuration => const Duration(milliseconds: 400);
}
1
likes
150
points
61
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A clean, lightweight, and type-safe routing library for Flutter that handles adaptive page transitions (Material/Cupertino) and stack tracking automatically.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on adaptive_router_behavior