我在用freezed.
我的代码如下所示:
import 'package:freezed_annotation/freezed_annotation.dart';
part 'key_state.freezed.dart';
part 'key_state.g.dart';
@freezed
class KeyState with _$KeyState {
factory KeyState({
CancelToken? token,
// ...
}) = _KeyState;
factory KeyState.initial() => KeyState();
factory KeyState.fromJson(Map<String, dynamic> json) =>
_$KeyStateFromJson(json);
}
这是CancelToken
来自https://github.com/flutterchina/dio/blob/master/dio/lib/src/cancel_token.dart的课程
这不起作用。
错误:
Could not generate `fromJson` code for `token`.
To support the type `CancelToken` you can:
* Use `JsonConverter`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonConverter-class.html
* Use `JsonKey` fields `fromJson` and `toJson`
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/fromJson.html
https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonKey/toJson.html
package:flutter_app/redux/state/key_state.freezed.dart:114:22
我该怎么做呢?