AnimatedList Flutter :
Screenshot :

import 'package:flutter/material.dart'; import 'dart:math'; void main() => runApp(MyApp()); class Item { Item({this.name}); String name; } class MyApp extends StatelessWidget { const MyApp({Key key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'AnimatedList Flutter Tutorial', home: ListViewAnimatedScreen(), ); } } class ListViewAnimatedScreen extends StatefulWidget { @override _AnimatedListState createState() => _AnimatedListState(); } class _AnimatedListState extends State<ListViewAnimatedScreen> { List<Item> items = new List(); final GlobalKey<AnimatedListState> listKey = GlobalKey<AnimatedListState>(); var rng = new Random(); _addItem() { setState(() { listKey.currentState .insertItem(items.length, duration: const Duration(seconds: 1)); items.add(new Item(name: "Flutter Tutorial")); }); } _removeItem() { setState(() { int id = rng.nextInt(items.length); listKey.currentState.removeItem( id, (context, animation) => buildItem(context, 0, animation), duration: const Duration(milliseconds: 250), ); items.removeAt(id); }); } Widget buildItem( BuildContext context, int index, Animation<double> animation) { return SizeTransition( key: ValueKey<int>(index), axis: Axis.vertical, sizeFactor: animation, child: SizedBox( child: ListTile( title: Text('${items[index].name}'), ), ), ); } @override Widget build(BuildContext context) { final Map<int, Animation<double>> animations = <int, Animation<double>>{}; return Scaffold( appBar: AppBar( title: Text("AnimatedList"), actions: <Widget>[ IconButton( icon: const Icon(Icons.add), onPressed: _addItem, ), IconButton( icon: const Icon(Icons.remove), onPressed: _removeItem, ) ], ), body: Directionality( textDirection: TextDirection.ltr, child: AnimatedList( key: listKey, initialItemCount: items.length, itemBuilder: (context, index, animation) { return buildItem(context, index, animation); }, ))); } }
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