feat: search product and fix product

This commit is contained in:
efrilm
2025-08-07 12:19:25 +07:00
parent 5575596bfc
commit fe92082ceb
9 changed files with 349 additions and 118 deletions
@@ -30,9 +30,14 @@ class CategoryLoaderBloc
updatedAt: DateTime.now(),
),
);
emit(_Loaded(categories));
emit(_Loaded(categories, null));
},
);
});
on<_SetCategoryId>((event, emit) async {
var currentState = state as _Loaded;
emit(_Loaded(currentState.categories, event.categoryId));
});
}
}
@@ -19,32 +19,38 @@ mixin _$CategoryLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
required TResult Function(_SetCategoryId value) setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
TResult Function(_SetCategoryId value)? setCategoryId,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@@ -111,6 +117,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) {
return get();
}
@@ -119,6 +126,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) {
return get?.call();
}
@@ -127,6 +135,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) {
if (get != null) {
@@ -139,6 +148,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
required TResult Function(_SetCategoryId value) setCategoryId,
}) {
return get(this);
}
@@ -147,6 +157,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) {
return get?.call(this);
}
@@ -155,6 +166,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
TResult Function(_SetCategoryId value)? setCategoryId,
required TResult orElse(),
}) {
if (get != null) {
@@ -168,13 +180,156 @@ abstract class _Get implements CategoryLoaderEvent {
const factory _Get() = _$GetImpl;
}
/// @nodoc
abstract class _$$SetCategoryIdImplCopyWith<$Res> {
factory _$$SetCategoryIdImplCopyWith(
_$SetCategoryIdImpl value, $Res Function(_$SetCategoryIdImpl) then) =
__$$SetCategoryIdImplCopyWithImpl<$Res>;
@useResult
$Res call({String categoryId});
}
/// @nodoc
class __$$SetCategoryIdImplCopyWithImpl<$Res>
extends _$CategoryLoaderEventCopyWithImpl<$Res, _$SetCategoryIdImpl>
implements _$$SetCategoryIdImplCopyWith<$Res> {
__$$SetCategoryIdImplCopyWithImpl(
_$SetCategoryIdImpl _value, $Res Function(_$SetCategoryIdImpl) _then)
: super(_value, _then);
/// Create a copy of CategoryLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? categoryId = null,
}) {
return _then(_$SetCategoryIdImpl(
null == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$SetCategoryIdImpl implements _SetCategoryId {
const _$SetCategoryIdImpl(this.categoryId);
@override
final String categoryId;
@override
String toString() {
return 'CategoryLoaderEvent.setCategoryId(categoryId: $categoryId)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SetCategoryIdImpl &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
}
@override
int get hashCode => Object.hash(runtimeType, categoryId);
/// Create a copy of CategoryLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SetCategoryIdImplCopyWith<_$SetCategoryIdImpl> get copyWith =>
__$$SetCategoryIdImplCopyWithImpl<_$SetCategoryIdImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) {
return setCategoryId(categoryId);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) {
return setCategoryId?.call(categoryId);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) {
if (setCategoryId != null) {
return setCategoryId(categoryId);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
required TResult Function(_SetCategoryId value) setCategoryId,
}) {
return setCategoryId(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) {
return setCategoryId?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
TResult Function(_SetCategoryId value)? setCategoryId,
required TResult orElse(),
}) {
if (setCategoryId != null) {
return setCategoryId(this);
}
return orElse();
}
}
abstract class _SetCategoryId implements CategoryLoaderEvent {
const factory _SetCategoryId(final String categoryId) = _$SetCategoryIdImpl;
String get categoryId;
/// Create a copy of CategoryLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SetCategoryIdImplCopyWith<_$SetCategoryIdImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$CategoryLoaderState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) =>
throw _privateConstructorUsedError;
@@ -182,7 +337,8 @@ mixin _$CategoryLoaderState {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) =>
throw _privateConstructorUsedError;
@@ -190,7 +346,8 @@ mixin _$CategoryLoaderState {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) =>
@@ -286,7 +443,9 @@ class _$InitialImpl implements _Initial {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return initial();
@@ -297,7 +456,8 @@ class _$InitialImpl implements _Initial {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return initial?.call();
@@ -308,7 +468,8 @@ class _$InitialImpl implements _Initial {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@@ -403,7 +564,9 @@ class _$LoadingImpl implements _Loading {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return loading();
@@ -414,7 +577,8 @@ class _$LoadingImpl implements _Loading {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return loading?.call();
@@ -425,7 +589,8 @@ class _$LoadingImpl implements _Loading {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@@ -483,7 +648,7 @@ abstract class _$$LoadedImplCopyWith<$Res> {
_$LoadedImpl value, $Res Function(_$LoadedImpl) then) =
__$$LoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<CategoryModel> categories});
$Res call({List<CategoryModel> categories, String? categoryId});
}
/// @nodoc
@@ -500,12 +665,17 @@ class __$$LoadedImplCopyWithImpl<$Res>
@override
$Res call({
Object? categories = null,
Object? categoryId = freezed,
}) {
return _then(_$LoadedImpl(
null == categories
? _value._categories
: categories // ignore: cast_nullable_to_non_nullable
as List<CategoryModel>,
freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@@ -513,7 +683,7 @@ class __$$LoadedImplCopyWithImpl<$Res>
/// @nodoc
class _$LoadedImpl implements _Loaded {
const _$LoadedImpl(final List<CategoryModel> categories)
const _$LoadedImpl(final List<CategoryModel> categories, this.categoryId)
: _categories = categories;
final List<CategoryModel> _categories;
@@ -524,9 +694,12 @@ class _$LoadedImpl implements _Loaded {
return EqualUnmodifiableListView(_categories);
}
@override
final String? categoryId;
@override
String toString() {
return 'CategoryLoaderState.loaded(categories: $categories)';
return 'CategoryLoaderState.loaded(categories: $categories, categoryId: $categoryId)';
}
@override
@@ -535,12 +708,14 @@ class _$LoadedImpl implements _Loaded {
(other.runtimeType == runtimeType &&
other is _$LoadedImpl &&
const DeepCollectionEquality()
.equals(other._categories, _categories));
.equals(other._categories, _categories) &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
}
@override
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_categories));
int get hashCode => Object.hash(runtimeType,
const DeepCollectionEquality().hash(_categories), categoryId);
/// Create a copy of CategoryLoaderState
/// with the given fields replaced by the non-null parameter values.
@@ -555,10 +730,12 @@ class _$LoadedImpl implements _Loaded {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return loaded(categories);
return loaded(categories, categoryId);
}
@override
@@ -566,10 +743,11 @@ class _$LoadedImpl implements _Loaded {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return loaded?.call(categories);
return loaded?.call(categories, categoryId);
}
@override
@@ -577,12 +755,13 @@ class _$LoadedImpl implements _Loaded {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(categories);
return loaded(categories, categoryId);
}
return orElse();
}
@@ -626,9 +805,12 @@ class _$LoadedImpl implements _Loaded {
}
abstract class _Loaded implements CategoryLoaderState {
const factory _Loaded(final List<CategoryModel> categories) = _$LoadedImpl;
const factory _Loaded(
final List<CategoryModel> categories, final String? categoryId) =
_$LoadedImpl;
List<CategoryModel> get categories;
String? get categoryId;
/// Create a copy of CategoryLoaderState
/// with the given fields replaced by the non-null parameter values.
@@ -707,7 +889,9 @@ class _$ErrorImpl implements _Error {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return error(message);
@@ -718,7 +902,8 @@ class _$ErrorImpl implements _Error {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return error?.call(message);
@@ -729,7 +914,8 @@ class _$ErrorImpl implements _Error {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@@ -3,4 +3,6 @@ part of 'category_loader_bloc.dart';
@freezed
class CategoryLoaderEvent with _$CategoryLoaderEvent {
const factory CategoryLoaderEvent.get() = _Get;
const factory CategoryLoaderEvent.setCategoryId(String categoryId) =
_SetCategoryId;
}
@@ -4,7 +4,7 @@ part of 'category_loader_bloc.dart';
class CategoryLoaderState with _$CategoryLoaderState {
const factory CategoryLoaderState.initial() = _Initial;
const factory CategoryLoaderState.loading() = _Loading;
const factory CategoryLoaderState.loaded(List<CategoryModel> categories) =
_Loaded;
const factory CategoryLoaderState.loaded(
List<CategoryModel> categories, String? categoryId) = _Loaded;
const factory CategoryLoaderState.error(String message) = _Error;
}