I just renamed a bunch of files and now I can't start my app as it has all these run-time errors to the effect of:
VpUser? createdBy,
^^^^^^
: Error: 'VpUser' isn't a type.
Then I go to my code where the error is supposed to be and the error doesn't exist at all. I can right-click > go to definition from the freezed file and it goes to the class. No reported problems in my vs code. Why does my app not compile when the errors in the debug console do not appear to exist?
The example error above is for this code:
user.dart:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../_common/entity_types/domain_entity.dart';
import '../../_common/utils/string_utils.dart';
import '../../application/local/image_picker_image/image_picker_image.dart';
import 'user_dto.dart';
part 'user.freezed.dart';
part 'user.g.dart';
/// This is the user of the application.
@freezed
class VpUser extends DomainEntity<VpUserDto, String?> with _$VpUser {
const factory VpUser(
{String? id,
String? emailAddress,
String? nickName,
VpImage? profilePicture,
@JsonKey(ignore: true) User? thirdPartyUser,
DateTime? createdDate,
DateTime? updatedDate,
String? createdById,
VpUser? createdBy,
String? updatedById,
VpUser? updatedBy}) = _VpUser;
factory VpUser.fromDto(VpUserDto dto) {
VpImage? profilePicture;
if (dto.profilePicture != null) {
final position = dto.profilePicture!.lastIndexOf('/') + 1;
final fileName =
dto.profilePicture!.substring(position, dto.profilePicture!.length);
profilePicture = VpImage(
bucketName: 'vp-profile-pictures',
url: dto.profilePicture,
file: null,
fileName: fileName);
}
return VpUser(
id: dto.id,
emailAddress: dto.emailAddress,
profilePicture: profilePicture,
nickName: dto.nickName,
createdBy: null, // to avoid infinite loop
createdById: dto.createdById,
createdDate: dto.createdDate,
updatedDate: dto.updatedDate,
updatedBy: null, // to avoid infinite loop
updatedById: dto.updatedById,
);
}
factory VpUser.fromJson(Map<String, dynamic> json) => _$VpUserFromJson(json);
factory VpUser.fromThirdPartyUser(User thirdPartyUser) {
VpImage? image;
if (thirdPartyUser.photoURL != null &&
thirdPartyUser.photoURL!.isNotEmpty) {
final position = thirdPartyUser.photoURL!.lastIndexOf('/') + 1;
final fileName = thirdPartyUser.photoURL!
.substring(position, thirdPartyUser.photoURL!.length);
image = VpImage(
fileName: fileName,
url: thirdPartyUser.photoURL,
bucketName: 'vp-profile-pictures');
}
final entity = VpUser(
id: thirdPartyUser.uid,
emailAddress: thirdPartyUser.email,
profilePicture: image,
nickName: thirdPartyUser.displayName,
thirdPartyUser: thirdPartyUser);
return entity;
}
const VpUser._();
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(nickName),
const DeepCollectionEquality().hash(emailAddress),
);
String get vpFileName {
return sanitiseFileName('user-${id!}');
}
@override
bool operator ==(Object other) =>
other is VpUser &&
other.runtimeType == runtimeType &&
other.nickName == nickName &&
other.emailAddress == emailAddress;
@override
VpUserDto toDto() {
return VpUserDto(
id: id,
emailAddress: emailAddress,
profilePicture: profilePicture?.url,
nickName: nickName,
createdBy: null, // to avoid infinite loop
createdById: createdById,
createdDate: createdDate,
updatedDate: updatedDate,
updatedBy: null, // to avoid infinite loop
updatedById: updatedById,
);
}
VpUserDto userToDto() {
return VpUserDto(
id: id,
emailAddress: emailAddress,
profilePicture: profilePicture?.url,
nickName: nickName,
createdBy: null, // to avoid infinite loop
createdById: createdById,
createdDate: createdDate,
updatedDate: updatedDate,
updatedBy: null, // to avoid infinite loop
updatedById: updatedById,
);
}
}