json_serializable 插件不支持 'File' 类型?
json_serializable plugin doesn't support 'File' type?
我正在使用 json_serializable 插件,但它似乎不适用于图像文件。 'myclass.g.dart' 未生成。我对其他类型没有任何问题。
(https://pub.dev/packages/json_serializable/versions/0.5.4#-readme-tab-)
这是我的代码:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
part 'myclass.g.dart';
@JsonSerializable()
class MyClass {
final String name;
final List<File> photosFile;
MyClass({
@required this.name,
@required this.photosFile,
});
factory MyClass.fromJson(Map<String, dynamic> json) => _$MyClassFromJson(json);
Map<String, dynamic> toJson() => _$MyClassToJson(this);
}
这是错误:
[SEVERE] json_serializable:json_serializable on lib/model/myclass.dart (cached):
Error running JsonSerializableGenerator
Could not generate `fromJson` code for `photosFile` because of type `File`.
None of the provided `TypeHelper` instances support the defined type.
package:mydomus_edl/model/myclass.dart:11:20
╷
17 │ final List<File> photosFile;
│ ^^^^^^^^^^
╵
[SEVERE] Failed after 171ms
有人知道吗?谢谢!
JSON 架构支持五种基本值类型:
- 字符串。
- 号码。
- 整数。
- 布尔值。
- 无效的。
您应该实现从字符串到文件的转换。
我正在使用 json_serializable 插件,但它似乎不适用于图像文件。 'myclass.g.dart' 未生成。我对其他类型没有任何问题。 (https://pub.dev/packages/json_serializable/versions/0.5.4#-readme-tab-)
这是我的代码:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';
part 'myclass.g.dart';
@JsonSerializable()
class MyClass {
final String name;
final List<File> photosFile;
MyClass({
@required this.name,
@required this.photosFile,
});
factory MyClass.fromJson(Map<String, dynamic> json) => _$MyClassFromJson(json);
Map<String, dynamic> toJson() => _$MyClassToJson(this);
}
这是错误:
[SEVERE] json_serializable:json_serializable on lib/model/myclass.dart (cached):
Error running JsonSerializableGenerator
Could not generate `fromJson` code for `photosFile` because of type `File`.
None of the provided `TypeHelper` instances support the defined type.
package:mydomus_edl/model/myclass.dart:11:20
╷
17 │ final List<File> photosFile;
│ ^^^^^^^^^^
╵
[SEVERE] Failed after 171ms
有人知道吗?谢谢!
JSON 架构支持五种基本值类型:
- 字符串。
- 号码。
- 整数。
- 布尔值。
- 无效的。
您应该实现从字符串到文件的转换。