skip to Main Content

I resently came across this error while building my flutter app.

======== Exception caught by widgets library =======================================================
The following _CastError was thrown building StreamBuilder<QuerySnapshot<Object?>>(dirty, state: _StreamBuilderBaseState<QuerySnapshot<Object?>, AsyncSnapshot<QuerySnapshot<Object?>>>#97a1b):
Null check operator used on a null value

The relevant error-causing widget was:
StreamBuilder<QuerySnapshot<Object?>> StreamBuilder
===============================================================================

This occured right after i try to display a screen/layout which has to stream data from firestore

Here is my firebase instance and the code I tried on my own.

final Stream<QuerySnapshot> teachersRegistered = FirebaseFirestore.instance.
    collection('userData').snapshots();

StreamBuilder<QuerySnapshot<Object?>>(
    stream: teachersRegistered,
    builder: (context, snapshot) {
      if (snapshot.hasError) {
        return const Text('Error');
      } else if (snapshot.connectionState == ConnectionState.waiting) {
        return const Text("waiting for connection");
      } else if (snapshot.connectionState == ConnectionState.done) {
        return const Text("Online");
      } else if (snapshot.connectionState == ConnectionState.none) {
        return const Text("THere's no connection");
      } else if (snapshot.hasData) {
        List<DropdownMenuItem> teachersItem = [];
        for (int i = 0; i < snapshot.data!.docs.length; i++) {
          DocumentSnapshot data = snapshot.data!.docs[i];

          teachersItem.add(DropdownMenuItem(
            value: user!.uid,
            child: Column(
              children: [
                Text(data['name']),
              ],
            ),
          ));
        }
        return DropdownButton(
          isExpanded: false,
          items: teachersItem,
          onChanged: (teacherItemValue) {
            setState(() {
              valueTeacher1 = teacherItemValue;
            });
          },
          value: valueTeacher1,
          hint: const Text("Teacher"),
        );
      }
      return const Text("No data");
    })

2

Answers


  1. for me add did unusual way i down graded my flutter version

    in terminal i typed this command : Flutter downgrade

    and it solved my error which was : Error: Expected ‘;’ after this. platform_channel.dart:313 6throw MissingPluginException(‘No implementation found for method $method on channel $name’);

    Login or Signup to reply.
  2. Can you try to convert data type like

      final Stream<QuerySnapshot<Map<String, dynamic>>> teachersRegistered =
          FirebaseFirestore.instance.collection('userData').snapshots();
    
      StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
          stream: teachersRegistered,
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search