redux_navigator 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new63

redux_navigator #

A Redux middleware for Navigator of Flutter. You can use default Navigator related Action, and also add custom behaviors.

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

  • navigatorMiddleware - A function that returns bundle of Navigator related middleware. You can also add more custom middleware by using NavigatorMiddlewareCallback.
  • NavigatorMiddlewareBuilder - A builder class for navigatorMiddleware. You can define custom behaviors with it.

Dart Version #

  • Dart 2.2.3+

Usage #

Demonstrate how to use redux_navigator.

  1. How to use default navigatorMiddleware.
  2. How to add custom behaviors with NavigatorMiddlewareBuilder.
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:redux_navigator/redux_navigator.dart';

class AppState {}

AppState appReducer(AppState state, dynamic action) {
  return state;
}

void main() {
  /// Initialize navigatorKey which is used for passing to
  /// [navigatorMiddleware] & [MaterialApp].
  final navigatorKey = GlobalKey<NavigatorState>();

  runApp(
    StoreProvider<AppState>(
      store: Store<AppState>(
        appReducer,
        initialState: AppState(),
        middleware: [
          /// Add navigatorMiddleware to middleware with [navigatorKey].
          ...navigatorMiddleware<AppState>(navigatorKey),
        ],
      ),
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),

        /// Pass navigatorKey to [MaterialApp].
        navigatorKey: navigatorKey,
        home: const HomePage(),
      ),
    ),
  );
}

/// A page which presents list of infinity indexes.
class HomePage extends StatelessWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    /// Get Store by using StoreProvider. The store will be used dispatching
    /// Navigator Action.
    final store = StoreProvider.of<AppState>(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('redux_heaven_demo'),
      ),
      body: ListView.builder(
        itemBuilder: (context, index) => InkWell(
          /// Dispatch PushAction to navigate DetailPage.
          ///
          /// You can also use PushNamedAction with routeName parameter.
          onTap: () => store.dispatch(
            PushAction(
              MaterialPageRoute<void>(
                builder: (context) => DetailPage(index: index),
              ),
            ),
          ),
          child: Container(
            padding: const EdgeInsets.all(24),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  color: Colors.black.withOpacity(0.3),
                ),
              ),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  'Item: $index',
                  style: Theme.of(context).textTheme.button,
                ),
                const Icon(Icons.navigate_next)
              ],
            ),
          ),
        ),
      ),
    );
  }
}

/// Destination of [PushAction] above.
class DetailPage extends StatelessWidget {
  const DetailPage({
    @required this.index,
    Key key,
  }) : super(key: key);

  final int index;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Item Detail Page : $index'),
      ),
      body: Center(
        child: Text(
          'Item:$index',
          style: Theme.of(context).textTheme.title,
        ),
      ),
    );
  }
}

2. How to define custom behaviors. #

navigatorMiddleware<AppState>(
  navigatorKey,
  customBuilders: [
    /// You can add custom [Navigator] related behaviors by
    /// specifying [NavigatorMiddlewareBuilder]s list.
    NavigatorMiddlewareBuilder<AppState, ShowAlertDialogAction>(
      callback: (navigatorKey, store, action, next) {
        showDialog<void>(
          context: navigatorKey.currentState.overlay.context,
          builder: (context) {
            return const AlertDialog(
              content: Text('Addtional Middleware'),
            );
          },
        );
      },
    ),
  ],
),

[0.2.1]

  • update dependencies for redux.dart-v4.0.0

[0.2.0]

  • add custom builders.

[0.1.1]

  • BUG FIX.

[0.1.0]

  • create NavigatorMiddlewareCallback class & add Document comment, refactor.

[0.0.1]

  • bundle private utils for navigator with Redux.

example/README.md

redux_navigator_example #

An example to demonstrate how to use redux_navigator.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  redux_navigator: ^0.2.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:redux_navigator/redux_navigator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
26
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]
63
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.3 <3.0.0
flutter 0.0.0
redux ^4.0.0 4.0.0
redux_heaven ^0.1.0 0.1.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic_mono ^1.4.0