go_navigator 2.0.0 copy "go_navigator: ^2.0.0" to clipboard
go_navigator: ^2.0.0 copied to clipboard

A comprehensive Flutter Navigation System that provides a set of utilities for managing routes, passing arguments, and navigating through your application with ease.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:go_navigator/go/go.dart';
import 'package:go_navigator/go/go_navigator.dart';

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

/// The main application widget.
class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

/// The state for the main application widget.
class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      /// The `MaterialApp` widget, which is the root of the application.
      onGenerateRoute: (RouteSettings routeSettings) => GoNavigator(
        initialRoute: Page1(),
        routes: {
          /// Define the routes for the application using the `NavigationSystem`.
          Page1.routeName: (context, args) => Page1(),
          Page2.routeName: (context, args) => const Page2(),
          Page3.routeName: (context, args) => const Page3(),
          Page4.routeName: (context, args) => const Page4(),
        },
      ).generateRoute(routeSettings),
    );
  }
}

/// The first page of the application.
class Page1 extends StatelessWidget {
  static const routeName = '/d1';
  Page1({super.key});

  TextEditingController p1Ctl = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(' Page 1'),
      ),
      body: Center(
        child: Column(
          children: [
            const Text('This is  Page 1 content.'),
            TextField(controller: p1Ctl)
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
          heroTag: 'p1_f',
          onPressed: () {
            /// Navigate to Page2 when the floating action button is pressed.
            context.to(Page2.routeName, args: {'title': p1Ctl.text});
          },
          child: const Icon(Icons.arrow_forward_ios_rounded)),
    );
  }
}

/// The second page of the application.
class Page2 extends StatelessWidget {
  static const routeName = '/d2';
  const Page2({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(' Page 2 - Data ${context.args['title']}'),
      ),
      body: const Center(
        child: Text('This is  Page 2 content.'),
      ),
      floatingActionButton: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          FloatingActionButton(
            heroTag: 'p2_b',
            onPressed: () {
              /// Pop the current page to return to the previous page.
              context.pop();
            },
            child: const Icon(Icons.arrow_back_ios_new_rounded),
          ),
          const SizedBox(
            width: 10,
          ),
          FloatingActionButton(
              heroTag: 'p2_f',
              onPressed: () {
                /// Navigate to Page3 when the second floating action button is pressed.
                context.to(Page3.routeName);
              },
              child: const Icon(Icons.arrow_forward_ios_rounded)),
        ],
      ),
    );
  }
}

/// The third page of the application.
class Page3 extends StatelessWidget {
  static const routeName = '/d3';
  const Page3({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(' Page 3'),
      ),
      body: const Center(
        child: Text('This is  Page 3 content.'),
      ),
      floatingActionButton: FloatingActionButton(
        heroTag: 'p3_b',
        onPressed: () {
          /// Pop the current page to return to the previous page.
          context.pop();
        },
        child: const Icon(Icons.arrow_back_ios_new_rounded),
      ),
    );
  }
}

/// The third page of the application.
class Page4 extends StatelessWidget {
  static const routeName = '/e4';
  const Page4({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(' Page 3'),
      ),
      body: const Center(
        child: Text('This is  Page 3 content.'),
      ),
      floatingActionButton: FloatingActionButton(
        heroTag: 'p3_b',
        onPressed: () {
          /// Pop the current page to return to the previous page.
          context.pop();
        },
        child: const Icon(Icons.arrow_back_ios_new_rounded),
      ),
    );
  }
}
3
likes
0
points
26
downloads

Publisher

unverified uploader

Weekly Downloads

A comprehensive Flutter Navigation System that provides a set of utilities for managing routes, passing arguments, and navigating through your application with ease.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on go_navigator