Home > OS >  The method 'data' isn't defined for the type 'Function'. Try correcting the
The method 'data' isn't defined for the type 'Function'. Try correcting the

Time:10-30

The method 'data' isn't defined for the type 'Function'. Try correcting the name to the name of an existing method, or defining a method named 'data'.

                import 'package:cloud_firestore/cloud_firestore.dart';

            class Cita {
              int? turn;
              DateTime? day;
              String? status;
              String? email;
              DocumentReference? reference;

              String formattedDay() => '${day!.day}/${day?.month}/${day?.year}';

              Cita.fromSnapshot(DocumentSnapshot snapshot)
                  : this.fromMap(snapshot.data.data(), reference: snapshot.reference);

              Cita.fromMap(Map<String?, dynamic> map, {this.reference})
                  : turn = map['turn'],
                    day = map['day'].toDate(),
                    status = map['status'],
                    email = map['email'];
            }

CodePudding user response:

Try the following code:

import 'package:cloud_firestore/cloud_firestore.dart';

class Cita {
  int? turn;
  DateTime? day;
  String? status;
  String? email;
  DocumentReference? reference;

  String formattedDay() => '${day!.day}/${day?.month}/${day?.year}';

  Cita.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromMap(snapshot.data() as Map<String, dynamic>,
            reference: snapshot.reference);

  Cita.fromMap(Map<String?, dynamic> map, {this.reference})
      : turn = map['turn'],
        day = map['day'].toDate(),
        status = map['status'],
        email = map['email'];
}
  • Related