Commit fd744a12 authored by Collin Jackson's avatar Collin Jackson

Use unique integers as the key for history items to prevent collisions

parent 99346d00
...@@ -130,8 +130,9 @@ class Transition extends AnimatedComponent { ...@@ -130,8 +130,9 @@ class Transition extends AnimatedComponent {
} }
class HistoryEntry { class HistoryEntry {
HistoryEntry(this.route); HistoryEntry({ this.route, this.key });
final RouteBase route; final RouteBase route;
final int key;
// TODO(jackson): Keep track of the requested transition // TODO(jackson): Keep track of the requested transition
} }
...@@ -142,11 +143,12 @@ class NavigationState { ...@@ -142,11 +143,12 @@ class NavigationState {
if (route.name != null) if (route.name != null)
namedRoutes[route.name] = route; namedRoutes[route.name] = route;
} }
history.add(new HistoryEntry(routes[0])); history.add(new HistoryEntry(route: routes[0], key: _lastKey++));
} }
List<HistoryEntry> history = new List<HistoryEntry>(); List<HistoryEntry> history = new List<HistoryEntry>();
int historyIndex = 0; int historyIndex = 0;
int _lastKey = 0;
Map<String, RouteBase> namedRoutes = new Map<String, RouteBase>(); Map<String, RouteBase> namedRoutes = new Map<String, RouteBase>();
RouteBase get currentRoute => history[historyIndex].route; RouteBase get currentRoute => history[historyIndex].route;
...@@ -159,7 +161,7 @@ class NavigationState { ...@@ -159,7 +161,7 @@ class NavigationState {
} }
void push(RouteBase route) { void push(RouteBase route) {
HistoryEntry historyEntry = new HistoryEntry(route); HistoryEntry historyEntry = new HistoryEntry(route: route, key: _lastKey++);
history.insert(historyIndex + 1, historyEntry); history.insert(historyIndex + 1, historyEntry);
historyIndex++; historyIndex++;
} }
...@@ -224,9 +226,8 @@ class Navigator extends StatefulComponent { ...@@ -224,9 +226,8 @@ class Navigator extends StatefulComponent {
} }
if (content == null) if (content == null)
continue; continue;
String key = historyEntry.route.key;
Transition transition = new Transition( Transition transition = new Transition(
key: key, key: historyEntry.key.toString(),
content: content, content: content,
direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse, direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse,
interactive: (i == state.historyIndex), interactive: (i == state.historyIndex),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment