Search packages, repositories and app categories

Package detailsv0.7.1

flutter_redux_navigation

A simple reactive navigation middleware for Flutter's redux library.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
443
Likes
13
Pub points
160

Install package

flutter pub add flutter_redux_navigation

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A lightweight middleware that enables reactive navigation in Flutter apps using Redux. It synchronizes navigation state with the Redux store, allowing routes to be managed declaratively and reactively based on app state changes. This package simplifies navigation logic by integrating it into the Redux flow, reducing boilerplate and improving testability. It supports all major platforms and works seamlessly with Flutter's Redux ecosystem.

Use cases

  • Declarative route management
  • Reactive navigation based on state
  • Synchronized navigation across components
  • Testing navigation logic
  • Streamlined state-driven routing

Key features

  • Integrates with Redux store
  • Reactive route updates
  • Minimal boilerplate
  • Cross-platform support
  • Easy testing
  • State-driven navigation

Suitable for

  • Redux-based Flutter apps
  • Apps needing state-dependent navigation
  • Developers seeking clean navigation patterns
  • Teams using reactive state management
  • Projects requiring predictable navigation flows

Considerations

  • Requires Redux setup
  • Limited to Redux architecture
  • May add complexity for simple apps
  • Not suitable for non-Redux projects
  • Needs careful state design for navigation

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Build Status codecov

Flutter Navigation for redux

Navigation Middleware for Flutter's redux library.

Basic classes that enables page navigation through by utilizing Redux Store middleware facility.

This package is built to work with Redux.dart 4.0.0+.

Redux Middleware

  • NavigationMiddleware<T> - The Middleware that reacts to NavigateToActions.

Examples

Take a look in the examples directory.

How to setup navigation

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

class AppState {
  final String name;
  
  const AppState(this.name);
  
  factory AppState.initial() => AppState(null);
  factory AppState.changeName(String name) => AppState(name);
}

class AppNameChangedAction {
  final String name;

  AppNameChangedAction(this.name);
}

AppState _onAppNameChanged(AppState state, AppNameChangedAction action) =>
    state.changeName(action.name);

final appReducer = combineReducers<AppState>([
  TypedReducer<AppState, AppNameChangedAction>(_onAppNameChanged),
]);


final store = new Store<AppState>(combineReducers<AppState>([appReducer]),
    initialState: AppState.initial(),
    middleware: [
      NavigationMiddleware<AppState>(),
    ]);

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StoreProvider<AppState>(
        store: store,
        child: MaterialApp(
          title: 'My App',
          navigatorKey: NavigatorHolder.navigatorKey,
        )
    );
  }
}

void main() => runApp(MyApp());

How to navigate

Let's say you wish to navigate from a LoginPage to some dashboard page, you only need to dispatch a NavigateToAction.replace action with the appropriate path, which is registered to the dashboard page.

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

class LoginPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => LoginPageState();
}

class LoginPageState extends State<LoginPage> {
  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AuthBloc>(
      converter: (store) {
        return store;
      },
      builder: (BuildContext context, Store<AppState> store) {
        return Scaffold(body: Builder(
          builder: (BuildContext context) {
            return Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                onPressed: () {
                  store.dispatch(NavigateToAction.replace('/dashboard'));
                },
                child: Text('Login'),
              )
              ],
            );
          },
        ));
      },
    );
  }
}

How to use pre and post navigation hooks

Let's use the same example as before, but now let's assume that you want to start a loader whilst navigating to the dashboard and stop it once you have navigated.

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

class LoginPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => LoginPageState();
}

class LoginPageState extends State<LoginPage> {
  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AuthBloc>(
      converter: (store) {
        return store;
      },
      builder: (BuildContext context, Store<AppState> store) {
        return Scaffold(body: Builder(
          builder: (BuildContext context) {
            return Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                RaisedButton(
                onPressed: () {
                  store.dispatch(
                    NavigateToAction.replace(
                      '/dashboard',
                      preNavigation: () => store.dispatch(StartLoadingAction()),
                      postNavigation: () => store.dispatch(StopLoadingAction()),
                    ),
                  );
                },
                child: Text('Login'),
              )
              ],
            );
          },
        ));
      },
    );
  }
}

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package