navigation_without_context 0.0.4 copy "navigation_without_context: ^0.0.4" to clipboard
navigation_without_context: ^0.0.4 copied to clipboard

A Flutter package that enables global navigation without requiring BuildContext, using a clean abstraction and GetIt for dependency injection.

example/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigator.navigatorKey,
      title: 'Navigation Example',
      initialRoute: '/',
      routes: {
        '/': (context) => HomePage(),
        '/second': (context) => SecondPage(),
      },
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Home Page')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => navigator.pushNamed('/second'),
          child: Text('Go to Second Page'),
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Second Page')),
      body: Center(
        child: ElevatedButton(
          onPressed: () => navigator.goBack(),
          child: Text('Go Back'),
        ),
      ),
    );
  }
}
0
likes
150
points
289
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that enables global navigation without requiring BuildContext, using a clean abstraction and GetIt for dependency injection.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, get_it_di_global_variable

More

Packages that depend on navigation_without_context