Я пытаюсь получить данные из API, но когда я их получаю, выдается строка, а не подтип карты ошибка.
Как я могу решить этот? Вот мой модельный класс. Я не знаю, где возникает проблема. Я думаю, в классе модели, но где?
Я использую пакет JsonSerializable, я также делаю класс обнуляемым, чтобы быть уверенным, что данные в API вернули ноль и поставьте явноToJson == true, но я не решил проблему.
import 'package:json_annotation/json_annotation.dart';
part 'appointment_model.g.dart';
@JsonSerializable(explicitToJson: true)
class AppointmentsList {
final List appointments;
AppointmentsList({required this.appointments});
factory AppointmentsList.fromJson(Map json) =>
_$AppointmentsListFromJson(json);
Map toJson() => _$AppointmentsListToJson(this);
}
@JsonSerializable(explicitToJson: true)
class Appointment {
final int id;
final String appointment_number;
final int client_id;
final String appointment_date;
final int work_shift_id;
final String appointment_prefer_time;
final int early_appointment;
final String? address_notes;
final int payment_id;
final String reference_number;
final int category_id;
final int address_id;
final int tech_id;
final int service_id;
final int duration;
final int near_power_slot;
final int appointment_confirmed;
final String status;
final int? appointment_status_id;
final int? technician_status_id;
final int? contact_request_id;
final int subtotal;
final int total;
final int tax;
final String created_at;
final String updated_at;
final ServiceModel service;
final ClientModel client;
final AddressModel address;
final List products;
Appointment({
required this.id,
required this.appointment_number,
required this.client_id,
required this.appointment_date,
required this.work_shift_id,
required this.appointment_prefer_time,
required this.early_appointment,
this.address_notes,
required this.payment_id,
required this.reference_number,
required this.category_id,
required this.address_id,
required this.tech_id,
required this.service_id,
required this.duration,
required this.near_power_slot,
required this.appointment_confirmed,
required this.status,
this.appointment_status_id,
this.technician_status_id,
this.contact_request_id,
required this.subtotal,
required this.total,
required this.tax,
required this.created_at,
required this.updated_at,
required this.service,
required this.client,
required this.address,
required this.products,
});
factory Appointment.fromJson(Map json) =>
_$AppointmentFromJson(json);
Map toJson() => _$AppointmentToJson(this);
}
@JsonSerializable(explicitToJson: true)
class ServiceModel {
final int? id;
final String? name;
final String? service_time;
final String? status;
final String? created_at;
final String? updated_at;
ServiceModel({
this.id,
this.name,
this.service_time,
this.status,
this.created_at,
this.updated_at,
});
factory ServiceModel.fromJson(Map json) =>
_$ServiceModelFromJson(json);
Map toJson() => _$ServiceModelToJson(this);
}
@JsonSerializable(explicitToJson: true)
class ClientModel {
final int? id;
final String? type;
final String? full_name;
final String? phone;
final String? second_phone;
final int? whatsapp_notifications;
final String? created_at;
final String? updated_at;
ClientModel({
this.id,
this.type,
this.full_name,
this.phone,
this.second_phone,
this.whatsapp_notifications,
this.created_at,
this.updated_at,
});
factory ClientModel.fromJson(Map json) =>
_$ClientModelFromJson(json);
Map toJson() => _$ClientModelToJson(this);
}
@JsonSerializable(explicitToJson: true)
class AddressModel {
final int? id;
final int? default_address;
final int? client_id;
final int? city_id;
final int? district_id;
final int? sector_id;
final String? name;
final String? lat;
final String? long;
final String? location_note;
final String? created_at;
final String? updated_at;
AddressModel({
this.id,
this.default_address,
this.client_id,
this.city_id,
this.district_id,
this.sector_id,
this.name,
this.lat,
this.long,
this.location_note,
this.created_at,
this.updated_at,
});
factory AddressModel.fromJson(Map json) =>
_$AddressModelFromJson(json);
Map toJson() => _$AddressModelToJson(this);
}
@JsonSerializable(explicitToJson: true)
class ProductModel {
final int? id;
final int? appointment_id;
final int? product_id;
final int? price;
final int? qty;
final int? total_price;
final String? created_at;
final String? updated_at;
final ProductDetailModel?
product; // Assuming ProductDetailModel is defined elsewhere
ProductModel({
this.id,
this.appointment_id,
this.product_id,
this.price,
this.qty,
this.total_price,
this.created_at,
this.updated_at,
this.product,
});
factory ProductModel.fromJson(Map json) =>
_$ProductModelFromJson(json);
Map toJson() => _$ProductModelToJson(this);
}
@JsonSerializable(explicitToJson: true)
class ProductDetailModel {
final int? id;
final int? category_id;
final String? name;
final String? sku;
final String? description;
final String? status;
final int? price;
final String? notes;
final int? is_available;
final int? maintenance_recurring;
final String? item_code;
final String? created_at;
final String? updated_at;
ProductDetailModel({
this.id,
this.category_id,
this.name,
this.sku,
this.description,
this.status,
this.price,
this.notes,
this.is_available,
this.maintenance_recurring,
this.item_code,
this.created_at,
this.updated_at,
});
factory ProductDetailModel.fromJson(Map json) =>
_$ProductDetailModelFromJson(json);
Map toJson() => _$ProductDetailModelToJson(this);
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... ng-dynamic
_TypeError (тип «String» не является подтипом типа «Map») ⇐ Android
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение