history 0.2.1

  • README.md
  • Installing
  • Versions
  • 7

Pub Build Status codecov


history lets you manage session history in any environment. It uses a subset of the HTML5 session history API and brings it to the VM and Browsers that don't support session History manipulation. history abstracts away the differences in environments using a minimal API. This lets you easily change the history stack, navigate to different locations in your app, confirm navigation changes using custom prompts, and persist any custom state you want between sessions.


history provides 3 variants to use based on your environment:

  • MemoryHistory - For use in non-DOM environments such as the dart vm. All session information is stored in memory. This variant can be used in the browser if needed.
  • BrowserHistory - For use in modern browsers that support the HTML5 session history API. session information is stored using the browser's history API, allowing history manipulation from other sources to be synced with this history.
  • HashHistory - For use in legacy browsers. Relies on the hash-based paths and syncs with the browsers hashchange events. Custom states are not supported.

To use history, simply import and go!

// For use in Browser
import 'package:history/history.dart';
// For use in VM
// import 'package:history/vm.dart'; 

Confirmation confirmation = (_) => new Future.value(true);
MemoryHistory history = new MemoryHistory(getConfirmation: confirmation);

// Listen for changes
var sub = history.onChange.listen((updatedHistory) {
  var location = updatedHistory.location;
  print('Transitioned to ${location.path} with action ${updatedHistory.action}!');
  print('State associated with this location: ${location.state}');

// Manipulate the history
await history.push('/first');
await history.push('/second', 'with a state');
await history.replace('/third', {'with': 'a', 'state': 'object'});
await history.goBack();
await history.goForward();
await history.go(-1);

// Block transitions until they are confirmed by the user
history.block('Are you sure you want to navigate?');

// This call waits for a user confirmation before continuing

// Use a more complex Prompt for more flexibilty
history.block((Location l, Action a) {
  if (l.path == '/logout') {
    return 'Logging out will cause you to lose all unsaved data!';
  } else if (a == Action.pop) {
    return 'Are you sure you want to go back?';
  return 'Are you sure you want to navigate?';

// Prints different prompts based on the transition
await history.goBack();
await history.push('/logout');

// Return to non-blocking mode

// Stop listening


Examples are available in the examples/ folder -- one for each type of history variant.

  • For Browser Examples, run pub get and pub serve example. Then navigate to localhost:8080
  • For a VM Example, run pub get then run dart example/example_vm.dart


This project is largely based on history, an npm package provided by React Training

Change Log

All notable changes to this project will be documented here.

This project adheres to Semantic Versioning.

[v0.2.1] - 2016-7-18


  • quiver dependency loosened

[v0.2.0] - 2018-7-15


  • Added Changelog


  • Location how supports a dynamic state when using non-default constructor
  • BrowserHistory how uses window.confirm by default when no custom confirmation is passed

[v0.1.0] - 2018-7-14


  • Initial Release

Use this package as a library

1. Depend on it

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

  history: ^0.2.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:history/history.dart';
Version Uploaded Documentation Archive
0.2.1 Jul 19, 2018 Go to the documentation of history 0.2.1 Download history 0.2.1 archive
0.2.0 Jul 15, 2018 Go to the documentation of history 0.2.0 Download history 0.2.0 archive
0.1.0 Jul 14, 2018 Go to the documentation of history 0.1.0 Download history 0.1.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <2.0.0