Это ожидаемо, так как timeDilation является своего рода глобальным свойством, поэтому вам нужно устанавливать его каждый раз, когда вам нужно изменить скорость вашей анимации onTap
будет идеальным местом для этого,
проверьте измененный код ниже
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
class PhotoHero extends StatelessWidget {
const PhotoHero({Key key, this.photo, this.onTap, this.width})
: super(key: key);
final String photo;
final VoidCallback onTap;
final double width;
Widget build(BuildContext context) {
return SizedBox(
width: width,
child: Hero(
tag: photo,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
child: Image.asset(
photo,
fit: BoxFit.contain,
),
),
),
),
); }}
class HeroAnimation extends StatelessWidget {
Widget build(BuildContext context) {
//timeDilation = 10.0; // 1.0 means normal animation speed.
return Scaffold(
appBar: AppBar(
title: const Text('Basic Hero Animation'),
),
body: Center(
child: PhotoHero(
photo: '/images/flippers-alpha.png',
width: 300.0,
onTap: () {
timeDilation = 10.0;
Navigator.of(context).push(
MaterialPageRoute<void>(builder: (context) => SecondScreen()));
},
),
),
); }}
void main() {
runApp(MaterialApp(
routes: {
'/': (context) => HeroAnimation(),
'/second': (context) => SecondScreen(),
'/third': (context) => ThirdScreen(),
}, ));}
class ThirdScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
timeDilation = 1.0;
return Scaffold(
appBar: AppBar(
title: Title(color: Colors.red, child: Text('Dummy Title')),
),
); }}
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
//timeDilation = 1.0;
return Scaffold(
appBar: AppBar(
title: const Text('Flippers Page'),
),
body: Container(
// Set background to blue to emphasize that it's a new route.
color: Colors.lightBlueAccent,
padding: const EdgeInsets.all(16.0),
alignment: Alignment.topLeft,
child: PhotoHero(
photo: '/images/flippers-alpha.png',
width: 100.0,
onTap: () {
Navigator.of(context).pushNamed('/third');
},
),
),
); }}