jeudi 19 novembre 2020

Flutter: How to test a widgets who contains a StreamBuilder?

I'm new on Flutter and i want add Widgets tests to my app. But i have some problems and questions about widgets tests little more complex that flutter documentation. Indeed i have a Scaffold widget with this body :

body: StreamBuilder<List<UserData>> (
        stream: DatabaseService().searchUser(searchValue),
        builder: (context, snapshot) {
          if (snapshot.hasData && searchValue.length >= 3){
            return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (context, index) {
                return ListTile(
                  onTap: () {
                    Navigator.pushReplacementNamed(context, '/friends/search/details', arguments: snapshot.data[index]);
                  },
                  title: Text(snapshot.data[index].name),
                );
              }
            );
          }
          return Center();
        },
      )

The first question is : It is necessary to test this StreamBuilder ? And if yes : How can i mock the stream and test this widgets ?

Aucun commentaire:

Enregistrer un commentaire