我刚刚重命名了一堆文件,现在我无法启动我的应用程序,因为它有所有这些运行时错误的影响:
VpUser? createdBy,
^^^^^^
: Error: 'VpUser' isn't a type.
然后我转到我的代码,错误应该在哪里,而错误根本不存在。我可以右键单击〉从冻结的文件转到定义,它会转到类。我的vs代码中没有报告问题。为什么我的应用在调试控制台中的错误似乎不存在的情况下无法编译?
上面的示例错误针对以下代码:
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,
);
}
}
1条答案
按热度按时间6yoyoihd1#
我的一些导入在明显应该有“/”的地方有“//”,例如:
由于某种原因,这不会对vscode造成任何问题,并且是一个完全隐藏的错误,当导入有“//”但应用程序不编译时,您仍然可以右键单击〉转到定义。可能值得将此保持在线,因为它非常意外。