0

can anyone convert this function and body to stream builder i want to get countinous updated data instead of one time calling (Streambuilder instead of Futurebuilder)

issue: with this future builder is when something is change on the database its refresh the whole list

Function

Future fetch() async {
  final session = await account.get();
  sessionid = session.$id;
  final documentList = await databases.listDocuments(
      databaseId: '123456789',
      collectionId: '123456789',
      queries: [
        Query.orderDesc('\$id'),
        Query.limit(25),
      ]);
  final documents = documentList.documents;

  items.clear();

  items.addAll(documents.map((doc) {
    final epTitle = doc.data['epTitle'];
    final epNo = doc.data['epNo'];
    final epDuration = doc.data['epDuration'];

    return {
      ...doc.data,
      'epTitle': epTitle,
      'epNo': epNo,
      'epDuration': epDuration,
    };
  }));
}

Body

FutureBuilder(
        future: fetch(),
        builder: (context, snapshot) {
          if (snapshot.connectionState ==
          ConnectionState.waiting) {
          return Text('waiting');
          } else if (snapshot.hasError) {
          checkInternet();
          return Text('${snapshot.error}');
          } else if (snapshot.connectionState ==
          ConnectionState.done) {
          return  ListView.builder(
          itemCount: snapshot.length,
          itemBuilder: (context, index) {
            //list data
          });
          }  else{
          return Text('something went wrong');
          }}
        );

i searched nothing found

iamrishan
  • 94
  • 6
  • What backend are you using? If that's firebase, you need to start by using .snapshots() and not .get(). In other words, you need a Stream... just changing from FutureBuilder to StreamBuilder won't be enough. – Randal Schwartz Aug 23 '23 at 05:35
  • backend is appwrite. get works fine in appwrite. yeah i know just changing from FutureBuilder to StreamBuilder won't be enough. thats what iam asking convert it for me – iamrishan Aug 24 '23 at 11:46
  • You want Appwrite Realtime, described at https://appwrite.io/docs/realtime – Randal Schwartz Aug 24 '23 at 16:04
  • looked the whole docs. they only show how to get the data from their end. they dont show futurebuilder or streambuilder code. – iamrishan Aug 24 '23 at 16:14

0 Answers0