diff --git a/docs/src/content/docs/faqs.mdx b/docs/src/content/docs/faqs.mdx index 267a8ccb171..b244a18d98c 100644 --- a/docs/src/content/docs/faqs.mdx +++ b/docs/src/content/docs/faqs.mdx @@ -55,7 +55,7 @@ bloc. :::caution `Equatable` properties should always be copied rather than modified. If an `Equatable` class contains a `List` or `Map` as properties, be sure to use -`List.from` or `Map.from` respectively to ensure that equality is evaluated +`List.of` or `Map.of` respectively to ensure that equality is evaluated based on the values of the properties rather than the reference. ::: diff --git a/docs/src/content/docs/ko/faqs.mdx b/docs/src/content/docs/ko/faqs.mdx index a3d8dc23b91..8d39c3affd5 100644 --- a/docs/src/content/docs/ko/faqs.mdx +++ b/docs/src/content/docs/ko/faqs.mdx @@ -50,7 +50,7 @@ import BlocExternalForEachSnippet from '~/components/faqs/BlocExternalForEachSni :::caution -`Equatable` 프로퍼티는 항상 수정하지 말고 복사해야 합니다. `Equatable` 클래스에 `List` 또는 `Map`이 프로퍼티로 있는 경우, 참조가 아닌 프로퍼티 값을 기준으로 동등성이 평가되도록 `List.from` 또는 `Map.from`을 각각 사용해야 합니다. +`Equatable` 프로퍼티는 항상 수정하지 말고 복사해야 합니다. `Equatable` 클래스에 `List` 또는 `Map`이 프로퍼티로 있는 경우, 참조가 아닌 프로퍼티 값을 기준으로 동등성이 평가되도록 `List.of` 또는 `Map.of`을 각각 사용해야 합니다. ::: ## 언제 Equatable를 사용해야 하나요 diff --git a/packages/hydrated_bloc/test/cubits/list_cubit.dart b/packages/hydrated_bloc/test/cubits/list_cubit.dart index 77016674ba8..9bf83299a1d 100644 --- a/packages/hydrated_bloc/test/cubits/list_cubit.dart +++ b/packages/hydrated_bloc/test/cubits/list_cubit.dart @@ -4,7 +4,7 @@ import 'package:meta/meta.dart'; class ListCubit extends HydratedCubit> { ListCubit() : super(const []); - void addItem(String item) => emit(List.from(state)..add(item)); + void addItem(String item) => emit(List.of(state)..add(item)); @override Map toJson(List state) { @@ -22,16 +22,14 @@ class ListCubitMap, E> extends HydratedCubit> { final T Function(Map json) _fromJson; final bool explicit; - void addItem(T item) => emit(List.from(state)..add(item)); + void addItem(T item) => emit(List.of(state)..add(item)); @override Map toJson(List state) { final map = { 'state': explicit - ? List>.from( - state.map( - (x) => x.toJson(), - ), + ? List>.of( + state.map((x) => x.toJson()), ) : state, }; @@ -53,17 +51,15 @@ class ListCubitList, E> extends HydratedCubit> { final T Function(List json) _fromJson; final bool explicit; - void addItem(T item) => emit(List.from(state)..add(item)); + void addItem(T item) => emit(List.of(state)..add(item)); void reset() => emit([]); @override Map toJson(List state) { final map = { 'state': explicit - ? List>.from( - state.map( - (x) => x.toJson(), - ), + ? List>.of( + state.map((x) => x.toJson()), ) : state, };