add static method to create material hero controller (#61662)

This commit is contained in:
chunhtai 2020-07-17 14:26:03 -07:00 committed by GitHub
parent 14dcbb2d84
commit 09dfca6f5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View File

@ -536,6 +536,17 @@ class MaterialApp extends StatefulWidget {
@override
_MaterialAppState createState() => _MaterialAppState();
/// The [HeroController] used for Material page transitions.
///
/// Used by the [MaterialApp].
static HeroController createMaterialHeroController() {
return HeroController(
createRectTween: (Rect begin, Rect end) {
return MaterialRectArcTween(begin: begin, end: end);
},
);
}
}
class _MaterialScrollBehavior extends ScrollBehavior {
@ -572,7 +583,7 @@ class _MaterialAppState extends State<MaterialApp> {
@override
void initState() {
super.initState();
_heroController = HeroController(createRectTween: _createRectTween);
_heroController = MaterialApp.createMaterialHeroController();
}
@override
@ -583,14 +594,10 @@ class _MaterialAppState extends State<MaterialApp> {
// old Navigator won't be disposed (and thus won't unregister with its
// observers) until after the new one has been created (because the
// Navigator has a GlobalKey).
_heroController = HeroController(createRectTween: _createRectTween);
_heroController = MaterialApp.createMaterialHeroController();
}
}
RectTween _createRectTween(Rect begin, Rect end) {
return MaterialRectArcTween(begin: begin, end: end);
}
// Combine the Localizations for Material with the ones contributed
// by the localizationsDelegates parameter, if any. Only the first delegate
// of a particular LocalizationsDelegate.type is loaded so the

View File

@ -834,6 +834,15 @@ void main() {
expect(find.text('regular page one'), findsNothing);
expect(find.text('regular page two'), findsNothing);
});
testWidgets('MaterialApp does create HeroController with the MaterialRectArcTween', (WidgetTester tester) async {
final HeroController controller = MaterialApp.createMaterialHeroController();
final Tween<Rect> tween = controller.createRectTween(
const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
const Rect.fromLTRB(0.0, 0.0, 20.0, 20.0)
);
expect(tween, isA<MaterialRectArcTween>());
});
}
class MockAccessibilityFeature implements AccessibilityFeatures {