flutter_redux_navigation 0.4.1

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 3.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'),
              )
              ],
            );
          },
        ));
      },
    );
  }
}

Change Log #

v0.4.1 (2019-04-19)

Full Changelog

Closed issues:

  • Replacement for pushNamedAndRemoveUntil #6

Merged pull requests:

  • feat(navigate_to_action, navigation_middleware) #7 (esarbanis)

v0.4.0 (2019-03-21)

Full Changelog

Closed issues:

  • Arguments #1

Merged pull requests:

  • add an arguments optional parameter for push and replace #2 (esarbanis)

v0.3.3 (2019-03-14)

Full Changelog

v0.3.2 (2019-03-12)

Full Changelog

v0.3.1 (2019-03-03)

Full Changelog

0.3.0 (2019-01-06)

Full Changelog

0.2.0 (2019-01-04)

Full Changelog

0.1.1 (2018-12-28)

Full Changelog

0.1.0 (2018-12-28)

Full Changelog

0.0.3 (2018-12-28)

Full Changelog

0.0.2 (2018-12-28)

Full Changelog

0.0.1 (2018-12-28)

* This Change Log was automatically generated by github_changelog_generator

example/README.md

Examples #

  • Simple Login Example - A simple example to demonstrate the replacement navigation through NavigationToActions.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_redux_navigation: ^0.4.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_redux_navigation/flutter_redux_navigation.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
91
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/navigate_to_action.dart.

Run flutter format to format lib/src/navigate_to_action.dart.

Format lib/src/navigation_middleware.dart.

Run flutter format to format lib/src/navigation_middleware.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
redux ^3.0.0 3.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
mockito 4.0.0

Admin