Home > OS >  Why is cloud_firestore not working in FlutterFire even after complete configuration?
Why is cloud_firestore not working in FlutterFire even after complete configuration?

Time:05-28

I want to fetch data from Firebase and for that I have integrated Firebase to my Flutter app SciFish.

In pubspec.yaml, I have added the plugins:

dependencies:
   firebase_core: ^1.17.0
   cloud_firestore: ^3.1.16

flutterfire configure command in the root directory looks fine:

flutterfire configure result

I can see the android/app/google-services.json :

google-services.json path pic

After initialization Firebase, my main() looks like:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

In TemperaturePage, I created the method to fetch the data but the print statements inside the await doesn't work.

final _firestore = FirebaseFirestore.instance;
void temperatureStream() async{
    print('this prints');
    await for(var snapshot in _firestore.collection('temperature').snapshots()){
      for(var temp in snapshot.docs){
        print('this doesnt');
        print(temp.data());
      }
   }
}

ListTile(
   title: const Text('Show Temperature'),
   onTap: () {
       temperatureStream();
   }
)

The run console says,

Performing hot restart...
Syncing files to device sdk gphone64 x86 64...
Restarted application in 1,994ms.
D/EGL_emulation(10450): app_time_stats: avg=6669.94ms min=6669.94ms max=6669.94ms count=1
D/EGL_emulation(10450): app_time_stats: avg=36988.71ms min=420.94ms max=73556.49ms count=2
D/EGL_emulation(10450): app_time_stats: avg=128.04ms min=13.50ms max=930.64ms count=9
I/flutter (10450): this prints
W/DynamiteModule(10450): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule(10450): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller(10450): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
D/EGL_emulation(10450): app_time_stats: avg=345.94ms min=10.15ms max=4548.11ms count=14
I/flutter (10450): this prints
D/EGL_emulation(10450): app_time_stats: avg=131.44ms min=14.88ms max=2143.03ms count=19
I/flutter (10450): this prints

Tried solving these warnings that appear on the first onTap(), but temperature collection

Build platform: Windows 10Pro Flutter Version : 2.10.4 Dart Version : 2.16.2

CodePudding user response:

As discussed in our meeting, there was an empty space in your collection name.

  • "temperature "

And that's why it was returning null.

Future Tip

  • Make sure to check there are no empty spaces in your firebase collection names while structuring the data :)

Cheers!

  • Related