参数类型' list<插槽?>?'可以将参数类型分配给列表< gt;??'

发布于 2025-01-26 03:39:54 字数 5221 浏览 3 评论 0原文

我最近将代码迁移到无效的安全性。在DART Migrate命令中获得以下错误。

参数类型“列表<插槽?&gt ;?”无法分配到参数类型“列表?”在lib/explosemodels/pufbormant/calendar/calendar_response.g.dart:17:5

下方的错误抛出线

突出显示了plays therefor therefling lines plays plays_response.dart

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'calendar_response.dart';

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

CalenderResponse _$CalenderResponseFromJson(Map<String, dynamic> json) {
  return CalenderResponse(
    json['createdAt'] as String?,
    json['dayInWeek'] as String?,
    json['isHavingSlot'] as String?,
    json['message'] as String?,
    json['schedulerId'] as String?,
    json['selectedDate'] as String?,
    **(json['slotTimings'] as List?)
        ?.map(
            (e) => e == null ? null : Slots.fromJson(e as Map<String, dynamic>))
        ?.toList(),**
    json['status'] as String?,
    json['updatedAt'] as String?,
    json['currenttime'] as String?,
  );
}

CalenderAvailableDatesResponse _$CalenderAvailableDatesResponseFromJson(
    Map<String, dynamic> json) {
  return CalenderAvailableDatesResponse(
      (json['dateList'] as List?)?.map((e) => e as String).toList(),
      json['message'] as String?,
      json['status'] as String?,
      json['currenttime'] as String?);
}

slots_response.dart

import 'package:json_annotation/json_annotation.dart';

part 'slots_response.g.dart';

@JsonSerializable(createToJson: false)
class SlotsResponse {
  final String? status;
  final String? message;
  final List<SlotsGroups>? availableGroups;
  SlotsResponse(this.availableGroups, this.message, this.status);

  factory SlotsResponse.fromJson(Map<String, dynamic> map) =>
      _$SlotsResponseFromJson(map);
}

@JsonSerializable(createToJson: false)
class SlotsGroups {
  final String? groupId;
  final String? vendorId;
  final String? groupName;
  final String? status;
  final String? createdAt;
  final String? updatedAt;
  final List<Slots>? availSlots;

  SlotsGroups(this.availSlots, this.createdAt, this.groupId, this.groupName,
      this.status, this.updatedAt, this.vendorId);

  factory SlotsGroups.fromJson(Map<String, dynamic> map) =>
      _$SlotsGroupsFromJson(map);
}

@JsonSerializable(createToJson: false)
class Slots {
  late final String? slotId;
  late final String? startTime;
  late final String? endTime;
  late final String? duration;
  late final String? startDateStrTime;
  late final String? endDateStrTime;
  late final String? stGivenString;
  late final String? endGivenString;
  late final String? status;
  late final String? createdAt;
  late final String? updatedAt;
  late final String? isAnyAppointment;
  late final BookingDetails? bookingDetails;

  Slots(
      this.createdAt,
      this.duration,
      this.endDateStrTime,
      this.endGivenString,
      this.endTime,
      this.slotId,
      this.stGivenString,
      this.bookingDetails,
      this.isAnyAppointment,
      this.startDateStrTime,
      this.startTime,
      this.status,
      this.updatedAt);

  factory Slots.fromJson(Map<String, dynamic> map) => _$SlotsFromJson(map);
}

@JsonSerializable(createToJson: false)
class BookingDetails {
  final String? customerName;
  final String? serviceName;

  BookingDetails(this.customerName, this.serviceName);

  factory BookingDetails.fromJson(Map<String, dynamic> map) =>
      _$BookingDetailsFromJson(map);
}

calendar_response.dart

import 'package:awomowa/responsemodels/appointment/slots/slots_response.dart';
import 'package:json_annotation/json_annotation.dart';

part 'calendar_response.g.dart';

@JsonSerializable(createToJson: false)
class CalenderResponse {
  final String? status;
  final String? message;
  final String? isHavingSlot;
  final String? schedulerId;

  final String? dayInWeek;
  final String? selectedDate;
  final String? createdAt;
  final String? updatedAt;
  final List<Slots>? slotTimings;
  final String? currenttime;
  
  CalenderResponse(
      this.createdAt,
      this.dayInWeek,
      this.isHavingSlot,
      this.message,
      this.schedulerId,
      this.selectedDate,
      this.slotTimings,
      this.status,
      this.updatedAt,
      this.currenttime);

  factory CalenderResponse.fromJson(Map<String, dynamic> map) =>
      _$CalenderResponseFromJson(map);
}

@JsonSerializable(createToJson: false)
class CalenderAvailableDatesResponse {
  final String? status;
  final String? message;
  final List<String>? dateList;
  final String? currenttime;

  CalenderAvailableDatesResponse(this.dateList, this.message, this.status,this.currenttime);
  factory CalenderAvailableDatesResponse.fromJson(Map<String, dynamic> map) =>
      _$CalenderAvailableDatesResponseFromJson(map);
}

i have recently migrated my code to null safety. got the below error in dart migrate command.

The argument type 'List<Slots?>?' can't be assigned to the parameter type 'List?' at lib/responsemodels/appointment/calendar/calendar_response.g.dart:17:5

Highlighted the error throwing line below

calendar_response.dart

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'calendar_response.dart';

// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************

CalenderResponse _$CalenderResponseFromJson(Map<String, dynamic> json) {
  return CalenderResponse(
    json['createdAt'] as String?,
    json['dayInWeek'] as String?,
    json['isHavingSlot'] as String?,
    json['message'] as String?,
    json['schedulerId'] as String?,
    json['selectedDate'] as String?,
    **(json['slotTimings'] as List?)
        ?.map(
            (e) => e == null ? null : Slots.fromJson(e as Map<String, dynamic>))
        ?.toList(),**
    json['status'] as String?,
    json['updatedAt'] as String?,
    json['currenttime'] as String?,
  );
}

CalenderAvailableDatesResponse _$CalenderAvailableDatesResponseFromJson(
    Map<String, dynamic> json) {
  return CalenderAvailableDatesResponse(
      (json['dateList'] as List?)?.map((e) => e as String).toList(),
      json['message'] as String?,
      json['status'] as String?,
      json['currenttime'] as String?);
}

slots_response.dart

import 'package:json_annotation/json_annotation.dart';

part 'slots_response.g.dart';

@JsonSerializable(createToJson: false)
class SlotsResponse {
  final String? status;
  final String? message;
  final List<SlotsGroups>? availableGroups;
  SlotsResponse(this.availableGroups, this.message, this.status);

  factory SlotsResponse.fromJson(Map<String, dynamic> map) =>
      _$SlotsResponseFromJson(map);
}

@JsonSerializable(createToJson: false)
class SlotsGroups {
  final String? groupId;
  final String? vendorId;
  final String? groupName;
  final String? status;
  final String? createdAt;
  final String? updatedAt;
  final List<Slots>? availSlots;

  SlotsGroups(this.availSlots, this.createdAt, this.groupId, this.groupName,
      this.status, this.updatedAt, this.vendorId);

  factory SlotsGroups.fromJson(Map<String, dynamic> map) =>
      _$SlotsGroupsFromJson(map);
}

@JsonSerializable(createToJson: false)
class Slots {
  late final String? slotId;
  late final String? startTime;
  late final String? endTime;
  late final String? duration;
  late final String? startDateStrTime;
  late final String? endDateStrTime;
  late final String? stGivenString;
  late final String? endGivenString;
  late final String? status;
  late final String? createdAt;
  late final String? updatedAt;
  late final String? isAnyAppointment;
  late final BookingDetails? bookingDetails;

  Slots(
      this.createdAt,
      this.duration,
      this.endDateStrTime,
      this.endGivenString,
      this.endTime,
      this.slotId,
      this.stGivenString,
      this.bookingDetails,
      this.isAnyAppointment,
      this.startDateStrTime,
      this.startTime,
      this.status,
      this.updatedAt);

  factory Slots.fromJson(Map<String, dynamic> map) => _$SlotsFromJson(map);
}

@JsonSerializable(createToJson: false)
class BookingDetails {
  final String? customerName;
  final String? serviceName;

  BookingDetails(this.customerName, this.serviceName);

  factory BookingDetails.fromJson(Map<String, dynamic> map) =>
      _$BookingDetailsFromJson(map);
}

calendar_response.dart

import 'package:awomowa/responsemodels/appointment/slots/slots_response.dart';
import 'package:json_annotation/json_annotation.dart';

part 'calendar_response.g.dart';

@JsonSerializable(createToJson: false)
class CalenderResponse {
  final String? status;
  final String? message;
  final String? isHavingSlot;
  final String? schedulerId;

  final String? dayInWeek;
  final String? selectedDate;
  final String? createdAt;
  final String? updatedAt;
  final List<Slots>? slotTimings;
  final String? currenttime;
  
  CalenderResponse(
      this.createdAt,
      this.dayInWeek,
      this.isHavingSlot,
      this.message,
      this.schedulerId,
      this.selectedDate,
      this.slotTimings,
      this.status,
      this.updatedAt,
      this.currenttime);

  factory CalenderResponse.fromJson(Map<String, dynamic> map) =>
      _$CalenderResponseFromJson(map);
}

@JsonSerializable(createToJson: false)
class CalenderAvailableDatesResponse {
  final String? status;
  final String? message;
  final List<String>? dateList;
  final String? currenttime;

  CalenderAvailableDatesResponse(this.dateList, this.message, this.status,this.currenttime);
  factory CalenderAvailableDatesResponse.fromJson(Map<String, dynamic> map) =>
      _$CalenderAvailableDatesResponseFromJson(map);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2025-02-02 03:39:55

问题在于MAP中使用的功能可以返回null。换句话说:其返回类型是插槽?,而不是插槽

要求解它,您可以将零值从列表中滤除,以从list&lt; lt&lt; to list&lt; lt; slots&gt;之类

(json['slotTimings'] as List?)
    ?.map(
        (e) => e == null ? null : Slots.fromJson(e as Map<String, dynamic>))
    .whereType<Slots>().toList(),

The problem is that the function used in map can return null. In other words: its return type is Slots?, and not Slots.

To solve it you can filter the null values out of the list to turn the list from List<Slots?> to List<Slots> like this

(json['slotTimings'] as List?)
    ?.map(
        (e) => e == null ? null : Slots.fromJson(e as Map<String, dynamic>))
    .whereType<Slots>().toList(),
原野 2025-02-02 03:39:55

我想您使用的是JSON_ANNOTATIONJSON_SERIALIZABLE带有build> build_runner。如**。g文件中指定的那样。

// GENERATED CODE - DO NOT MODIFY BY HAND

您应该修改模型文件,以适应您在那里的问题/情况,然后运行:
Flutter Pub Run Build_runner build

flutter Pub Run Build_runner构建 - DELETE CONFRICTING-OUTPUTS

I presume you are using json_annotation, json_serializable with build_runner. As is being specified in the **.g file.

// GENERATED CODE - DO NOT MODIFY BY HAND

You should modify your model file to accommodate the issue/situation you have there and then and then run:
flutter pub run build_runner build
or
flutter pub run build_runner build --delete-conflicting-outputs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文