Skip to content

Commit

Permalink
Fixed bug when popping.
Browse files Browse the repository at this point in the history
  • Loading branch information
Salby committed Aug 26, 2019
1 parent ef9c56d commit b1ea0ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.2.0+1] - 2019-08-26

### Fixes
- Fixed a bug where `MorpheusPageRoute` couldn't re-use the existing `RenderBox` and would throw an exception when popping a layer in the navigation stack.

## [1.2.0] - 2019-08-26

### Added
Expand Down
21 changes: 18 additions & 3 deletions lib/page_routes/morpheus_page_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,31 @@ class MorpheusPageRoute<T> extends PageRoute<T> {
/// This only affects bidirectional transitions.
final bool scaleChild;

RenderBox _renderBox() {
/// Returns a [RenderBox] from a [GlobalKey] if one is provided, either
/// through the [parentKey] parameter or [settings.arguments].
///
/// If no [GlobalKey] is provided, this method returns null.
RenderBox _getRenderBox() {
// Return the stored [RenderBox] if it exists.
if (_renderBox != null) return _renderBox;

final arguments = settings.arguments as MorpheusRouteArguments;
final key = parentKey ?? arguments?.parentKey;

// Return null if [key] is null.
if (key == null) return null;

return key.currentContext.findRenderObject();
// Get the [RenderBox].
final renderBox = key.currentContext.findRenderObject();

// Store the [RenderBox] for later.
_renderBox = renderBox;

return renderBox;
}

RenderBox _renderBox;

@override
final Duration transitionDuration;

Expand Down Expand Up @@ -119,7 +134,7 @@ class MorpheusPageRoute<T> extends PageRoute<T> {

// Return page transition.
return MorpheusPageTransition(
renderBox: _renderBox(),
renderBox: _getRenderBox(),
context: context,
animation: animation,
secondaryAnimation: secondaryAnimation,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: morpheus
description: A Flutter package for easily implementing Material Design navigation transitions.
version: 1.2.0
version: 1.2.0+1
author: Sander Dalby Larsen <[email protected]>
homepage: https://github.com/salby/morpheus

Expand Down

0 comments on commit b1ea0ed

Please sign in to comment.