Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# Name/Organization <email address>

Google Inc.
Britannio Jarrett <britanniojarrett@gmail.com>
9 changes: 8 additions & 1 deletion packages/animations/lib/src/open_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class OpenContainer<T extends Object> extends StatefulWidget {
this.transitionDuration = const Duration(milliseconds: 300),
this.transitionType = ContainerTransitionType.fade,
this.useRootNavigator = false,
this.routeSettings,
}) : assert(closedColor != null),
assert(openColor != null),
assert(closedElevation != null),
Expand Down Expand Up @@ -257,6 +258,9 @@ class OpenContainer<T extends Object> extends StatefulWidget {
/// to the nearest navigator.
final bool useRootNavigator;

/// Provides additional data to the [openBuilder] route pushed by the Navigator.
final RouteSettings routeSettings;

@override
_OpenContainerState<T> createState() => _OpenContainerState<T>();
}
Expand Down Expand Up @@ -295,6 +299,7 @@ class _OpenContainerState<T> extends State<OpenContainer<T>> {
transitionDuration: widget.transitionDuration,
transitionType: widget.transitionType,
useRootNavigator: widget.useRootNavigator,
routeSettings: widget.routeSettings,
));
if (widget.onClosed != null) {
widget.onClosed(data);
Expand Down Expand Up @@ -409,6 +414,7 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
@required this.transitionDuration,
@required this.transitionType,
@required this.useRootNavigator,
@required RouteSettings routeSettings,
}) : assert(closedColor != null),
assert(openColor != null),
assert(closedElevation != null),
Expand All @@ -435,7 +441,8 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
middleColor: middleColor,
),
_closedOpacityTween = _getClosedOpacityTween(transitionType),
_openOpacityTween = _getOpenOpacityTween(transitionType);
_openOpacityTween = _getOpenOpacityTween(transitionType),
super(settings: routeSettings);

static _FlippableTweenSequence<Color> _getColorTween({
@required ContainerTransitionType transitionType,
Expand Down
54 changes: 54 additions & 0 deletions packages/animations/test/open_container_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,50 @@ void main() {
expect(tester.getSize(find.text('Opened')),
equals(tester.getSize(find.byKey(appKey))));
});

testWidgets(
'Verify routeSettings passed to Navigator',
(WidgetTester tester) async {
final OpenContainerNavigatorObserver observer =
OpenContainerNavigatorObserver();

const RouteSettings routeSettings = RouteSettings(
name: 'route-name',
arguments: 'arguments',
);

final Widget openContainer = OpenContainer(
routeSettings: routeSettings,
closedBuilder: (BuildContext context, VoidCallback action) {
return GestureDetector(
onTap: action,
child: const Text('Closed'),
);
},
openBuilder: (BuildContext context, VoidCallback action) {
return GestureDetector(
onTap: action,
child: const Text('Open'),
);
},
);

await tester.pumpWidget(
MaterialApp(
home: openContainer,
navigatorObservers: <NavigatorObserver>[observer],
),
);

// Open the container
await tester.tap(find.text('Closed'));
await tester.pumpAndSettle();

// Expect the last route pushed to the navigator to contain RouteSettings
// equal to the RouteSettings passed to the OpenContainer
expect(observer.lastRoutePushed.settings, routeSettings);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining an Observer, the test could just use ModalRoute.of(tester.element(find.text('Open'))) to get the ModalRoute and check that ModalRoute.settings is set correctly to simplify things a little.

@britannio britannio Nov 11, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goderbauer Interesting, I've just made the suggested change!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned the wrong person, sorry!
cc @goderbauer

},
);
}

Color _getScrimColor(WidgetTester tester) {
Expand Down Expand Up @@ -1829,3 +1873,13 @@ class __RemoveOpenContainerExampleState
);
}
}

class OpenContainerNavigatorObserver extends NavigatorObserver {
Route<dynamic> get lastRoutePushed => _lastRoutePushed;
Route<dynamic> _lastRoutePushed;

@override
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
_lastRoutePushed = route;
}
}