In this recipe, we will use a FadeTransition into an AnimatedList:
- Create a new file in the lib folder, called animatedlist.dart.
- At the top of the file, import material.dart:
import 'package:flutter/material.dart';
- Create a stateful widget, calling it AnimatedListScreen:
class AnimatedListScreen extends StatefulWidget {
@override
_AnimatedListScreenState createState() =>
_AnimatedListScreenState();
}
class _AnimatedListScreenState extends State<AnimatedListScreen> {
@override
Widget build(BuildContext context) {
return Container();
}
}
- At the top of the _AnimatedListScreenState class, declare a GlobalKey that you will use to access the AnimatedList from anywhere within the class:
final GlobalKey<AnimatedListState> listKey = GlobalKey<AnimatedListState>();
- Under the GlobalKey, declare a List of int values, and set the list to contain numbers from 1 to 5, and a counter integer:
final List<int> _items ...