Suppose there exist two data classes declared in two seperated files and one has another as one of its property. Then the generated code of the parent class will try to access the _$ChildCopyWIthImpl in its _$ParentCopyWithImpl, which is not visible to the parent module.
//main.dart
import 'package:freezed_annotation/freezed_annotation.dart';
import 'baz.dart';
part 'main.freezed.dart';
@freezed
abstract class Parent with _$Parent {
const factory Parent(Child child) = _Parent;
}
//baz.dart
import 'package:freezed_annotation/freezed_annotation.dart';
part 'baz.freezed.dart';
@freezed
abstract class Child with _$Child {
const factory Child(String name) = _Child;
}
md5-ebebc907968f6780cb13a9bc5da32d02
//main.freezed.dart
//...
class _$ParentCopyWithImpl<$Res> implements $ParentCopyWith<$Res> {
//...
@override
$ChildCopyWith<$Res> get child {
if (_value.child == null) {
return null;
}
return _$ChildCopyWithImpl<$Res>(_value.child, (value) {
// ^^^^^^^^^^^^^^^^^^^
// The method '_$ChildCopyWithImpl' isn't defined for the class '_$ParentCopyWithImpl'.
return _then(_value.copyWith(child: value));
});
}
}
Rename _Child to AChild, this does work.
I think the problem is, _Classes are private
That's an interesting point.
I'm not quite sure how we should solve this, to be honest.
Should the generated class always be public? 🤔
Another solution would be to re-generate the implementation files if they are private.
I'm not sure if it's a good idea though.
I still have this issue on 0.10.4, when update from 0.9.2 (on 0.9.2 i haven't). Help please @rrousselGit
@Comp0te can you give me a way to reproduce the error?
https://gist.github.com/Comp0te/63d471cea00fec99b69d527723211a62 - it's source code with nested class
https://gist.github.com/Comp0te/0cfa5aed2b6312056e56a45935750728 - it's with top class
Error occurs in this place:
`abstract class $ErrorCopyWith<$Res> {
factory $ErrorCopyWith(Error value, $Res Function(Error) then) =
_$ErrorCopyWithImpl<$Res>;
$Res call({AuthFailure failure});
$AuthFailureCopyWith<$Res> get failure; // error here
}`
@rrousselGit
The problem is your import. Do:
import 'package:smarty_duelist/src/domain/domain.dart' show AuthFailure, $AuthFailureCopyWith;
I shot myself in the foot with these imports! Thank you very much!
Most helpful comment
The problem is your import. Do: