我正在尝试实现提供者类持有使用@freezed 生成的状态:
@injectable
class NewClientFormProvider with ChangeNotifier, DiagnosticableTreeMixin {
final IClientRepository _clientRepository;
NewClientFormState _state = NewClientFormState.initial();
NewClientFormState get state => _state;
NewClientFormProvider(this._clientRepository);
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
DiagnosticsProperty<NewClientFormState>("state", _state),
);
}
}
@freezed
class NewClientFormState with _$NewClientFormState, DiagnosticableTreeMixin {
const factory NewClientFormState({
required Client client,
required bool isSubmitting,
required Option<Either<SaveFailure, Client>> saveFailureOrSuccessOption,
}) = _NewClientFormState;
const NewClientFormState._();
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
DiagnosticsProperty<String>("companyName", client.companyName),
);
}
}
一切都已成功生成并编译,但未使用覆盖的方法,因此 DevTools 无法读取当前状态值(现在应该是可见属性“companyName”。我也尝试排除 DiagnosticableTreeMixin 并仅实现 toString(),但这是也没有使用(使用覆盖的冻结版本)。