WosLovesLife / flutter_flip_view

BSD 2-Clause "Simplified" License
57 stars 15 forks source link

multiple back view #6

Open zeyexci opened 4 years ago

zeyexci commented 4 years ago

is it possible to have multiple back view? for example, A => B, A => C, A => D, A => E

WosLovesLife commented 4 years ago

Sure. you should add a AnimationStatusListener into the AnimationController in initState function. inside the callback, you can invoke the setState function to change the view.

here is an example:

class _SimpleExampleState extends State<SimpleExample> with SingleTickerProviderStateMixin {
  int currentSide = 1;

  @override
  void initState() {
    super.initState();

    ...
    _animationController.addStatusListener((AnimationStatus status){
      if(status == AnimationStatus.dismissed){
        setState(() {
          currentSide += 1;
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Center(
            child: FlipView(
              animationController: _curvedAnimation,
              front: _buildCard('A', () => _flip(true)),
              back: _buildCard('B$currentSide', () => _flip(false)),
            ),
          ),
        ),
      ),
    );
  }
}