Animating items in a ListView inside a stream builder

Viewed 215

I was working on a flutter project which involved searching items from a SQL database and then displaying them inside a StreamBuilder. I wanted to add an animation when new items are added by using a package called "flutter_staggered_animations" but since every time the search happens all the items inside my ListView are refreshed and the animation happens for every item, How can I make the animation happen only for the new results/items(that weren't found in the previous search)? I'm new to flutter. the code for the body is down below

body: StreamBuilder(
        stream: _stream,
        builder: (BuildContext ctx, AsyncSnapshot snapshot){
          if(snapshot.data == null){
            return Container(
              child:Center(child: Text("Enter a search word")),
            );
          }
          if(snapshot.data == "waiting"){
            return Center(
              child: CircularProgressIndicator(),
            );
          }
          return ListView.builder(
            itemCount: snapshot.data.length <= 20 ? snapshot.data.length : 20,
            itemBuilder: (BuildContext context,int index){
              return AnimationConfiguration.staggeredList(
                position: index,
                duration: const Duration(milliseconds: 375),
                child: SlideAnimation(
                  verticalOffset: 50.0,
                  child: FadeInAnimation(
                    child: Container(
                      color: Colors.grey[300],
                      child: Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: ListTile(
                          // leading: snapshot.data.length!=2 ? null : CircleAvatar(),
                          title: Text(snapshot.data[index]["word"]),
                          subtitle: Text(snapshot.data[index]["definition"]),
                        ),
                      ),
                    ),
                  ),
                ),
              );
            },
          );
        },
      ),
0 Answers
Related