Compare commits

..

No commits in common. "fe92082cebf0363984ef122b4c610f63392bec8e" and "8022fa6b322a82e6fc8ba9ef6d6e40c1910e4bcb" have entirely different histories.

10 changed files with 120 additions and 363 deletions

View File

@ -2,9 +2,7 @@ import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:enaklo_pos/core/network/dio_client.dart';
import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart';
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
import 'package:enaklo_pos/presentation/setting/models/tax_model.dart';
import '../../core/constants/variables.dart';
import 'auth_local_datasource.dart';
@ -14,7 +12,6 @@ class OutletRemoteDataSource {
Future<Either<String, OutletResponse>> getOutlets() async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/outlets/list';
final response = await dio.get(
@ -31,8 +28,7 @@ class OutletRemoteDataSource {
);
if (response.statusCode == 200) {
final data = OutletResponse.fromMap(response.data);
return Right(data);
return Right(OutletResponse.fromMap(response.data));
} else {
return const Left('Failed to get outlets');
}
@ -70,15 +66,7 @@ class OutletRemoteDataSource {
);
if (response.statusCode == 200) {
final data = OutletDetailResponse.fromMap(response.data);
await SettingsLocalDatasource().saveTax(
TaxModel(
name: 'PB1',
type: TaxType.pajak,
value: data.data?.taxRate ?? 0,
),
);
return Right(data);
return Right(OutletDetailResponse.fromMap(response.data));
} else {
return const Left('Failed to get outlets');
}

View File

@ -17,7 +17,6 @@ class ProductRemoteDatasource {
int page = 1,
int limit = Variables.defaultLimit,
String? categoryId,
String? search,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
@ -32,10 +31,6 @@ class ProductRemoteDatasource {
queryParameters['category_id'] = categoryId;
}
if (search != null && search.isNotEmpty) {
queryParameters['search'] = search;
}
final response = await dio.get(
url,
queryParameters: queryParameters,

View File

@ -30,14 +30,9 @@ class CategoryLoaderBloc
updatedAt: DateTime.now(),
),
);
emit(_Loaded(categories, null));
emit(_Loaded(categories));
},
);
});
on<_SetCategoryId>((event, emit) async {
var currentState = state as _Loaded;
emit(_Loaded(currentState.categories, event.categoryId));
});
}
}

View File

@ -19,38 +19,32 @@ 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;
@ -117,7 +111,6 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) {
return get();
}
@ -126,7 +119,6 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) {
return get?.call();
}
@ -135,7 +127,6 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) {
if (get != null) {
@ -148,7 +139,6 @@ 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);
}
@ -157,7 +147,6 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) {
return get?.call(this);
}
@ -166,7 +155,6 @@ 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) {
@ -180,156 +168,13 @@ 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, String? categoryId)
loaded,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(String message) error,
}) =>
throw _privateConstructorUsedError;
@ -337,8 +182,7 @@ mixin _$CategoryLoaderState {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(String message)? error,
}) =>
throw _privateConstructorUsedError;
@ -346,8 +190,7 @@ mixin _$CategoryLoaderState {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) =>
@ -443,9 +286,7 @@ class _$InitialImpl implements _Initial {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(String message) error,
}) {
return initial();
@ -456,8 +297,7 @@ class _$InitialImpl implements _Initial {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(String message)? error,
}) {
return initial?.call();
@ -468,8 +308,7 @@ class _$InitialImpl implements _Initial {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@ -564,9 +403,7 @@ class _$LoadingImpl implements _Loading {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(String message) error,
}) {
return loading();
@ -577,8 +414,7 @@ class _$LoadingImpl implements _Loading {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(String message)? error,
}) {
return loading?.call();
@ -589,8 +425,7 @@ class _$LoadingImpl implements _Loading {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@ -648,7 +483,7 @@ abstract class _$$LoadedImplCopyWith<$Res> {
_$LoadedImpl value, $Res Function(_$LoadedImpl) then) =
__$$LoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<CategoryModel> categories, String? categoryId});
$Res call({List<CategoryModel> categories});
}
/// @nodoc
@ -665,17 +500,12 @@ 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?,
));
}
}
@ -683,7 +513,7 @@ class __$$LoadedImplCopyWithImpl<$Res>
/// @nodoc
class _$LoadedImpl implements _Loaded {
const _$LoadedImpl(final List<CategoryModel> categories, this.categoryId)
const _$LoadedImpl(final List<CategoryModel> categories)
: _categories = categories;
final List<CategoryModel> _categories;
@ -694,12 +524,9 @@ class _$LoadedImpl implements _Loaded {
return EqualUnmodifiableListView(_categories);
}
@override
final String? categoryId;
@override
String toString() {
return 'CategoryLoaderState.loaded(categories: $categories, categoryId: $categoryId)';
return 'CategoryLoaderState.loaded(categories: $categories)';
}
@override
@ -708,14 +535,12 @@ class _$LoadedImpl implements _Loaded {
(other.runtimeType == runtimeType &&
other is _$LoadedImpl &&
const DeepCollectionEquality()
.equals(other._categories, _categories) &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
.equals(other._categories, _categories));
}
@override
int get hashCode => Object.hash(runtimeType,
const DeepCollectionEquality().hash(_categories), categoryId);
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_categories));
/// Create a copy of CategoryLoaderState
/// with the given fields replaced by the non-null parameter values.
@ -730,12 +555,10 @@ class _$LoadedImpl implements _Loaded {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(String message) error,
}) {
return loaded(categories, categoryId);
return loaded(categories);
}
@override
@ -743,11 +566,10 @@ class _$LoadedImpl implements _Loaded {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(String message)? error,
}) {
return loaded?.call(categories, categoryId);
return loaded?.call(categories);
}
@override
@ -755,13 +577,12 @@ class _$LoadedImpl implements _Loaded {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(categories, categoryId);
return loaded(categories);
}
return orElse();
}
@ -805,12 +626,9 @@ class _$LoadedImpl implements _Loaded {
}
abstract class _Loaded implements CategoryLoaderState {
const factory _Loaded(
final List<CategoryModel> categories, final String? categoryId) =
_$LoadedImpl;
const factory _Loaded(final List<CategoryModel> categories) = _$LoadedImpl;
List<CategoryModel> get categories;
String? get categoryId;
/// Create a copy of CategoryLoaderState
/// with the given fields replaced by the non-null parameter values.
@ -889,9 +707,7 @@ class _$ErrorImpl implements _Error {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(String message) error,
}) {
return error(message);
@ -902,8 +718,7 @@ class _$ErrorImpl implements _Error {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(String message)? error,
}) {
return error?.call(message);
@ -914,8 +729,7 @@ class _$ErrorImpl implements _Error {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {

View File

@ -3,6 +3,4 @@ part of 'category_loader_bloc.dart';
@freezed
class CategoryLoaderEvent with _$CategoryLoaderEvent {
const factory CategoryLoaderEvent.get() = _Get;
const factory CategoryLoaderEvent.setCategoryId(String categoryId) =
_SetCategoryId;
}

View File

@ -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, String? categoryId) = _Loaded;
const factory CategoryLoaderState.loaded(List<CategoryModel> categories) =
_Loaded;
const factory CategoryLoaderState.error(String message) = _Error;
}

View File

@ -18,22 +18,22 @@ final _privateConstructorUsedError = UnsupportedError(
mixin _$ProductLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function() refresh,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function()? refresh,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) =>
@ -89,7 +89,7 @@ abstract class _$$GetProductImplCopyWith<$Res> {
_$GetProductImpl value, $Res Function(_$GetProductImpl) then) =
__$$GetProductImplCopyWithImpl<$Res>;
@useResult
$Res call({String? categoryId, String? search});
$Res call({String? categoryId});
}
/// @nodoc
@ -106,17 +106,12 @@ class __$$GetProductImplCopyWithImpl<$Res>
@override
$Res call({
Object? categoryId = freezed,
Object? search = freezed,
}) {
return _then(_$GetProductImpl(
categoryId: freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
search: freezed == search
? _value.search
: search // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@ -124,16 +119,14 @@ class __$$GetProductImplCopyWithImpl<$Res>
/// @nodoc
class _$GetProductImpl implements _GetProduct {
const _$GetProductImpl({this.categoryId, this.search});
const _$GetProductImpl({this.categoryId});
@override
final String? categoryId;
@override
final String? search;
@override
String toString() {
return 'ProductLoaderEvent.getProduct(categoryId: $categoryId, search: $search)';
return 'ProductLoaderEvent.getProduct(categoryId: $categoryId)';
}
@override
@ -142,12 +135,11 @@ class _$GetProductImpl implements _GetProduct {
(other.runtimeType == runtimeType &&
other is _$GetProductImpl &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId) &&
(identical(other.search, search) || other.search == search));
other.categoryId == categoryId));
}
@override
int get hashCode => Object.hash(runtimeType, categoryId, search);
int get hashCode => Object.hash(runtimeType, categoryId);
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@ -160,33 +152,33 @@ class _$GetProductImpl implements _GetProduct {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function() refresh,
}) {
return getProduct(categoryId, search);
return getProduct(categoryId);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function()? refresh,
}) {
return getProduct?.call(categoryId, search);
return getProduct?.call(categoryId);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) {
if (getProduct != null) {
return getProduct(categoryId, search);
return getProduct(categoryId);
}
return orElse();
}
@ -227,11 +219,9 @@ class _$GetProductImpl implements _GetProduct {
}
abstract class _GetProduct implements ProductLoaderEvent {
const factory _GetProduct({final String? categoryId, final String? search}) =
_$GetProductImpl;
const factory _GetProduct({final String? categoryId}) = _$GetProductImpl;
String? get categoryId;
String? get search;
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@ -246,7 +236,7 @@ abstract class _$$LoadMoreImplCopyWith<$Res> {
_$LoadMoreImpl value, $Res Function(_$LoadMoreImpl) then) =
__$$LoadMoreImplCopyWithImpl<$Res>;
@useResult
$Res call({String? categoryId, String? search});
$Res call({String? categoryId});
}
/// @nodoc
@ -263,17 +253,12 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
@override
$Res call({
Object? categoryId = freezed,
Object? search = freezed,
}) {
return _then(_$LoadMoreImpl(
categoryId: freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
search: freezed == search
? _value.search
: search // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@ -281,16 +266,14 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
/// @nodoc
class _$LoadMoreImpl implements _LoadMore {
const _$LoadMoreImpl({this.categoryId, this.search});
const _$LoadMoreImpl({this.categoryId});
@override
final String? categoryId;
@override
final String? search;
@override
String toString() {
return 'ProductLoaderEvent.loadMore(categoryId: $categoryId, search: $search)';
return 'ProductLoaderEvent.loadMore(categoryId: $categoryId)';
}
@override
@ -299,12 +282,11 @@ class _$LoadMoreImpl implements _LoadMore {
(other.runtimeType == runtimeType &&
other is _$LoadMoreImpl &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId) &&
(identical(other.search, search) || other.search == search));
other.categoryId == categoryId));
}
@override
int get hashCode => Object.hash(runtimeType, categoryId, search);
int get hashCode => Object.hash(runtimeType, categoryId);
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@ -317,33 +299,33 @@ class _$LoadMoreImpl implements _LoadMore {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function() refresh,
}) {
return loadMore(categoryId, search);
return loadMore(categoryId);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function()? refresh,
}) {
return loadMore?.call(categoryId, search);
return loadMore?.call(categoryId);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) {
if (loadMore != null) {
return loadMore(categoryId, search);
return loadMore(categoryId);
}
return orElse();
}
@ -384,11 +366,9 @@ class _$LoadMoreImpl implements _LoadMore {
}
abstract class _LoadMore implements ProductLoaderEvent {
const factory _LoadMore({final String? categoryId, final String? search}) =
_$LoadMoreImpl;
const factory _LoadMore({final String? categoryId}) = _$LoadMoreImpl;
String? get categoryId;
String? get search;
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@ -438,8 +418,8 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function() refresh,
}) {
return refresh();
@ -448,8 +428,8 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function()? refresh,
}) {
return refresh?.call();
@ -458,8 +438,8 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) {

View File

@ -2,9 +2,8 @@ part of 'product_loader_bloc.dart';
@freezed
class ProductLoaderEvent with _$ProductLoaderEvent {
const factory ProductLoaderEvent.getProduct(
{String? categoryId, String? search}) = _GetProduct;
const factory ProductLoaderEvent.loadMore(
{String? categoryId, String? search}) = _LoadMore;
const factory ProductLoaderEvent.getProduct({String? categoryId}) =
_GetProduct;
const factory ProductLoaderEvent.loadMore({String? categoryId}) = _LoadMore;
const factory ProductLoaderEvent.refresh() = _Refresh;
}

View File

@ -103,8 +103,7 @@ class _HomePageState extends State<HomePage> {
}).toList();
}
bool _handleScrollNotification(
ScrollNotification notification, String? categoryId) {
bool _handleScrollNotification(ScrollNotification notification) {
// Check if the ScrollController is attached before accessing position
if (!scrollController.hasClients) {
return false;
@ -112,12 +111,9 @@ class _HomePageState extends State<HomePage> {
if (notification is ScrollEndNotification &&
scrollController.position.extentAfter == 0) {
context.read<ProductLoaderBloc>().add(
ProductLoaderEvent.loadMore(
categoryId: categoryId,
search: searchQuery,
),
);
context
.read<ProductLoaderBloc>()
.add(const ProductLoaderEvent.loadMore());
return true;
}
return false;
@ -151,46 +147,42 @@ class _HomePageState extends State<HomePage> {
flex: 3,
child: Align(
alignment: AlignmentDirectional.topStart,
child: BlocBuilder<CategoryLoaderBloc, CategoryLoaderState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => Center(
child: CircularProgressIndicator(),
),
loaded: (categories, categoryId) => Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
HomeTitle(
controller: searchController,
onChanged: (value) {
setState(() {
searchQuery = value;
});
Future.delayed(Duration(milliseconds: 600), () {
context.read<ProductLoaderBloc>().add(
ProductLoaderEvent.getProduct(
categoryId: categoryId,
search: value,
),
);
});
},
),
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
builder: (context, state) {
return NotificationListener<ScrollNotification>(
onNotification: (notification) {
return state.maybeWhen(
orElse: () => false,
loaded: (products, hasReachedMax,
currentPage, isLoadingMore) {
return _handleScrollNotification(
notification, categoryId);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
HomeTitle(
controller: searchController,
onChanged: (value) {
setState(() {
searchQuery = value;
});
},
),
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
builder: (context, state) {
return NotificationListener<ScrollNotification>(
onNotification: (notification) {
return state.maybeWhen(
orElse: () => false,
loaded: (products, hasReachedMax, currentPage,
isLoadingMore) {
return _handleScrollNotification(
notification);
},
);
},
child: Expanded(child: BlocBuilder<
CategoryLoaderBloc, CategoryLoaderState>(
builder: (contextCategory, stateCateogry) {
return stateCateogry.maybeWhen(
orElse: () => SizedBox.shrink(),
loading: () {
return const Center(
child: CircularProgressIndicator(),
);
},
child: Expanded(
child: CategoryTabBar(
loaded: (categories) {
return CategoryTabBar(
categories: categories,
tabViews: categories.map((category) {
return SizedBox(
@ -236,15 +228,15 @@ class _HomePageState extends State<HomePage> {
}),
);
}).toList(),
),
),
);
},
);
},
),
],
),
);
},
)),
);
},
),
],
),
),
),

View File

@ -1,6 +1,5 @@
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
import 'package:enaklo_pos/presentation/home/bloc/category_loader/category_loader_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/product_loader/product_loader_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@ -37,9 +36,6 @@ class _CategoryTabBarState extends State<CategoryTabBar>
context.read<ProductLoaderBloc>().add(
ProductLoaderEvent.getProduct(categoryId: selectedCategoryId),
);
context
.read<CategoryLoaderBloc>()
.add(CategoryLoaderEvent.setCategoryId(selectedCategoryId ?? ""));
}
}
});