Skip to content

Commit

Permalink
[animations] add routeSettings and imageFilter options to showModal (#…
Browse files Browse the repository at this point in the history
…279)

* [animations] add routeSettings and imageFilter options to showModal

* [animations] update version to 2.1.0-nullsafety.1

Co-authored-by: Shi-Hao Hong <[email protected]>
  • Loading branch information
britannio and Shi-Hao Hong authored Feb 23, 2021
1 parent e82599a commit 41eb920
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/animations/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [2.0.0-nullsafety.1] - February 6, 2021

* Add `routeSettings` and `filter` option to `showModal`.

## [2.0.0-nullsafety.0] - November 16, 2020

* Migrates to null safety.
Expand Down
13 changes: 11 additions & 2 deletions packages/animations/lib/src/modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' as ui;

import 'package:flutter/material.dart';

import 'fade_scale_transition.dart';
Expand Down Expand Up @@ -51,6 +53,8 @@ Future<T?> showModal<T>({
ModalConfiguration configuration = const FadeScaleTransitionConfiguration(),
bool useRootNavigator = true,
required WidgetBuilder builder,
RouteSettings? routeSettings,
ui.ImageFilter? filter,
}) {
String? barrierLabel = configuration.barrierLabel;
// Avoid looking up [MaterialLocalizations.of(context).modalBarrierDismissLabel]
Expand All @@ -68,6 +72,8 @@ Future<T?> showModal<T>({
transitionDuration: configuration.transitionDuration,
reverseTransitionDuration: configuration.reverseTransitionDuration,
builder: builder,
routeSettings: routeSettings,
filter: filter,
),
);
}
Expand All @@ -91,8 +97,11 @@ class _ModalRoute<T> extends PopupRoute<T> {
required this.reverseTransitionDuration,
required _ModalTransitionBuilder transitionBuilder,
required this.builder,
}) : assert(!barrierDismissible || barrierLabel != null),
_transitionBuilder = transitionBuilder;
RouteSettings? routeSettings,
ui.ImageFilter? filter,
}) : assert(!barrierDismissible || barrierLabel != null),
_transitionBuilder = transitionBuilder,
super(filter: filter, settings: routeSettings);

@override
final Color? barrierColor;
Expand Down
2 changes: 1 addition & 1 deletion packages/animations/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: animations
description: Fancy pre-built animations that can easily be integrated into any Flutter application.
version: 2.0.0-nullsafety.0
version: 2.0.0-nullsafety.1
homepage: https://github.com/flutter/packages/tree/master/packages/animations

environment:
Expand Down
84 changes: 84 additions & 0 deletions packages/animations/test/modal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:ui' as ui;

import 'package:animations/src/modal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -456,8 +458,90 @@ void main() {
expect(find.byKey(topKey), findsNothing);
},
);

testWidgets(
'showModal builds a new route with specified route settings',
(WidgetTester tester) async {
const RouteSettings routeSettings = RouteSettings(
name: 'route-name',
arguments: 'arguments',
);

final Widget button = Builder(builder: (BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: () {
showModal<void>(
context: context,
configuration: _TestModalConfiguration(),
routeSettings: routeSettings,
builder: (BuildContext context) {
return const _FlutterLogoModal();
},
);
},
child: const Icon(Icons.add),
),
);
});

await tester.pumpWidget(_boilerplate(button));
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();

// New route containing _FlutterLogoModal is present.
expect(find.byType(_FlutterLogoModal), findsOneWidget);

// Expect the last route pushed to the navigator to contain RouteSettings
// equal to the RouteSettings passed to showModal
final ModalRoute<dynamic> modalRoute = ModalRoute.of(
tester.element(find.byType(_FlutterLogoModal)),
)!;
expect(modalRoute.settings, routeSettings);
},
);

testWidgets(
'showModal builds a new route with specified image filter',
(WidgetTester tester) async {
final ui.ImageFilter filter = ui.ImageFilter.blur(sigmaX: 1, sigmaY: 1);

final Widget button = Builder(builder: (BuildContext context) {
return Center(
child: ElevatedButton(
onPressed: () {
showModal<void>(
context: context,
configuration: _TestModalConfiguration(),
filter: filter,
builder: (BuildContext context) {
return const _FlutterLogoModal();
},
);
},
child: const Icon(Icons.add),
),
);
});

await tester.pumpWidget(_boilerplate(button));
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();

// New route containing _FlutterLogoModal is present.
expect(find.byType(_FlutterLogoModal), findsOneWidget);
final BackdropFilter backdropFilter = tester.widget<BackdropFilter>(
find.byType(BackdropFilter),
);

// Verify new route's backdrop filter has been applied
expect(backdropFilter.filter, filter);
},
);
}

Widget _boilerplate(Widget child) => MaterialApp(home: Scaffold(body: child));

double _getOpacity(GlobalKey key, WidgetTester tester) {
final Finder finder = find.ancestor(
of: find.byKey(key),
Expand Down

0 comments on commit 41eb920

Please sign in to comment.