Animated ListView In Flutter

Animated ListView In Flutter :

Screenshot :

Animated ListView In Flutter

animator.dart

import 'dart:async';

import 'package:flutter/material.dart';

class Animator extends StatefulWidget {
  final Widget child;
  final Duration time;
  Animator(this.child, this.time);
  @override
  _AnimatorState createState() => _AnimatorState();
}

class _AnimatorState extends State<Animator>
    with SingleTickerProviderStateMixin {
  Timer timer;
  AnimationController animationController;
  Animation animation;
  @override
  void initState() {
    super.initState();
    animationController =
        AnimationController(duration: Duration(milliseconds: 290), vsync: this);
    animation =
        CurvedAnimation(parent: animationController, curve: Curves.easeInOut);
    timer = Timer(widget.time, animationController.forward);
  }

  @override
  void dispose() {
    super.dispose();
    timer.cancel();
    animationController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
        animation: animation,
        child: widget.child,
        builder: (BuildContext context, Widget child) {
          return Opacity(
              opacity: animation.value,
              child: Transform.translate(
                  offset: Offset(0.0, (1 - animation.value) * 20),
                  child: child));
        });
  }
}

Timer timer;
Duration duration = Duration();
wait() {
  if (timer == null || !timer.isActive) {
    timer = Timer(Duration(microseconds: 120), () {
      duration = Duration();
    });
  }
  duration += Duration(milliseconds: 100);
  return duration;
}

class WidgetAnimator extends StatelessWidget {
  final Widget child;
  WidgetAnimator(this.child);
  @override
  Widget build(BuildContext context) {
    return Animator(child, wait());
  }
}

main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Tutorial',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: AnimationListPage());
  }
}

class AnimationListPage extends StatefulWidget {
  @override
  createState() => _AnimationListState();
}

class _AnimationListState extends State<AnimationListPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Flutter Animated ListView'),
        ),
        body: ListView.builder(
            itemCount: 6,
            itemBuilder: (BuildContext context, int index) {
              return WidgetAnimator(Card(
                  margin: EdgeInsets.all(10),
                  elevation: 5,
                  child: Container(
                      padding: EdgeInsets.all(10),
                      child: Text('Flutter Tutorial',
                          style: TextStyle(fontSize: 15)))));
            }));
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in