'Error: Unable to read Data and display in Flutter using GetX and Firestore

I am very new to Dart, and coding in general. I have produced this code after watching tutorials on YouTube. For the most part, I have been able to troubleshoot most of my problems on my own, yet I cannot figure out my most recent errors. I was successful to create record in firestore but I am not able to read it. When I tried to read I am getting this error

Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 910ms.
[GETX] Instance "AuthController" has been created
[GETX] Instance "AuthController" has been initialized
[GETX] Instance "GetMaterialController" has been created
[GETX] Instance "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /ProfileScreen
[GETX] REMOVING ROUTE /
[GETX] Instance "ProfileController" has been created
[GETX] Instance "ProfileController" has been initialized
W/DynamiteModule( 5257): Local module descriptor class for 
com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule( 5257): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller( 5257): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
W/ProviderInstaller( 5257): Failed to report request stats: reportRequestStats [class android.content.Context, long, long]

my Profile Page Code is:-

class ProfileScreen extends StatelessWidget {
const ProfileScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(
  title: Text('Profile Page'),
  actions: [
  IconButton(
       onPressed: () {
           authcontroller.loggout();
        },
         icon: Icon(Icons.power_settings_new),
       )
     ],
  ),
  body: GetX<ProfileController>(
    init: Get.put<ProfileController>(ProfileController()),
    builder: (ProfileController profileController){
      return SafeArea(
        child: Container(
          margin: EdgeInsets.symmetric(horizontal: 4, vertical: 4),
            child: ListView.builder(
              itemCount: profileController.profiles.length,
                itemBuilder: (BuildContext context, int index) {
                print(profileController.profiles[index].firstName);
                final _profileModel = profileController.profiles[index];
                return  Column(
                    //mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        _profileModel.firstName,
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        'Father Name: fatherName',
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        'Address: address',
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        'PhoneNumber: phoneNumber',
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Text(
                        'School: schoolName',
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      Text(
                        'Class: stdClass',
                        style: TextStyle(
                          fontSize: 20,
                        ),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      SizedBox(
                        height: 50,
                        width: 200,
                        child: ElevatedButton(
                            onPressed: () {

                              Get.to(EditProfile());
                            },
                            child: Text('Edit')),
                      ),
                      SizedBox(height: 10,),
                      SizedBox(
                        height: 50,
                        width: 200,
                        child: ElevatedButton(
                            onPressed: () {

                              Get.to(AddProfileScreen());
                            },
                            child: Text('Add')),
                      )
                    ],


                  // child: Row(
                  //   children: [Text(_profileModel.firstName), Text('hello'), Text(_profileModel.lastName)],


                  );

                })

        ),
      );
    },
  ),
);
}
}

my DB file :-

      import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:lms_definer/constants/constants.dart';
  import 'package:lms_definer/model/profileModel.dart';
  
  class FirestoreDb {
    static createProfile(ProfileModel profilemodel) async {
      await firebaseFirestore.collection('users').doc(auth.currentUser!.uid)
          .collection('profile')
          .add({
        'firstName': profilemodel.firstName,
        'lastName': profilemodel.lastName,
        'parentName': profilemodel.parentName,
        'phoneNumber': profilemodel.phoneNumber,
        'address': profilemodel.address,
        'schoolName': profilemodel.schoolName,
        'stdClass': profilemodel.stdClass,
        'createdOn': Timestamp.now(),
        'isDone': true
      });
    }
  
    static Stream<List<ProfileModel>> profileStream() {
      return firebaseFirestore
          .collection('user')
          .doc(auth.currentUser!.uid)
          .collection('profile')
          .snapshots()
          .map((QuerySnapshot query) {
        List<ProfileModel> profiles = [];
        for (var profile in query.docs) {
          final profileModel =
          ProfileModel.fromDocmentSnapshot(documentSnapshot: profile);
          profiles.add(profileModel);
        }
        return profiles;
      });
    }
  
    static updateProfile(bool isDone, documentId) {
      firebaseFirestore
          .collection('users')
          .doc(auth.currentUser!.uid)
          .collection('profiles')
          .doc(documentId)
          .update(
          {
            'isDone': isDone,
          }
      );
    }
  
    static deleteProfile(String documentID) {
      firebaseFirestore.collection('users').doc(auth.currentUser!.uid).collection(
          'profile').doc(documentID).delete();
  
  }}

my controller file:-

      import 'package:lms_definer/model/profileModel.dart';
  import 'package:lms_definer/helper/firestore_db.dart';
  import 'package:get/get.dart';
  
  class ProfileController extends GetxController{
    Rx<List<ProfileModel>> profileList = Rx<List<ProfileModel>>([]);
    List<ProfileModel> get profiles => profileList.value;
  
    @override
    void onReady(){
      profileList.bindStream(FirestoreDb.profileStream());
    }
  }

Please help me understand what is wrong here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source