feat: create table

This commit is contained in:
efrilm
2025-08-03 23:33:00 +07:00
parent 617b5c54f2
commit 8431b07057
9 changed files with 393 additions and 95 deletions
@@ -1,7 +1,5 @@
import 'dart:ui';
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'create_table_event.dart';
@@ -9,12 +7,19 @@ part 'create_table_state.dart';
part 'create_table_bloc.freezed.dart';
class CreateTableBloc extends Bloc<CreateTableEvent, CreateTableState> {
CreateTableBloc() : super(_Initial()) {
final TableRemoteDataSource _tableRemoteDataSource;
CreateTableBloc(this._tableRemoteDataSource)
: super(CreateTableState.initial()) {
on<_CreateTable>((event, emit) async {
emit(_Loading());
await ProductLocalDatasource.instance
.createTableManagement(event.tableName, event.position);
emit(_Success('Create Table Success'));
final result = await _tableRemoteDataSource.createTable(
tableName: event.tableName,
capacity: event.capacity,
location: event.location,
);
result.fold((l) => emit(_Error(l)),
(r) => emit(_Success('Meja berhasil dibuat')));
});
}
}
@@ -19,19 +19,22 @@ mixin _$CreateTableEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(String tableName, Offset position) createTable,
required TResult Function(String tableName, int capacity, String location)
createTable,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(String tableName, Offset position)? createTable,
TResult? Function(String tableName, int capacity, String location)?
createTable,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(String tableName, Offset position)? createTable,
TResult Function(String tableName, int capacity, String location)?
createTable,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@@ -119,7 +122,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(String tableName, Offset position) createTable,
required TResult Function(String tableName, int capacity, String location)
createTable,
}) {
return started();
}
@@ -128,7 +132,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(String tableName, Offset position)? createTable,
TResult? Function(String tableName, int capacity, String location)?
createTable,
}) {
return started?.call();
}
@@ -137,7 +142,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(String tableName, Offset position)? createTable,
TResult Function(String tableName, int capacity, String location)?
createTable,
required TResult orElse(),
}) {
if (started != null) {
@@ -188,7 +194,7 @@ abstract class _$$CreateTableImplCopyWith<$Res> {
_$CreateTableImpl value, $Res Function(_$CreateTableImpl) then) =
__$$CreateTableImplCopyWithImpl<$Res>;
@useResult
$Res call({String tableName, Offset position});
$Res call({String tableName, int capacity, String location});
}
/// @nodoc
@@ -205,17 +211,22 @@ class __$$CreateTableImplCopyWithImpl<$Res>
@override
$Res call({
Object? tableName = null,
Object? position = null,
Object? capacity = null,
Object? location = null,
}) {
return _then(_$CreateTableImpl(
null == tableName
tableName: null == tableName
? _value.tableName
: tableName // ignore: cast_nullable_to_non_nullable
as String,
null == position
? _value.position
: position // ignore: cast_nullable_to_non_nullable
as Offset,
capacity: null == capacity
? _value.capacity
: capacity // ignore: cast_nullable_to_non_nullable
as int,
location: null == location
? _value.location
: location // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
@@ -223,16 +234,21 @@ class __$$CreateTableImplCopyWithImpl<$Res>
/// @nodoc
class _$CreateTableImpl implements _CreateTable {
const _$CreateTableImpl(this.tableName, this.position);
const _$CreateTableImpl(
{required this.tableName,
required this.capacity,
required this.location});
@override
final String tableName;
@override
final Offset position;
final int capacity;
@override
final String location;
@override
String toString() {
return 'CreateTableEvent.createTable(tableName: $tableName, position: $position)';
return 'CreateTableEvent.createTable(tableName: $tableName, capacity: $capacity, location: $location)';
}
@override
@@ -242,12 +258,14 @@ class _$CreateTableImpl implements _CreateTable {
other is _$CreateTableImpl &&
(identical(other.tableName, tableName) ||
other.tableName == tableName) &&
(identical(other.position, position) ||
other.position == position));
(identical(other.capacity, capacity) ||
other.capacity == capacity) &&
(identical(other.location, location) ||
other.location == location));
}
@override
int get hashCode => Object.hash(runtimeType, tableName, position);
int get hashCode => Object.hash(runtimeType, tableName, capacity, location);
/// Create a copy of CreateTableEvent
/// with the given fields replaced by the non-null parameter values.
@@ -261,29 +279,32 @@ class _$CreateTableImpl implements _CreateTable {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() started,
required TResult Function(String tableName, Offset position) createTable,
required TResult Function(String tableName, int capacity, String location)
createTable,
}) {
return createTable(tableName, position);
return createTable(tableName, capacity, location);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started,
TResult? Function(String tableName, Offset position)? createTable,
TResult? Function(String tableName, int capacity, String location)?
createTable,
}) {
return createTable?.call(tableName, position);
return createTable?.call(tableName, capacity, location);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? started,
TResult Function(String tableName, Offset position)? createTable,
TResult Function(String tableName, int capacity, String location)?
createTable,
required TResult orElse(),
}) {
if (createTable != null) {
return createTable(tableName, position);
return createTable(tableName, capacity, location);
}
return orElse();
}
@@ -321,11 +342,14 @@ class _$CreateTableImpl implements _CreateTable {
}
abstract class _CreateTable implements CreateTableEvent {
const factory _CreateTable(final String tableName, final Offset position) =
_$CreateTableImpl;
const factory _CreateTable(
{required final String tableName,
required final int capacity,
required final String location}) = _$CreateTableImpl;
String get tableName;
Offset get position;
int get capacity;
String get location;
/// Create a copy of CreateTableEvent
/// with the given fields replaced by the non-null parameter values.
@@ -341,6 +365,7 @@ mixin _$CreateTableState {
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(String message) success,
required TResult Function(String message) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -348,6 +373,7 @@ mixin _$CreateTableState {
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -355,6 +381,7 @@ mixin _$CreateTableState {
TResult Function()? initial,
TResult Function()? loading,
TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@@ -363,6 +390,7 @@ mixin _$CreateTableState {
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -370,6 +398,7 @@ mixin _$CreateTableState {
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -377,6 +406,7 @@ mixin _$CreateTableState {
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@@ -447,6 +477,7 @@ class _$InitialImpl implements _Initial {
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(String message) success,
required TResult Function(String message) error,
}) {
return initial();
}
@@ -457,6 +488,7 @@ class _$InitialImpl implements _Initial {
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) {
return initial?.call();
}
@@ -467,6 +499,7 @@ class _$InitialImpl implements _Initial {
TResult Function()? initial,
TResult Function()? loading,
TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (initial != null) {
@@ -481,6 +514,7 @@ class _$InitialImpl implements _Initial {
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) {
return initial(this);
}
@@ -491,6 +525,7 @@ class _$InitialImpl implements _Initial {
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) {
return initial?.call(this);
}
@@ -501,6 +536,7 @@ class _$InitialImpl implements _Initial {
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (initial != null) {
@@ -558,6 +594,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(String message) success,
required TResult Function(String message) error,
}) {
return loading();
}
@@ -568,6 +605,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) {
return loading?.call();
}
@@ -578,6 +616,7 @@ class _$LoadingImpl implements _Loading {
TResult Function()? initial,
TResult Function()? loading,
TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loading != null) {
@@ -592,6 +631,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) {
return loading(this);
}
@@ -602,6 +642,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) {
return loading?.call(this);
}
@@ -612,6 +653,7 @@ class _$LoadingImpl implements _Loading {
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (loading != null) {
@@ -696,6 +738,7 @@ class _$SuccessImpl implements _Success {
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(String message) success,
required TResult Function(String message) error,
}) {
return success(message);
}
@@ -706,6 +749,7 @@ class _$SuccessImpl implements _Success {
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) {
return success?.call(message);
}
@@ -716,6 +760,7 @@ class _$SuccessImpl implements _Success {
TResult Function()? initial,
TResult Function()? loading,
TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (success != null) {
@@ -730,6 +775,7 @@ class _$SuccessImpl implements _Success {
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) {
return success(this);
}
@@ -740,6 +786,7 @@ class _$SuccessImpl implements _Success {
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) {
return success?.call(this);
}
@@ -750,6 +797,7 @@ class _$SuccessImpl implements _Success {
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (success != null) {
@@ -770,3 +818,155 @@ abstract class _Success implements CreateTableState {
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$ErrorImplCopyWith<$Res> {
factory _$$ErrorImplCopyWith(
_$ErrorImpl value, $Res Function(_$ErrorImpl) then) =
__$$ErrorImplCopyWithImpl<$Res>;
@useResult
$Res call({String message});
}
/// @nodoc
class __$$ErrorImplCopyWithImpl<$Res>
extends _$CreateTableStateCopyWithImpl<$Res, _$ErrorImpl>
implements _$$ErrorImplCopyWith<$Res> {
__$$ErrorImplCopyWithImpl(
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
: super(_value, _then);
/// Create a copy of CreateTableState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? message = null,
}) {
return _then(_$ErrorImpl(
null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$ErrorImpl implements _Error {
const _$ErrorImpl(this.message);
@override
final String message;
@override
String toString() {
return 'CreateTableState.error(message: $message)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ErrorImpl &&
(identical(other.message, message) || other.message == message));
}
@override
int get hashCode => Object.hash(runtimeType, message);
/// Create a copy of CreateTableState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
__$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(String message) success,
required TResult Function(String message) error,
}) {
return error(message);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) {
return error?.call(message);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(message);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) {
return error(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) {
return error?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(this);
}
return orElse();
}
}
abstract class _Error implements CreateTableState {
const factory _Error(final String message) = _$ErrorImpl;
String get message;
/// Create a copy of CreateTableState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -3,6 +3,9 @@ part of 'create_table_bloc.dart';
@freezed
class CreateTableEvent with _$CreateTableEvent {
const factory CreateTableEvent.started() = _Started;
const factory CreateTableEvent.createTable(
String tableName, Offset position) = _CreateTable;
const factory CreateTableEvent.createTable({
required String tableName,
required int capacity,
required String location,
}) = _CreateTable;
}
@@ -7,4 +7,5 @@ class CreateTableState with _$CreateTableState {
const factory CreateTableState.loading() = _Loading;
// success
const factory CreateTableState.success(String message) = _Success;
const factory CreateTableState.error(String message) = _Error;
}