Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[animations] PageTransitionSwitcher doesn't animate smoothly if reverse is true on Flutter 2.8.0  #95270

@gcostaapps

Description

@gcostaapps

When I use PageTransitionSwitcher in Flutter with reverse flag true there is an bug in the exit animation. I'm using the newest version of animations package (2.0.2).

This bug is present on flutter version 2.8.0 but it was not on 2.5.3.

There is an video showing the comparison between the animation in the two versions. Note that the reverse animation (red to blue, in the 5s of video) of version 2.8.0 the red container overlaps the blue one until the animation is complete. In this example the bug doesn't seem to cause much trouble, but if the page as a lot of widgets and the two pages transitioning is very different the animation is really annoying.

2.8.0 2.5.3
2.8.0.mp4
2.5.3.mp4

Steps to Reproduce

  1. Run flutter run on the sample below
  2. Click the fab to play the animation
  3. Click the fab to reverse the animation
  4. Observe that the animation isn't smooth during the reversal
Code sample
import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

void main() {
  timeDilation = 5;
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _firsPage = true;

  void _changePage() {
    setState(() {
      _firsPage = !_firsPage;
    });
  }

  @override
  Widget build(BuildContext context) {
    const text = 'Flutter 2.5.3';
    return Scaffold(
      body: Center(
        child: PageTransitionSwitcher(
          reverse: _firsPage,
          duration: const Duration(milliseconds: 200),
          transitionBuilder: (
            Widget child,
            Animation<double> animation,
            Animation<double> secondaryAnimation,
          ) {
            return SharedAxisTransition(
              child: child,
              animation: animation,
              secondaryAnimation: secondaryAnimation,
              transitionType: SharedAxisTransitionType.horizontal,
            );
          },
          child: _firsPage
              ? Container(
                  key: const ValueKey(1),
                  padding: const EdgeInsets.all(20),
                  color: Colors.blue,
                  child: const Text(text, style: TextStyle(fontSize: 40)),
                )
              : Container(
                  key: const ValueKey(2),
                  padding: const EdgeInsets.all(20),
                  color: Colors.red,
                  child: const Text(text, style: TextStyle(fontSize: 40)),
                ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
          onPressed: _changePage,
          tooltip: 'ChangePage',
          child: const Icon(Icons.update)),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: animationAnimation APIsc: regressionIt was better in the past than it is nowengineflutter/engine related. See also e: labels.found in release: 2.8Found to occur in 2.8found in release: 2.9Found to occur in 2.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions