I'm trying to fetch data from Cloud Firestore on flutter but as soon as I import the cloud_firestore.dart package, the app doesn't even build and crashes instantly with a lot of errors.
https://hastebin.com/esuzizuzod.sql this is the error it throws.
And this is the code
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
Future<void> main() async {
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Firestore Demo"),
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection("users").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Text("Loading data...Please wait!");
} else {
return Column(
children: <Widget>[
Text(snapshot.data.documents[0]["name"]),
Text(snapshot.data.documents[0]["age"]),
Text(snapshot.data.documents[0]["role"]),
],
);
}
}),
);
}
}
I have also implemented all the packages in the pubspec.yaml file.
Does anyone know how to fix this?
Thanks