'The argument type 'Object?' can't be assigned to the parameter type 'QuerySnapshot<Object?>'. Facing while developing a Flutter Website

Trying to develop an Admin Grocery Website, but faced an error and can't fix it as I am new to flutter. I am getting an error here rows: vendorsDetailsRow(snapshot.data) and the error is The argument type 'Object?' can't be assigned to the parameter type 'QuerySnapshot<Object?>'.

Facing This Error

So here is my code

import 'package:admin_app_grocery/services/firebase_services.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    FirebaseServices services = FirebaseServices();
    return StreamBuilder(
      stream:
          services.vendors.orderBy('shopName', descending: true).snapshots(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return const Text("Something Went Wrong");
        }
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Center(child: CircularProgressIndicator());
        }
        return SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: DataTable(
            showBottomBorder: true,
            dataRowHeight: 60,
            headingRowColor: MaterialStateProperty.all(Colors.grey[200]),
            columns: const [
              DataColumn(
                label: Text("Active/Inactive"),
              ),
              DataColumn(
                label: Text("Top Picked"),
              ),
              DataColumn(
                label: Text("Shop Name"),
              ),
              DataColumn(
                label: Text("Rating"),
              ),
              DataColumn(
                label: Text("Total Sales"),
              ),
              DataColumn(
                label: Text("Mobile"),
              ),
              DataColumn(
                label: Text("Email"),
              ),
              DataColumn(
                label: Text("View Details"),
              ),
            ],
            rows: vendorsDetailsRow(snapshot.data),
          ),
        );
      },
    );
  }

  List<DataRow> vendorsDetailsRow(QuerySnapshot snapshot) {
    List<DataRow> newList =
        snapshot.docs.map((DocumentSnapshot documentSnapshot) {
      return DataRow(cells: [
        DataCell(IconButton(
          onPressed: () {},
          icon: documentSnapshot['accVerified']
              ? const Icon(
                  Icons.check_circle,
                  color: Colors.blue,
                )
              : const Icon(
                  Icons.remove_circle,
                  color: Colors.red,
                ),
        )),
        DataCell(IconButton(
          onPressed: () {},
          icon: documentSnapshot['isTopPicked']
              ? const Icon(
                  Icons.check_circle,
                  color: Colors.blue,
                )
              : const Icon(null),
        )),
        DataCell(documentSnapshot['shopName']),
        DataCell(Row(
          children: const [Icon(Icons.star), Text("3.5")],
        )),
        const DataCell(Text("20,000")),
        DataCell(Text(documentSnapshot['mobile'])),
        DataCell(Text(documentSnapshot['email'])),
        DataCell(IconButton(
          icon: const Icon(Icons.remove_red_eye_outlined),
          onPressed: () {},
        ))
      ]);
    }).toList();
    return newList;
  }
}



Solution 1:[1]

Fixed the code it was just a very minor mistake just changed this line of code i.e DataCell(documentSnapshot['shopName']), to DataCell(Text(documentSnapshot['shopName'])), . Earlier it was returning a String now its returning a Text Widget , this fixed my issue.

Modified Code is :

import 'package:admin_app_grocery/services/firebase_services.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    FirebaseServices services = FirebaseServices();
    return StreamBuilder<QuerySnapshot>(
      stream:
          services.vendors.orderBy('shopName', descending: true).snapshots(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return const Text("Something Went Wrong");
        }
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Center(child: CircularProgressIndicator());
        }
        return SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: DataTable(
            showBottomBorder: true,
            dataRowHeight: 60,
            headingRowColor: MaterialStateProperty.all(Colors.grey[200]),
            columns: const [
              DataColumn(
                label: Text("Active/Inactive"),
              ),
              DataColumn(
                label: Text("Top Picked"),
              ),
              DataColumn(
                label: Text("Shop Name"),
              ),
              DataColumn(
                label: Text("Rating"),
              ),
              DataColumn(
                label: Text("Total Sales"),
              ),
              DataColumn(
                label: Text("Mobile"),
              ),
              DataColumn(
                label: Text("Email"),
              ),
              DataColumn(
                label: Text("View Details"),
              ),
            ],
            rows: vendorsDetailsRow(snapshot.data),
          ),
        );
      },
    );
  }

  List<DataRow> vendorsDetailsRow(QuerySnapshot? snapshot) {
    List<DataRow> newList =
        snapshot!.docs.map((DocumentSnapshot documentSnapshot) {
      return DataRow(cells: [
        DataCell(IconButton(
          onPressed: () {},
          icon: documentSnapshot['accVerified']
              ? const Icon(
                  Icons.check_circle,
                  color: Colors.blue,
                )
              : const Icon(
                  Icons.remove_circle,
                  color: Colors.red,
                ),
        )),
        DataCell(IconButton(
          onPressed: () {},
          icon: documentSnapshot['isTopPicked']
              ? const Icon(
                  Icons.check_circle,
                  color: Colors.blue,
                )
              : const Icon(null),
        )),
        DataCell(Text(documentSnapshot['shopName'])),
        DataCell(Row(
          children: const [Icon(Icons.star), Text("3.5")],
        ),),
        const DataCell(Text("20,000")),
        DataCell(Text(documentSnapshot['mobile'])),
        DataCell(Text(documentSnapshot['email'])),
        DataCell(IconButton(
          icon: const Icon(Icons.remove_red_eye_outlined),
          onPressed: () {},
        ))
      ]);
    }).toList();
    return newList;
  }
}

Solution 2:[2]

Specify the type in the StreamBuilder like so

 return StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
      stream:
          services.vendors.orderBy('shopName', descending: true).snapshots(),
      builder: (context, snapshot) {
        if (snapshot.hasError) {
          return const Text("Something Went Wrong");
        }
        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Center(child: CircularProgressIndicator());
        }
        return SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: DataTable(
            showBottomBorder: true,
            dataRowHeight: 60,
            headingRowColor: MaterialStateProperty.all(Colors.grey[200]),
            columns: const [
              DataColumn(
                label: Text("Active/Inactive"),
              ),
              DataColumn(
                label: Text("Top Picked"),
              ),
              DataColumn(
                label: Text("Shop Name"),
              ),
              DataColumn(
                label: Text("Rating"),
              ),
              DataColumn(
                label: Text("Total Sales"),
              ),
              DataColumn(
                label: Text("Mobile"),
              ),
              DataColumn(
                label: Text("Email"),
              ),
              DataColumn(
                label: Text("View Details"),
              ),
            ],
            rows: vendorsDetailsRow(snapshot.data),
          ),
        );
      },
    );
  }

And update vendorsDetailsRow to:

 List<DataRow> vendorsDetailsRow(QuerySnapshot<Map<String, dynamic>> snapshot) {
    List<DataRow> newList =
        snapshot.docs.map((DocumentSnapshot x) {
     final documentSnapshot = x.data();
      return DataRow(cells: [
        DataCell(IconButton(
          onPressed: () {},
          icon: documentSnapshot['accVerified']
              ? const Icon(
                  Icons.check_circle,
                  color: Colors.blue,
                )
              : const Icon(
                  Icons.remove_circle,
                  color: Colors.red,
                ),
        )),
        DataCell(IconButton(
          onPressed: () {},
          icon: documentSnapshot['isTopPicked']
              ? const Icon(
                  Icons.check_circle,
                  color: Colors.blue,
                )
              : const Icon(null),
        )),
        DataCell(documentSnapshot['shopName']),
        DataCell(Row(
          children: const [Icon(Icons.star), Text("3.5")],
        )),
        const DataCell(Text("20,000")),
        DataCell(Text(documentSnapshot['mobile'])),
        DataCell(Text(documentSnapshot['email'])),
        DataCell(IconButton(
          icon: const Icon(Icons.remove_red_eye_outlined),
          onPressed: () {},
        ))
      ]);
    }).toList();
    return newList;
  }

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Rudransh Singh Mahra
Solution 2 Josteve