簡體   English   中英

Flutter 錯誤“不是類型”與導入的 class

[英]Flutter error "isn't a type" with imported class

我有文件 models.dart 有幾個不同的模型,其中之一是 PaidCheckLists。 我決定為其中的每個 class 創建文件夾,使用 json_serializable 庫為需要它的類創建方法 toJson 和 fromJson,但后來發生了一些非常奇怪的事情。

在 class LocalStorage 的文件 local_storage.dart 中,我無法使用 PaidCheckLists 類型創建變量,但我從文件夾中導入了 Paid CheckLists class

import 'package:inspector/data/models/paid/paid.dart';

但我可以在其他 class 中創建類型為 PaidCheckList 的變量,例如在我的某些屏幕的塊 class 中

在這里你可以看到我的文件是如何存儲的

這是我用來在我的一些集團 class 中創建具有 PaidCheckList 類型的變量的導入

import 'package:inspector/data/models/paid/paid.dart';

這就是 class 的樣子

import 'package:json_annotation/json_annotation.dart';

part 'paid.g.dart';

@JsonSerializable()
class PaidCheckLists {
  List<String> id;
  PaidCheckLists(this.id);

  factory PaidCheckLists.fromJson(Map<String, dynamic> json) => _$PaidCheckListsFromJson(json);
  Map<String, dynamic> toJson() => _$PaidCheckListsToJson(this);
}

這是我可以在文件 local_storage.dart 中導入的其他 class

import 'package:json_annotation/json_annotation.dart';

part 'logs.g.dart';

@JsonSerializable()
class Logs {
  String eventNumber;
  String event;
  String eventDetails;
  String macAdress;
  Logs(this.eventNumber, this.event, this.eventDetails, this.macAdress);
  factory Logs.fromJson(Map<String, dynamic> json) => _$LogsFromJson(json);
  Map<String, dynamic> toJson() => _$LogsToJson(this);
}

您是否嘗試使用此命令清理 flutter 緩存?

flutter pub緩存修復

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM