9

The PageController of a PageView has a function animateToPage which allows to define the curve effect during page swipe.

Future<void> animateToPage(
    int page, {
    @required Duration duration,
    @required Curve curve,
  })

I need to match it's behavior with that of the default swipe transition of PageView.

Any help?

pso
  • 819
  • 12
  • 25
  • page swipe from iOS style ? – Rubens Melo May 22 '19 at 06:09
  • it does not use `Curve` for swipes: it uses [physics](https://api.flutter.dev/flutter/widgets/PageView/physics.html) property - for more see `packages/flutter/lib/src/widgets/page_view.dart` source file – pskink May 22 '19 at 06:11
  • and more or less it follows `SpringSimulation` – pskink May 22 '19 at 06:47
  • Thanks @pskink, my problem is that I am not able to relate the Physics behavior with the Curves animation. However, Curves.ease as suggested by Rubens does seem to match with the default behavior of PageView scroll. – pso May 22 '19 at 06:59
  • no it is not - see https://api.flutter.dev/flutter/animation/Curves-class.html - i would say more realistic is `decelerate` or `easeOut*` – pskink May 22 '19 at 07:04
  • and how are you comparing these two effects with that of the PageView? – pso May 22 '19 at 07:11
  • 1
    how? this is more or less how [SpringSimulation](https://api.flutter.dev/flutter/physics/SpringSimulation-class.html) works – pskink May 22 '19 at 07:21
  • I will have to do further research before concluding. But thanks a lot for your help @pskink – pso May 22 '19 at 07:25

1 Answers1

2

As mentioned by @pskink in the comments, the default PageView transition animation relies on the physics applied by the user's gesture. Depending on the user's swipe, it's then translated to the page's transition animation.

On the other hand, PageController's animateToPage relies on the duration set and curve. To emulate a smooth swipe, you can use Curves.ease as previously mentioned.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Omatt
  • 8,564
  • 2
  • 42
  • 144