1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] type '_WithConverterDocumentSnapshot<PharmacyModel>' is not a subtype of type...

Discussão em 'Mobile' iniciado por Stack, Outubro 7, 2024 às 11:42.

  1. Stack

    Stack Membro Participativo

    I am trying to convert a DocumentSnapshot into my own model called PharmacyModel. But when I tried that, I got this error 'type '_WithConverterDocumentSnapshot' is not a subtype of type 'DocumentSnapshot<Map<String, dynamic>>' in type cast'.

    I am passing an argument of type of DocumentSnapshot to a page and take it as a DocumentSnapshot<Map<String, dynamic>>. Then I used fromSnapshot factory method to convert it into the PharmacyModel.

    Here's how I passed the argument,

    Navigator.pushNamed(context, '/pdf', arguments: {'pharmacy': pharmacyDoc});


    Here's how I take it and convert it into the PharmacyModel,

    final args = ModalRoute.of(context)!.settings.arguments as Map?;
    if (args != null)
    {
    pharmacyDoc = args['pharmacy'] as DocumentSnapshot<Map<String, dynamic>>;
    }


    Here's my fromSnapshot factory method for PharmacyModel,

    factory PharmacyModel.fromSnapshot(DocumentSnapshot<Map<String, dynamic>> document) {
    if(document.data() != null) {
    final data = document.data()!;
    return PharmacyModel(
    id: document.id,
    name: data['Name'] as String? ?? '',
    address: data['Address'] as String? ?? '',
    contact: data['ContactNo'] as String? ?? '',
    ratings: data['Ratings'] as double? ?? 0,
    isDeliveryAvailable: data['DeliveryServiceAvailability'] as bool? ?? false,
    deliveryRate: data['DeliveryRate'] as double? ?? 0.0,
    operationHours: data['HoursOfOperation'] as String? ?? '',
    position: geo.point(
    latitude: (data['Position']['geopoint'] as GeoPoint).latitude,
    longitude: (data['Position']['geopoint'] as GeoPoint).longitude,
    ),
    tokens: List<String>.from(data['FCMTokens'] ?? []),
    );
    }
    else {
    return PharmacyModel.empty();
    }
    }

    Continue reading...

Compartilhe esta Página