Home > Mobile >  Flutter Convert FromMap to list The argument type 'Object?' can't be assigned to the
Flutter Convert FromMap to list The argument type 'Object?' can't be assigned to the

Time:03-18

I am trying to create some charts in a flutter, I am getting stuck in DocumentSnapshot.data I feel like flutter has changed the naming but I can not find it anywhere.

Widget _buildBody(BuildContext context){
    return StreamBuilder<QuerySnapshot>(
       stream: FirebaseFirestore.instance.collection('sales').snapshots(),
      builder: (context,snapshot){
        if(!snapshot.hasData){
          return LinearProgressIndicator();
        }
          else{

           
                 List<Sales> sales = snapshot.data!.docs
          .map((snapshot) => Sales.fromMap(snapshot.data()))
          .toList();
          }
      },
      
      );
  }

CodePudding user response:

Would you try to change like below.

From

Sales.fromMap(snapshot.data())

To

Sales.fromMap(snapshot.data() as Map<String, dynamic>)
  • Related