Implicit Flutter Animations

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

Part 2: Implicit Animations in Action

08. Create a Multi-Selection 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: 07. Create a Card Flip Animation Next episode: 09. Animate an Item Switcher

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: 08. Create a Multi-Selection 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

So far, we鈥檝e seen how to select and animate a sigle item. In this episode, we would learn how to create a multi selection animation. This is a common feature in many apps and we would cover both the setup and the animation.

class ExtraItem extends StatefulWidget {
  final Extra extra;
  final ValueChanged<bool> onSelected;

  const ExtraItem({Key? key, required this.extra, required this.onSelected}) : super(key: key);
...

class _ExtraItemState extends State<ExtraItem> {
    bool _isSelected = false;
    @override
    Widget build(BuildContext context) {
        return InkWell(
            onTap: () {
                setState(() {
                    _isSelected = !_isSelected;
                    widget.onSelected(_isSelected);
                });
            },
            child: Container(
                ...
ExtraItem(
    extra: extras[i],
    onSelected: (bool value) {
        if (value) {
            _selectedExtras.add(extras[i]);
        } else {
            _selectedExtras.remove(extras[i]);
        }
        setState(() {});
    },
)
child: Column(
    children: [
        AnimatedContainer(
            duration: const Duration(milliseconds: 500),
            padding: const EdgeInsets.all(24),
            decoration: BoxDecoration(
                shape: BoxShape.circle,
                border: _isSelected
                    ? Border.all(
                        color: colorScheme.secondary,
                        width: 2,
                        )
                    : null,
            ),
            child: Image.asset(
                ...
            ),
        ),
        AnimatedDefaultTextStyle(
            duration: const Duration(milliseconds: 500),
            style: TextStyle(
              color: Colors.black,
              fontWeight: _isSelected ? FontWeight.w600 : FontWeight.normal,
            ),
            child: Text(
              widget.extra.name,
            ),
        ),
    ],
),