Qries

Subscribe Us

Advertisement

Add Listview Animation

 




Code:

import 'package:flutter/material.dart';

class ListView5 extends StatefulWidget {
  @override
  _ListView5State createState() => _ListView5State();
}

class _ListView5State extends State<ListView5> {
  int count = 2;
  GlobalKey<AnimatedListState> key = GlobalKey();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      body: AnimatedList(
          key: key,
          initialItemCount: count,
          itemBuilder: (context, index, animation) => AlignTransition(
              alignment: animation.drive(
                AlignmentTween(
                    begin: Alignment.topRight, end: Alignment.topLeft),
              ),
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: Text("Hello #$index",
                    style: TextStyle(
                        color: Colors.white, fontWeight: FontWeight.bold)),
              ))),
      floatingActionButton: FloatingActionButton.extended(
        backgroundColor: Colors.white,
        heroTag: UniqueKey(),
        key: UniqueKey(),
        onPressed: () {
          setState(() {
            key.currentState.insertItem(count, duration: Duration(seconds: 1));
            count++;
          });
        },
        label: Text("Add Item", style: TextStyle(color: Colors.black)),
      ),
    );
  }
}

Post a Comment

0 Comments