Implicit Flutter Animations

Oct 4 2022 · Dart 2.17, Flutter 3.0, Visual Studio Code 1.7

Part 2: Implicit Animations in Action

07. Create a Card Flip Animation

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Create a Custom PageView Animation Next episode: 08. Create a Multi-Selection Animation

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 07. Create a Card Flip Animation

The student materials have been reviewed and are updated as of August 2022.

The updated material uses null safety and also deploys the use coding practises encouraged by the Flutter as per the Flutter lint rules and a few addons of practises that are considered good here at raywenderlich (see analysis_options.yaml in the material for more info).

Heads up... You鈥檙e accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You鈥檙e accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this episode, we would be creating a card flip animation. You鈥檒l learn how to trigger animations based on form interations. Let鈥檚 head over to the add_card_screen.

import 'dart:math' as math;
...
@override
Widget build(BuildContext context) {
    double rotationFactor = _isCvvFocused ? 1.0 : 0.0; // Add this
    ...
    // Paste this
    TweenAnimationBuilder(
        duration: const Duration(milliseconds: 1000),
        curve: Curves.fastOutSlowIn,
        tween: Tween(begin: rotationFactor, end: rotationFactor),
        builder: (context, value, child) {
        return Transform(
            transform: Matrix4.identity()
            ..setEntry(3, 2, 0.001) // perspective
            ..rotateY(math.pi * value),
            alignment: FractionalOffset.center,
            child: value < 0.5
                ? FrontCard(
                    cardNumber:
                        (formData['card_number'] as String?) ?? '-',
                    cardName: (formData['card_name'] as String?) ?? '-',
                    expiryDate: formData['expiry_date'] as DateTime?,
                )
                : BackCard(
                    cvv: (formData['cvv'] as String?) ?? '-',
                ),
        );
        },
    ),
class BackCard extends StatelessWidget {
  ...
  @override
  Widget build(BuildContext context) {
    return Transform(
      transform: Matrix4.identity()
        ..setEntry(3, 2, 0.001) // perspective
        ..rotateY(math.pi),
      alignment: FractionalOffset.center,
      child: Container(
          ...