FLUTTER BLOC 패턴에 대해서 공부해 보면서 공식 dev 에 있는 예제를 따라 해보고 있었다.
그러던중
The argument type 'Object' can't be assigned to the parameter type 'PostStatus'.
라는 에러를 봤다 아마 이런 류의 에러는 타입이 맞지 않아서 보통 나올것이다.
나의 경우에는
import 'package:equatable/equatable.dart';
import 'package:practice_bloc_infinitescroll/posts/models/post.dart';
enum PostStatus { initial, success, failure }
class PostState extends Equatable {
final PostStatus status;
final List<Post> posts;
final bool hasReachedMax;
const PostState({
this.status = PostStatus.initial,
this.posts = const <Post>[],
this.hasReachedMax = false,
});
PostState copyWith({
PostState? status,
List<Post>? posts,
bool? hasReachedMax,
}) {
return PostState(
status: status ?? this.status,
posts: posts ?? this.posts,
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
);
}
@override
String toString() {
return 'PostState{status: $status, posts: $posts, hasReachedMax: $hasReachedMax}';
}
@override
List<Object> get props => [status, posts, hasReachedMax];
}
에서 status: status ?? this.status, 라는 부분에서 에러가 나고 있었다. 코드를 보면 중간 부분에 있다.
에러가 난 부분을 아무리 고치려고 해도 안 고쳐졌는데 천천히 읽다 보니까 나의 오타를 발견했다.....
위에 copyWith 라는 메서드의 parameter를 받을때 PostStatus 라고 타입을 명시 해야 되는데 바보 같이 PostState로 했다...
너무 비슷하자나..... 그래서 아래와 같이 고쳤다.
import 'package:equatable/equatable.dart';
import 'package:practice_bloc_infinitescroll/posts/models/post.dart';
enum PostStatus { initial, success, failure }
class PostState extends Equatable {
final PostStatus status;
final List<Post> posts;
final bool hasReachedMax;
const PostState({
this.status = PostStatus.initial,
this.posts = const <Post>[],
this.hasReachedMax = false,
});
PostState copyWith({
PostStatus? status,
List<Post>? posts,
bool? hasReachedMax,
}) {
return PostState(
status: status ?? this.status,
posts: posts ?? this.posts,
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
);
}
@override
String toString() {
return 'PostState{status: $status, posts: $posts, hasReachedMax: $hasReachedMax}';
}
@override
List<Object> get props => [status, posts, hasReachedMax];
}
그랬더니 너무나도 쉽게 문제 해결!!!!
역시 에러 이유를 읽고 천천히 코딩을 하면 이런 에러는 안날듯...
그리고 너무 이름이 비슷해서 ㅠㅠ 네이밍에 조금 신중할 필요가 있다는 것을 다시 깨달았다.
'FLUTTER' 카테고리의 다른 글
[ERROR] (Xcode) : jpg: No such file or directory [Could not build the precompiled application for the device.] (0) | 2023.02.01 |
---|---|
플러터 png 파일 꽉찬 화면 (flutter png full screen) (0) | 2023.01.17 |
[Flutter] Post 요청을 수행하는 동안 CERTIFICATE_VERIFY_FAILED 을 해결하는 방법. (0) | 2022.11.03 |
[ERROR]One or more plugins require a higher Android SDK version. (0) | 2022.11.02 |
FLUTTER 패키지 추천해주는 사이트! (0) | 2022.10.07 |