Animare i widget in Flutter con animate_do

Mattepuffo's logo
Animare i widget in Flutter con animate_do

Animare i widget in Flutter con animate_do

animate_do è un'ottima libreria per Flutter che ci permette di animare i componenti.

E' compatibili con tutte le piattaforme al momento supportate da Flutter.

Per installarla:

flutter pub add animate_do

Si può animare tutto, anche le righe di una ListView:

import 'package:animate_do/animate_do.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  bool animate = true;
  late AnimationController controller;

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: ListView(
        padding: const EdgeInsets.all(8),
        children: <Widget>[
          FadeInDown(
            delay: const Duration(seconds: 1),
            animate: animate,
            child: const ListTile(
              title: Text('List 1'),
            ),
          ),
          FadeInDown(
            animate: animate,
            delay: const Duration(seconds: 2),
            child: const ListTile(
              title: Text('List 2'),
            ),
          ),
          FadeInDown(
            animate: animate,
            delay: const Duration(seconds: 3),
            child: const ListTile(
              title: Text('List 3'),
            ),
          ),
        ],
      ),
    );
  }
}

Enjoy!


Condividi

Commentami!