feat: get table

This commit is contained in:
efrilm
2025-08-03 23:53:06 +07:00
parent 8431b07057
commit 6afd62b617
14 changed files with 769 additions and 478 deletions
@@ -1,3 +1,4 @@
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
@@ -8,11 +9,17 @@ part 'get_table_state.dart';
part 'get_table_bloc.freezed.dart';
class GetTableBloc extends Bloc<GetTableEvent, GetTableState> {
GetTableBloc() : super(_Initial()) {
final TableRemoteDataSource _tableRemoteDataSource;
GetTableBloc(this._tableRemoteDataSource) : super(GetTableState.initial()) {
on<_GetTables>((event, emit) async {
emit(_Loading());
final tables = await ProductLocalDatasource.instance.getAllTable();
emit(_Success(tables));
final tables = await _tableRemoteDataSource.getTable();
tables.fold(
(l) => emit(_Error(l)),
(r) => emit(
_Success(r.data!.tables!),
),
);
});
}
}