0

由于某种原因,runtimeType在这个 Freezed 类的生成 json 中丢失了。它只是偶尔发生。见下图:

在此处输入图像描述

这会导致图像中的 switch case 掉到throw FallThroughError();,因为runtimeType不存在。

这是课程:

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:vepo/src/application/entities/option/option.dart';
import '../vegan_item.dart';

part 'basic_vegan_item.freezed.dart';
part 'basic_vegan_item.g.dart';

@freezed
class BasicVeganItem extends VeganItem with _$BasicVeganItem {
  const factory BasicVeganItem(
      {int? id,
      String? name,
      String? companyName,
      String? imageBucketName,
      String? description,
      String? image,
      List<Option>? tags,
      @Default(0) int isNotVeganCount,
      @Default(0) int isVeganCount,
      int? rating,
      @Default(0) int ratingsCount,
      @Default(1) int currentRevisionId}) = _BasicVeganItem;

  const factory BasicVeganItem.groceryItem(
      {int? id,
      String? name,
      String? companyName,
      @Default('vp-grocery-items') String? imageBucketName,
      String? description,
      String? image,
      List<Option>? tags,
      @Default(0) int isNotVeganCount,
      @Default(0) int isVeganCount,
      int? rating,
      @Default(0) int ratingsCount,
      @Default(1) int currentRevisionId}) = GroceryItem;

  const factory BasicVeganItem.menuItem(
      {int? id,
      String? name,
      String? companyName,
      @Default('vp-menu-items') String? imageBucketName,
      String? description,
      String? image,
      List<Option>? tags,
      @Default(0) int isNotVeganCount,
      @Default(0) int isVeganCount,
      int? rating,
      @Default(0) int ratingsCount,
      @Default(1) int currentRevisionId}) = MenuItem;

  const BasicVeganItem._();

  factory BasicVeganItem.fromJson(Map<String, dynamic> json) =>
      _$BasicVeganItemFromJson(json);
}
4

0 回答 0