Visitar URL original
[animations] add routeSettings and imageFilter options to showModal by britannio · Pull Request #279 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[animations] add routeSettings and imageFilter options to showModal
  • Loading branch information
britannio committed Feb 6, 2021
commit fc6d42d7b72c0183503f4af68a842a9c310f3975
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
83 changes: 83 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,89 @@ 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(
Comment thread
shihaohong marked this conversation as resolved.
Resolved
'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