1

StreamBuilder widget works well on debug mode but on release mode returns null. I had tried several solutions found here, but none worked. So maybe I am missing something in my code. Here are my source codes.

store_screen.dart

StreamBuilder<List<StoreItem>>(
  initialData: [],
  stream: widget.bloc.getStores(),
  builder: (context, querySnapshot) {
    if (querySnapshot.connectionState == ConnectionState.active) {
      List<StoreItem> stores = querySnapshot.data!;
      ....
    } else if (querySnapshot.hasError) {
      print(querySnapshot.toString());
      ....
    } else {
      ....
      return Center(
        child: CircularProgressIndicator(),
      );
    }
  },
),

store_bloc.dart

Stream<List<StoreItem>> getStores() {
  final snapshot = database.getDataFromCollection('owner');

  return snapshot.map((event) => event.docs
      .map((e) => StoreItem.fromMap(e.data() as Map<String, dynamic>))
      .toList());
}
4xMafole
  • 479
  • 1
  • 8
  • 20

1 Answers1

0

If it works perfectly on debug mode, but failing only on release version, then it can be because of you didn’t add app hash code on firebase config. Also I suggest to check privacy rules of database and make it properly for production.

Jakhongir Anasov
  • 1,207
  • 7
  • 16
  • I have added the hash codes on firebase config and also for the firestore rules are well implemented. – 4xMafole Sep 07 '22 at 15:08
  • Then run app on device in release mode with flutter run —release. And let me know what is the cause of error – Jakhongir Anasov Sep 08 '22 at 09:13
  • I had run the app in release mode, it returns an error that the snapshot is null. This means that the snapshot has no data. But in debug mode the snapshot has data that's the problem am facing. – 4xMafole Sep 08 '22 at 09:24