mirror of
https://github.com/flutter/flutter
synced 2024-08-24 18:36:03 +00:00
Fixes the transition builder changing the Cupertino transition on Android. (#134790)
Fixes #124850. Changes the fallback for the builder on Android. Before the error was from the platform being changed mid Cupertino transition to iOS. If a default builder wasn't set for iOS (which a developer developing only for Android might not), then it defaulted to the Zoom transition. Which changing the transition while on the fly caused issues.
This commit is contained in:
parent
074114b85a
commit
2be5084b26
|
@ -771,8 +771,10 @@ class PageTransitionsTheme with Diagnosticable {
|
|||
platform = TargetPlatform.iOS;
|
||||
}
|
||||
|
||||
final PageTransitionsBuilder matchingBuilder =
|
||||
builders[platform] ?? const ZoomPageTransitionsBuilder();
|
||||
final PageTransitionsBuilder matchingBuilder = builders[platform] ?? switch (platform) {
|
||||
TargetPlatform.iOS => const CupertinoPageTransitionsBuilder(),
|
||||
TargetPlatform.android || TargetPlatform.fuchsia || TargetPlatform.windows || TargetPlatform.macOS || TargetPlatform.linux => const ZoomPageTransitionsBuilder(),
|
||||
};
|
||||
return matchingBuilder.buildTransitions<T>(route, context, animation, secondaryAnimation, child);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,6 +134,86 @@ void main() {
|
|||
expect(findOpenUpwardsPageTransition(), findsOneWidget);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
||||
|
||||
testWidgets('PageTransitionsTheme override builds a CupertinoPageTransition on android', (WidgetTester tester) async {
|
||||
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
|
||||
'/': (BuildContext context) => Material(
|
||||
child: TextButton(
|
||||
child: const Text('push'),
|
||||
onPressed: () { Navigator.of(context).pushNamed('/b'); },
|
||||
),
|
||||
),
|
||||
'/b': (BuildContext context) => const Text('page b'),
|
||||
};
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
pageTransitionsTheme: const PageTransitionsTheme(
|
||||
builders: <TargetPlatform, PageTransitionsBuilder>{
|
||||
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
|
||||
},
|
||||
),
|
||||
),
|
||||
routes: routes,
|
||||
),
|
||||
);
|
||||
|
||||
expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride);
|
||||
expect(find.byType(CupertinoPageTransition), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('push'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page b'), findsOneWidget);
|
||||
expect(find.byType(CupertinoPageTransition), findsOneWidget);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
||||
|
||||
testWidgets('CupertinoPageTransition on android does not block gestures on backswipe', (WidgetTester tester) async {
|
||||
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
|
||||
'/': (BuildContext context) => Material(
|
||||
child: TextButton(
|
||||
child: const Text('push'),
|
||||
onPressed: () { Navigator.of(context).pushNamed('/b'); },
|
||||
),
|
||||
),
|
||||
'/b': (BuildContext context) => const Text('page b'),
|
||||
};
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
pageTransitionsTheme: const PageTransitionsTheme(
|
||||
builders: <TargetPlatform, PageTransitionsBuilder>{
|
||||
TargetPlatform.android: CupertinoPageTransitionsBuilder(),
|
||||
},
|
||||
),
|
||||
),
|
||||
routes: routes,
|
||||
),
|
||||
);
|
||||
|
||||
expect(Theme.of(tester.element(find.text('push'))).platform, debugDefaultTargetPlatformOverride);
|
||||
expect(find.byType(CupertinoPageTransition), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('push'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page b'), findsOneWidget);
|
||||
expect(find.byType(CupertinoPageTransition), findsOneWidget);
|
||||
|
||||
await tester.pumpAndSettle(const Duration(minutes: 1));
|
||||
|
||||
final TestGesture gesture = await tester.startGesture(const Offset(5.0, 100.0));
|
||||
await gesture.moveBy(const Offset(400.0, 0.0));
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
|
||||
await tester.pumpAndSettle(const Duration(minutes: 1));
|
||||
|
||||
expect(find.text('push'), findsOneWidget);
|
||||
await tester.tap(find.text('push'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page b'), findsOneWidget);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
||||
|
||||
testWidgets('PageTransitionsTheme override builds a _FadeUpwardsTransition', (WidgetTester tester) async {
|
||||
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
|
||||
'/': (BuildContext context) => Material(
|
||||
|
|
Loading…
Reference in a new issue