Unverified Commit 09dfca6f authored by chunhtai's avatar chunhtai Committed by GitHub

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

parent 14dcbb2d
......@@ -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
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment