Compare commits

..

4 Commits

Author SHA1 Message Date
efrilm
571ba9802e feat: update save 2025-08-04 00:50:10 +07:00
efrilm
6302ea0282 feat: update position table 2025-08-04 00:09:51 +07:00
efrilm
6afd62b617 feat: get table 2025-08-03 23:53:06 +07:00
efrilm
8431b07057 feat: create table 2025-08-03 23:33:00 +07:00
34 changed files with 1717 additions and 791 deletions

View File

@ -14,7 +14,7 @@ class CustomTextField extends StatelessWidget {
final Widget? prefixIcon; final Widget? prefixIcon;
final Widget? suffixIcon; final Widget? suffixIcon;
final bool readOnly; final bool readOnly;
final int? maxLines; final int maxLines;
final String? Function(String?)? validator; final String? Function(String?)? validator;
const CustomTextField({ const CustomTextField({
@ -30,7 +30,7 @@ class CustomTextField extends StatelessWidget {
this.prefixIcon, this.prefixIcon,
this.suffixIcon, this.suffixIcon,
this.readOnly = false, this.readOnly = false,
this.maxLines, this.maxLines = 1,
this.validator, this.validator,
}); });

View File

@ -358,19 +358,19 @@ class ProductLocalDatasource {
// generate table managent with count // generate table managent with count
Future<void> createTableManagement(String tableName, Offset position) async { Future<void> createTableManagement(String tableName, Offset position) async {
final db = await instance.database; // final db = await instance.database;
TableModel newTable = TableModel( // TableModel newTable = TableModel(
tableName: tableName, // tableName: tableName,
status: 'available', // status: 'available',
orderId: 0, // orderId: 0,
paymentAmount: 0, // paymentAmount: 0,
startTime: DateTime.now().toIso8601String(), // startTime: DateTime.now().toIso8601String(),
position: position, // position: position,
); // );
await db.insert( // await db.insert(
tableManagement, // tableManagement,
newTable.toMap(), // newTable.toMap(),
); // );
} }
// change position table // change position table

View File

@ -0,0 +1,134 @@
import 'dart:developer';
import 'dart:ui';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:enaklo_pos/core/network/dio_client.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import '../../core/constants/variables.dart';
import 'auth_local_datasource.dart';
class TableRemoteDataSource {
final Dio dio = DioClient.instance;
Future<Either<String, bool>> createTable({
required String tableName,
required int capacity,
required String location,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/tables';
final response = await dio.post(
url,
data: {
"outlet_id": authData.user?.outletId,
"table_name": tableName,
"capacity": capacity,
"location": location,
"status": "available",
"is_active": true,
"position_x": 200,
"position_y": 200,
},
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
},
),
);
if (response.statusCode == 200 || response.statusCode == 201) {
return Right(true);
} else {
return const Left('Failed to create table');
}
} on DioException catch (e) {
log("Dio error: ${e.message}");
return Left(e.response?.data['message'] ?? 'Gagal membuat table');
} catch (e) {
log("Unexpected error: $e");
return const Left('Unexpected error occurred');
}
}
Future<Either<String, TableResponseModel>> getTable({
int page = 1,
int limit = 10,
String? status,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/tables';
Map<String, dynamic> queryParameters = {
'page': page,
'limit': limit,
};
if (status != null) {
queryParameters['status'] = status;
}
final response = await dio.get(
url,
queryParameters: queryParameters,
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
},
),
);
if (response.statusCode == 200) {
return Right(TableResponseModel.fromMap(response.data));
} else {
return const Left('Failed to get tables');
}
} on DioException catch (e) {
log("Dio error: ${e.message}");
return Left(e.response?.data['message'] ?? 'Gagal mengambil data meja');
} catch (e) {
log("Unexpected error: $e");
return const Left('Unexpected error occurred');
}
}
Future<Either<String, bool>> updatePosition({
required String tableId,
required Offset position,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/tables/$tableId';
final response = await dio.put(
url,
data: {
"position_x": position.dx.round(),
"position_y": position.dy.round(),
},
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
},
),
);
if (response.statusCode == 200 || response.statusCode == 201) {
return Right(true);
} else {
return const Left('Failed to create table');
}
} on DioException catch (e) {
log("Dio error: ${e.message}");
return Left(e.response?.data['message'] ?? 'Gagal membuat table');
} catch (e) {
log("Unexpected error: $e");
return const Left('Unexpected error occurred');
}
}
}

View File

@ -1,74 +1,132 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first import 'dart:convert';
import 'dart:ui';
class TableResponseModel {
final bool? success;
final TableData? data;
final dynamic errors;
TableResponseModel({
this.success,
this.data,
this.errors,
});
factory TableResponseModel.fromJson(String str) =>
TableResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory TableResponseModel.fromMap(Map<String, dynamic> json) =>
TableResponseModel(
success: json["success"],
data: json["data"] == null ? null : TableData.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
class TableData {
final List<TableModel>? tables;
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
TableData({
this.tables,
this.totalCount,
this.page,
this.limit,
this.totalPages,
});
factory TableData.fromMap(Map<String, dynamic> json) => TableData(
tables: json["tables"] == null
? []
: List<TableModel>.from(
json["tables"].map((x) => TableModel.fromMap(x))),
totalCount: json["total_count"],
page: json["page"],
limit: json["limit"],
totalPages: json["total_pages"],
);
Map<String, dynamic> toMap() => {
"tables": tables == null
? []
: List<dynamic>.from(tables!.map((x) => x.toMap())),
"total_count": totalCount,
"page": page,
"limit": limit,
"total_pages": totalPages,
};
}
class TableModel { class TableModel {
int? id; final String? id;
final String tableName; final String? organizationId;
final String startTime; final String? outletId;
final String status; final String? tableName;
final int orderId; final String? status;
final int paymentAmount; final int? paymentAmount;
final Offset position; final double? positionX;
final double? positionY;
final int? capacity;
final bool? isActive;
final DateTime? createdAt;
final DateTime? updatedAt;
TableModel({ TableModel({
this.id, this.id,
required this.tableName, this.organizationId,
required this.startTime, this.outletId,
required this.status, this.tableName,
required this.orderId, this.status,
required this.paymentAmount, this.paymentAmount,
required this.position, this.positionX,
this.positionY,
this.capacity,
this.isActive,
this.createdAt,
this.updatedAt,
}); });
@override factory TableModel.fromMap(Map<String, dynamic> json) => TableModel(
id: json["id"],
organizationId: json["organization_id"],
outletId: json["outlet_id"],
tableName: json["table_name"],
status: json["status"],
paymentAmount: json["payment_amount"],
positionX: json["position_x"]?.toDouble(),
positionY: json["position_y"]?.toDouble(),
capacity: json["capacity"],
isActive: json["is_active"],
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
// from map Map<String, dynamic> toMap() => {
factory TableModel.fromMap(Map<String, dynamic> map) { "id": id,
return TableModel( "organization_id": organizationId,
id: map['id'], "outlet_id": outletId,
tableName: map['table_name'], "table_name": tableName,
startTime: map['start_time'], "status": status,
status: map['status'], "payment_amount": paymentAmount,
orderId: map['order_id'], "position_x": positionX,
paymentAmount: map['payment_amount'], "position_y": positionY,
position: Offset(map['x_position'], map['y_position']), "capacity": capacity,
); "is_active": isActive,
} "created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
// to map };
Map<String, dynamic> toMap() {
return {
'table_name': tableName,
'status': status,
'start_time': startTime,
'order_id': orderId,
'payment_amount': paymentAmount,
'x_position': position.dx,
'y_position': position.dy,
};
}
@override
bool operator ==(covariant TableModel other) {
if (identical(this, other)) return true;
return other.id == id &&
other.tableName == tableName &&
other.startTime == startTime &&
other.status == status &&
other.orderId == orderId &&
other.paymentAmount == paymentAmount &&
other.position == position;
}
@override
int get hashCode {
return id.hashCode ^
tableName.hashCode ^
startTime.hashCode ^
status.hashCode ^
orderId.hashCode ^
paymentAmount.hashCode ^
position.hashCode;
}
} }

View File

@ -2,6 +2,7 @@ import 'dart:developer';
import 'package:enaklo_pos/core/constants/theme.dart'; import 'package:enaklo_pos/core/constants/theme.dart';
import 'package:enaklo_pos/data/datasources/customer_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/customer_remote_datasource.dart';
import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart'; import 'package:enaklo_pos/data/datasources/outlet_remote_data_source.dart';
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:enaklo_pos/presentation/customer/bloc/customer_form/customer_form_bloc.dart'; import 'package:enaklo_pos/presentation/customer/bloc/customer_form/customer_form_bloc.dart';
import 'package:enaklo_pos/presentation/customer/bloc/customer_loader/customer_loader_bloc.dart'; import 'package:enaklo_pos/presentation/customer/bloc/customer_loader/customer_loader_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dart';
@ -147,13 +148,13 @@ class _MyAppState extends State<MyApp> {
create: (context) => TransactionReportBloc(OrderRemoteDatasource()), create: (context) => TransactionReportBloc(OrderRemoteDatasource()),
), ),
BlocProvider( BlocProvider(
create: (context) => CreateTableBloc(), create: (context) => CreateTableBloc(TableRemoteDataSource()),
), ),
BlocProvider( BlocProvider(
create: (context) => ChangePositionTableBloc(), create: (context) => ChangePositionTableBloc(TableRemoteDataSource()),
), ),
BlocProvider( BlocProvider(
create: (context) => GetTableBloc(), create: (context) => GetTableBloc(TableRemoteDataSource()),
), ),
BlocProvider( BlocProvider(
create: (context) => UpdateTableBloc(), create: (context) => UpdateTableBloc(),
@ -166,7 +167,7 @@ class _MyAppState extends State<MyApp> {
LastOrderTableBloc(ProductLocalDatasource.instance), LastOrderTableBloc(ProductLocalDatasource.instance),
), ),
BlocProvider( BlocProvider(
create: (context) => GetTableStatusBloc(), create: (context) => GetTableStatusBloc(TableRemoteDataSource()),
), ),
BlocProvider( BlocProvider(
create: (context) => AddProductBloc(ProductRemoteDatasource()), create: (context) => AddProductBloc(ProductRemoteDatasource()),

View File

@ -1,5 +1,5 @@
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:flutter_bloc/flutter_bloc.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'; import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
@ -9,12 +9,17 @@ part 'get_table_status_bloc.freezed.dart';
class GetTableStatusBloc class GetTableStatusBloc
extends Bloc<GetTableStatusEvent, GetTableStatusState> { extends Bloc<GetTableStatusEvent, GetTableStatusState> {
GetTableStatusBloc() : super(_Initial()) { final TableRemoteDataSource _tableRemoteDataSource;
GetTableStatusBloc(this._tableRemoteDataSource) : super(_Initial()) {
on<_GetTablesStatus>((event, emit) async { on<_GetTablesStatus>((event, emit) async {
emit(_Loading()); emit(_Loading());
final tables = final tables =
await ProductLocalDatasource.instance.getTableByStatus(event.status); await _tableRemoteDataSource.getTable(status: event.status);
emit(_Success(tables));
tables.fold(
(failure) => emit(_Error(failure)),
(tableResponse) => emit(_Success(tableResponse.data!.tables!)),
);
}); });
} }
} }

View File

@ -330,6 +330,7 @@ mixin _$GetTableStatusState {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -337,6 +338,7 @@ mixin _$GetTableStatusState {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -344,6 +346,7 @@ mixin _$GetTableStatusState {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -352,6 +355,7 @@ mixin _$GetTableStatusState {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -359,6 +363,7 @@ mixin _$GetTableStatusState {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -366,6 +371,7 @@ mixin _$GetTableStatusState {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -436,6 +442,7 @@ class _$InitialImpl implements _Initial {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) { }) {
return initial(); return initial();
} }
@ -446,6 +453,7 @@ class _$InitialImpl implements _Initial {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) { }) {
return initial?.call(); return initial?.call();
} }
@ -456,6 +464,7 @@ class _$InitialImpl implements _Initial {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -470,6 +479,7 @@ class _$InitialImpl implements _Initial {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return initial(this); return initial(this);
} }
@ -480,6 +490,7 @@ class _$InitialImpl implements _Initial {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return initial?.call(this); return initial?.call(this);
} }
@ -490,6 +501,7 @@ class _$InitialImpl implements _Initial {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -547,6 +559,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) { }) {
return loading(); return loading();
} }
@ -557,6 +570,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) { }) {
return loading?.call(); return loading?.call();
} }
@ -567,6 +581,7 @@ class _$LoadingImpl implements _Loading {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -581,6 +596,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return loading(this); return loading(this);
} }
@ -591,6 +607,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return loading?.call(this); return loading?.call(this);
} }
@ -601,6 +618,7 @@ class _$LoadingImpl implements _Loading {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -691,6 +709,7 @@ class _$SuccessImpl implements _Success {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) { }) {
return success(tables); return success(tables);
} }
@ -701,6 +720,7 @@ class _$SuccessImpl implements _Success {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) { }) {
return success?.call(tables); return success?.call(tables);
} }
@ -711,6 +731,7 @@ class _$SuccessImpl implements _Success {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -725,6 +746,7 @@ class _$SuccessImpl implements _Success {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return success(this); return success(this);
} }
@ -735,6 +757,7 @@ class _$SuccessImpl implements _Success {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return success?.call(this); return success?.call(this);
} }
@ -745,6 +768,7 @@ class _$SuccessImpl implements _Success {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -765,3 +789,155 @@ abstract class _Success implements GetTableStatusState {
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError; 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 _$GetTableStatusStateCopyWithImpl<$Res, _$ErrorImpl>
implements _$$ErrorImplCopyWith<$Res> {
__$$ErrorImplCopyWithImpl(
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
: super(_value, _then);
/// Create a copy of GetTableStatusState
/// 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 'GetTableStatusState.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 GetTableStatusState
/// 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(List<TableModel> tables) 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(List<TableModel> tables)? 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(List<TableModel> tables)? 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 GetTableStatusState {
const factory _Error(final String message) = _$ErrorImpl;
String get message;
/// Create a copy of GetTableStatusState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -5,4 +5,5 @@ class GetTableStatusState with _$GetTableStatusState {
const factory GetTableStatusState.initial() = _Initial; const factory GetTableStatusState.initial() = _Initial;
const factory GetTableStatusState.loading() = _Loading; const factory GetTableStatusState.loading() = _Loading;
const factory GetTableStatusState.success(List<TableModel> tables) = _Success; const factory GetTableStatusState.success(List<TableModel> tables) = _Success;
const factory GetTableStatusState.error(String message) = _Error;
} }

View File

@ -5,6 +5,7 @@ import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart'; import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/home/models/order_request.dart'; import 'package:enaklo_pos/presentation/home/models/order_request.dart';
import 'package:enaklo_pos/presentation/home/models/order_type.dart'; import 'package:enaklo_pos/presentation/home/models/order_type.dart';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart'; import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
@ -33,7 +34,8 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
customerName: event.customerName, customerName: event.customerName,
notes: '', notes: '',
orderType: event.orderType.name, orderType: event.orderType.name,
tableNumber: event.tableNumber.toString(), tableId: event.table.id,
tableNumber: event.table.tableName,
outletId: userData.user?.outletId, outletId: userData.user?.outletId,
userId: userData.user?.id, userId: userData.user?.id,
orderItems: event.items orderItems: event.items
@ -73,7 +75,8 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
customerName: event.customerName, customerName: event.customerName,
notes: '', notes: '',
orderType: event.orderType.name, orderType: event.orderType.name,
tableNumber: event.tableNumber.toString(), tableId: event.table.id,
tableNumber: event.table.tableName,
outletId: userData.user?.outletId, outletId: userData.user?.outletId,
userId: userData.user?.id, userId: userData.user?.id,
orderItems: event.items orderItems: event.items

View File

@ -20,14 +20,10 @@ mixin _$OrderFormEvent {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
@ -38,14 +34,10 @@ mixin _$OrderFormEvent {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
@ -56,14 +48,10 @@ mixin _$OrderFormEvent {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,
@ -195,14 +183,10 @@ class _$StartedImpl implements _Started {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
@ -216,14 +200,10 @@ class _$StartedImpl implements _Started {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
@ -237,14 +217,10 @@ class _$StartedImpl implements _Started {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,
@ -323,7 +299,7 @@ abstract class _$$CreateImplCopyWith<$Res> {
{List<ProductQuantity> items, {List<ProductQuantity> items,
String customerName, String customerName,
OrderType orderType, OrderType orderType,
String tableNumber}); TableModel table});
} }
/// @nodoc /// @nodoc
@ -342,7 +318,7 @@ class __$$CreateImplCopyWithImpl<$Res>
Object? items = null, Object? items = null,
Object? customerName = null, Object? customerName = null,
Object? orderType = null, Object? orderType = null,
Object? tableNumber = null, Object? table = freezed,
}) { }) {
return _then(_$CreateImpl( return _then(_$CreateImpl(
items: null == items items: null == items
@ -357,10 +333,10 @@ class __$$CreateImplCopyWithImpl<$Res>
? _value.orderType ? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable : orderType // ignore: cast_nullable_to_non_nullable
as OrderType, as OrderType,
tableNumber: null == tableNumber table: freezed == table
? _value.tableNumber ? _value.table
: tableNumber // ignore: cast_nullable_to_non_nullable : table // ignore: cast_nullable_to_non_nullable
as String, as TableModel,
)); ));
} }
} }
@ -372,7 +348,7 @@ class _$CreateImpl implements _Create {
{required final List<ProductQuantity> items, {required final List<ProductQuantity> items,
required this.customerName, required this.customerName,
required this.orderType, required this.orderType,
required this.tableNumber}) required this.table})
: _items = items; : _items = items;
final List<ProductQuantity> _items; final List<ProductQuantity> _items;
@ -388,11 +364,11 @@ class _$CreateImpl implements _Create {
@override @override
final OrderType orderType; final OrderType orderType;
@override @override
final String tableNumber; final TableModel table;
@override @override
String toString() { String toString() {
return 'OrderFormEvent.create(items: $items, customerName: $customerName, orderType: $orderType, tableNumber: $tableNumber)'; return 'OrderFormEvent.create(items: $items, customerName: $customerName, orderType: $orderType, table: $table)';
} }
@override @override
@ -405,8 +381,7 @@ class _$CreateImpl implements _Create {
other.customerName == customerName) && other.customerName == customerName) &&
(identical(other.orderType, orderType) || (identical(other.orderType, orderType) ||
other.orderType == orderType) && other.orderType == orderType) &&
(identical(other.tableNumber, tableNumber) || const DeepCollectionEquality().equals(other.table, table));
other.tableNumber == tableNumber));
} }
@override @override
@ -415,7 +390,7 @@ class _$CreateImpl implements _Create {
const DeepCollectionEquality().hash(_items), const DeepCollectionEquality().hash(_items),
customerName, customerName,
orderType, orderType,
tableNumber); const DeepCollectionEquality().hash(table));
/// Create a copy of OrderFormEvent /// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -430,20 +405,16 @@ class _$CreateImpl implements _Create {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
required TResult Function() refund, required TResult Function() refund,
}) { }) {
return create(items, customerName, orderType, tableNumber); return create(items, customerName, orderType, table);
} }
@override @override
@ -451,20 +422,16 @@ class _$CreateImpl implements _Create {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
TResult? Function()? refund, TResult? Function()? refund,
}) { }) {
return create?.call(items, customerName, orderType, tableNumber); return create?.call(items, customerName, orderType, table);
} }
@override @override
@ -472,14 +439,10 @@ class _$CreateImpl implements _Create {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,
@ -487,7 +450,7 @@ class _$CreateImpl implements _Create {
required TResult orElse(), required TResult orElse(),
}) { }) {
if (create != null) { if (create != null) {
return create(items, customerName, orderType, tableNumber); return create(items, customerName, orderType, table);
} }
return orElse(); return orElse();
} }
@ -541,12 +504,12 @@ abstract class _Create implements OrderFormEvent {
{required final List<ProductQuantity> items, {required final List<ProductQuantity> items,
required final String customerName, required final String customerName,
required final OrderType orderType, required final OrderType orderType,
required final String tableNumber}) = _$CreateImpl; required final TableModel table}) = _$CreateImpl;
List<ProductQuantity> get items; List<ProductQuantity> get items;
String get customerName; String get customerName;
OrderType get orderType; OrderType get orderType;
String get tableNumber; TableModel get table;
/// Create a copy of OrderFormEvent /// Create a copy of OrderFormEvent
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -566,7 +529,7 @@ abstract class _$$CreateWithPaymentMethodImplCopyWith<$Res> {
{List<ProductQuantity> items, {List<ProductQuantity> items,
String customerName, String customerName,
OrderType orderType, OrderType orderType,
String tableNumber, TableModel table,
PaymentMethod paymentMethod}); PaymentMethod paymentMethod});
} }
@ -587,7 +550,7 @@ class __$$CreateWithPaymentMethodImplCopyWithImpl<$Res>
Object? items = null, Object? items = null,
Object? customerName = null, Object? customerName = null,
Object? orderType = null, Object? orderType = null,
Object? tableNumber = null, Object? table = freezed,
Object? paymentMethod = null, Object? paymentMethod = null,
}) { }) {
return _then(_$CreateWithPaymentMethodImpl( return _then(_$CreateWithPaymentMethodImpl(
@ -603,10 +566,10 @@ class __$$CreateWithPaymentMethodImplCopyWithImpl<$Res>
? _value.orderType ? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable : orderType // ignore: cast_nullable_to_non_nullable
as OrderType, as OrderType,
tableNumber: null == tableNumber table: freezed == table
? _value.tableNumber ? _value.table
: tableNumber // ignore: cast_nullable_to_non_nullable : table // ignore: cast_nullable_to_non_nullable
as String, as TableModel,
paymentMethod: null == paymentMethod paymentMethod: null == paymentMethod
? _value.paymentMethod ? _value.paymentMethod
: paymentMethod // ignore: cast_nullable_to_non_nullable : paymentMethod // ignore: cast_nullable_to_non_nullable
@ -622,7 +585,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
{required final List<ProductQuantity> items, {required final List<ProductQuantity> items,
required this.customerName, required this.customerName,
required this.orderType, required this.orderType,
required this.tableNumber, required this.table,
required this.paymentMethod}) required this.paymentMethod})
: _items = items; : _items = items;
@ -639,13 +602,13 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
@override @override
final OrderType orderType; final OrderType orderType;
@override @override
final String tableNumber; final TableModel table;
@override @override
final PaymentMethod paymentMethod; final PaymentMethod paymentMethod;
@override @override
String toString() { String toString() {
return 'OrderFormEvent.createWithPayment(items: $items, customerName: $customerName, orderType: $orderType, tableNumber: $tableNumber, paymentMethod: $paymentMethod)'; return 'OrderFormEvent.createWithPayment(items: $items, customerName: $customerName, orderType: $orderType, table: $table, paymentMethod: $paymentMethod)';
} }
@override @override
@ -658,8 +621,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
other.customerName == customerName) && other.customerName == customerName) &&
(identical(other.orderType, orderType) || (identical(other.orderType, orderType) ||
other.orderType == orderType) && other.orderType == orderType) &&
(identical(other.tableNumber, tableNumber) || const DeepCollectionEquality().equals(other.table, table) &&
other.tableNumber == tableNumber) &&
(identical(other.paymentMethod, paymentMethod) || (identical(other.paymentMethod, paymentMethod) ||
other.paymentMethod == paymentMethod)); other.paymentMethod == paymentMethod));
} }
@ -670,7 +632,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
const DeepCollectionEquality().hash(_items), const DeepCollectionEquality().hash(_items),
customerName, customerName,
orderType, orderType,
tableNumber, const DeepCollectionEquality().hash(table),
paymentMethod); paymentMethod);
/// Create a copy of OrderFormEvent /// Create a copy of OrderFormEvent
@ -687,21 +649,17 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
required TResult Function() refund, required TResult Function() refund,
}) { }) {
return createWithPayment( return createWithPayment(
items, customerName, orderType, tableNumber, paymentMethod); items, customerName, orderType, table, paymentMethod);
} }
@override @override
@ -709,21 +667,17 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
TResult? Function()? refund, TResult? Function()? refund,
}) { }) {
return createWithPayment?.call( return createWithPayment?.call(
items, customerName, orderType, tableNumber, paymentMethod); items, customerName, orderType, table, paymentMethod);
} }
@override @override
@ -731,14 +685,10 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,
@ -747,7 +697,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
}) { }) {
if (createWithPayment != null) { if (createWithPayment != null) {
return createWithPayment( return createWithPayment(
items, customerName, orderType, tableNumber, paymentMethod); items, customerName, orderType, table, paymentMethod);
} }
return orElse(); return orElse();
} }
@ -801,14 +751,14 @@ abstract class _CreateWithPaymentMethod implements OrderFormEvent {
{required final List<ProductQuantity> items, {required final List<ProductQuantity> items,
required final String customerName, required final String customerName,
required final OrderType orderType, required final OrderType orderType,
required final String tableNumber, required final TableModel table,
required final PaymentMethod paymentMethod}) = required final PaymentMethod paymentMethod}) =
_$CreateWithPaymentMethodImpl; _$CreateWithPaymentMethodImpl;
List<ProductQuantity> get items; List<ProductQuantity> get items;
String get customerName; String get customerName;
OrderType get orderType; OrderType get orderType;
String get tableNumber; TableModel get table;
PaymentMethod get paymentMethod; PaymentMethod get paymentMethod;
/// Create a copy of OrderFormEvent /// Create a copy of OrderFormEvent
@ -888,14 +838,10 @@ class _$ToggleItemImpl implements _ToggleItem {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
@ -909,14 +855,10 @@ class _$ToggleItemImpl implements _ToggleItem {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
@ -930,14 +872,10 @@ class _$ToggleItemImpl implements _ToggleItem {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,
@ -1078,14 +1016,10 @@ class _$ToggleSelectAllImpl implements _ToggleSelectAll {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
@ -1099,14 +1033,10 @@ class _$ToggleSelectAllImpl implements _ToggleSelectAll {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
@ -1120,14 +1050,10 @@ class _$ToggleSelectAllImpl implements _ToggleSelectAll {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,
@ -1239,14 +1165,10 @@ class _$RefundImpl implements _Refund {
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function(Order order) started, required TResult Function(Order order) started,
required TResult Function(List<ProductQuantity> items, String customerName, required TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber) OrderType orderType, TableModel table)
create, create,
required TResult Function( required TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)
createWithPayment, createWithPayment,
required TResult Function(OrderItem item) toggleItem, required TResult Function(OrderItem item) toggleItem,
required TResult Function(bool selectAll) toggleSelectAll, required TResult Function(bool selectAll) toggleSelectAll,
@ -1260,14 +1182,10 @@ class _$RefundImpl implements _Refund {
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Order order)? started, TResult? Function(Order order)? started,
TResult? Function(List<ProductQuantity> items, String customerName, TResult? Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult? Function( TResult? Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult? Function(OrderItem item)? toggleItem, TResult? Function(OrderItem item)? toggleItem,
TResult? Function(bool selectAll)? toggleSelectAll, TResult? Function(bool selectAll)? toggleSelectAll,
@ -1281,14 +1199,10 @@ class _$RefundImpl implements _Refund {
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function(Order order)? started, TResult Function(Order order)? started,
TResult Function(List<ProductQuantity> items, String customerName, TResult Function(List<ProductQuantity> items, String customerName,
OrderType orderType, String tableNumber)? OrderType orderType, TableModel table)?
create, create,
TResult Function( TResult Function(List<ProductQuantity> items, String customerName,
List<ProductQuantity> items, OrderType orderType, TableModel table, PaymentMethod paymentMethod)?
String customerName,
OrderType orderType,
String tableNumber,
PaymentMethod paymentMethod)?
createWithPayment, createWithPayment,
TResult Function(OrderItem item)? toggleItem, TResult Function(OrderItem item)? toggleItem,
TResult Function(bool selectAll)? toggleSelectAll, TResult Function(bool selectAll)? toggleSelectAll,

View File

@ -7,13 +7,13 @@ class OrderFormEvent with _$OrderFormEvent {
required List<ProductQuantity> items, required List<ProductQuantity> items,
required String customerName, required String customerName,
required OrderType orderType, required OrderType orderType,
required String tableNumber, required TableModel table,
}) = _Create; }) = _Create;
const factory OrderFormEvent.createWithPayment({ const factory OrderFormEvent.createWithPayment({
required List<ProductQuantity> items, required List<ProductQuantity> items,
required String customerName, required String customerName,
required OrderType orderType, required OrderType orderType,
required String tableNumber, required TableModel table,
required PaymentMethod paymentMethod, required PaymentMethod paymentMethod,
}) = _CreateWithPaymentMethod; }) = _CreateWithPaymentMethod;
const factory OrderFormEvent.toggleItem(OrderItem item) = _ToggleItem; const factory OrderFormEvent.toggleItem(OrderItem item) = _ToggleItem;

View File

@ -35,6 +35,9 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
context
.read<GetTableStatusBloc>()
.add(GetTableStatusEvent.getTablesStatus('available'));
if (widget.selectedTable != null) { if (widget.selectedTable != null) {
selectTable = widget.selectedTable; selectTable = widget.selectedTable;
} }
@ -67,7 +70,10 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
BlocBuilder<GetTableStatusBloc, GetTableStatusState>( BlocBuilder<GetTableStatusBloc, GetTableStatusState>(
builder: (context, state) { builder: (context, state) {
return state.maybeWhen( return state.maybeWhen(
orElse: () => const CircularProgressIndicator(), orElse: () =>
Center(child: const CircularProgressIndicator()),
loading: () =>
Center(child: const CircularProgressIndicator()),
success: (tables) { success: (tables) {
final availableTables = tables; final availableTables = tables;
@ -106,7 +112,10 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
child: DropdownButtonHideUnderline( child: DropdownButtonHideUnderline(
child: DropdownButton<TableModel>( child: DropdownButton<TableModel>(
isExpanded: true, isExpanded: true,
value: selectTable, value: availableTables.firstWhere(
(t) => t.id == selectTable?.id,
orElse: () => availableTables.first,
),
onChanged: (TableModel? newValue) { onChanged: (TableModel? newValue) {
setState(() { setState(() {
selectTable = newValue; selectTable = newValue;
@ -117,7 +126,7 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
(TableModel value) => (TableModel value) =>
DropdownMenuItem<TableModel>( DropdownMenuItem<TableModel>(
value: value, value: value,
child: Text(value.tableName), child: Text(value.tableName ?? ""),
), ),
) )
.toList(), .toList(),
@ -152,7 +161,7 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
items: widget.items, items: widget.items,
customerName: widget.customerName, customerName: widget.customerName,
orderType: widget.orderType, orderType: widget.orderType,
tableNumber: selectTable!.tableName.toString(), table: selectTable!,
), ),
); );
}, },

View File

@ -4,6 +4,7 @@ class OrderRequestModel {
final String? outletId; final String? outletId;
final String? userId; final String? userId;
final String? tableNumber; final String? tableNumber;
final String? tableId;
final String? orderType; final String? orderType;
final String? notes; final String? notes;
final List<OrderItemRequest>? orderItems; final List<OrderItemRequest>? orderItems;
@ -13,6 +14,7 @@ class OrderRequestModel {
this.outletId, this.outletId,
this.userId, this.userId,
this.tableNumber, this.tableNumber,
this.tableId,
this.orderType, this.orderType,
this.notes, this.notes,
this.orderItems, this.orderItems,
@ -29,6 +31,7 @@ class OrderRequestModel {
outletId: json["outlet_id"], outletId: json["outlet_id"],
userId: json["user_id"], userId: json["user_id"],
tableNumber: json["table_number"], tableNumber: json["table_number"],
tableId: json["table_id"],
orderType: json["order_type"], orderType: json["order_type"],
notes: json["notes"], notes: json["notes"],
orderItems: json["order_items"] == null orderItems: json["order_items"] == null
@ -42,6 +45,7 @@ class OrderRequestModel {
"outlet_id": outletId, "outlet_id": outletId,
"user_id": userId, "user_id": userId,
"table_number": tableNumber, "table_number": tableNumber,
"table_id": tableId,
"order_type": orderType, "order_type": orderType,
"notes": notes, "notes": notes,
"order_items": orderItems == null "order_items": orderItems == null

View File

@ -829,7 +829,8 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
DropdownMenuItem< DropdownMenuItem<
TableModel>( TableModel>(
value: value, value: value,
child: Text(value.tableName), child: Text(
value.tableName ?? ""),
), ),
) )
.toList(), .toList(),
@ -1192,28 +1193,28 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
savedDraftOrder: (orderDraftId) { savedDraftOrder: (orderDraftId) {
log("PRICEVALUE: ${priceValue}"); log("PRICEVALUE: ${priceValue}");
final newTabel = TableModel( // final newTabel = TableModel(
id: widget.isTable // id: widget.isTable
? widget.table!.id // ? widget.table!.id
: selectTable?.id, // : selectTable?.id,
tableName: widget.isTable // tableName: widget.isTable
? widget.table!.tableName // ? widget.table!.tableName
: selectTable?.tableName ?? // : selectTable?.tableName ??
'0', // '0',
status: 'occupied', // status: 'occupied',
paymentAmount: priceValue, // paymentAmount: priceValue,
orderId: orderDraftId, // orderId: orderDraftId,
startTime: DateTime.now() // startTime: DateTime.now()
.toIso8601String(), // .toIso8601String(),
position: widget.isTable // position: widget.isTable
? widget.table!.position // ? widget.table!.position
: selectTable!.position); // : selectTable!.position);
log('new tabel: ${newTabel.toMap()}'); // log('new tabel: ${newTabel.toMap()}');
context // context
.read<StatusTableBloc>() // .read<StatusTableBloc>()
.add(StatusTableEvent.statusTabel( // .add(StatusTableEvent.statusTabel(
newTabel, // newTabel,
)); // ));
}); });
}, },
child: child:
@ -1357,16 +1358,16 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
if (widget.isTable) { if (widget.isTable) {
log("discountAmountValue: $totalDiscount"); log("discountAmountValue: $totalDiscount");
context.read<CheckoutBloc>().add( // context.read<CheckoutBloc>().add(
CheckoutEvent // CheckoutEvent
.saveDraftOrder( // .saveDraftOrder(
widget.isTable == true // widget.isTable == true
? widget.table!.id! // ? widget.table!.id!
: selectTable!.id!, // : selectTable!.id!,
customerController.text, // customerController.text,
totalDiscount.toInt(), // totalDiscount.toInt(),
), // ),
); // );
await showDialog( await showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@ -1515,120 +1516,120 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
// Tambahkan ke pesanan meja yang sudah ada // Tambahkan ke pesanan meja yang sudah ada
if (selectTable != null) { if (selectTable != null) {
// Ambil draft order yang sudah ada // Ambil draft order yang sudah ada
final existingDraftOrder = // final existingDraftOrder =
await ProductLocalDatasource // await ProductLocalDatasource
.instance // .instance
.getDraftOrderById( // .getDraftOrderById(
selectTable // selectTable
?.orderId ?? // ?.orderId ??
0); // 0);
if (existingDraftOrder != // if (existingDraftOrder !=
null) { // null) {
// Convert items ke DraftOrderItem // // Convert items ke DraftOrderItem
final newDraftItems = items // final newDraftItems = items
.map((item) => // .map((item) =>
DraftOrderItem( // DraftOrderItem(
product: // product:
item.product, // item.product,
quantity: // quantity:
item.quantity, // item.quantity,
)) // ))
.toList(); // .toList();
// Gabungkan dengan pesanan yang sudah ada // // Gabungkan dengan pesanan yang sudah ada
final updatedItems = [ // final updatedItems = [
...existingDraftOrder // ...existingDraftOrder
.orders, // .orders,
...newDraftItems // ...newDraftItems
]; // ];
final updatedDraftOrder = // final updatedDraftOrder =
existingDraftOrder // existingDraftOrder
.copyWith( // .copyWith(
orders: updatedItems, // orders: updatedItems,
totalQuantity: // totalQuantity:
updatedItems.fold<int>( // updatedItems.fold<int>(
0, // 0,
(sum, item) => // (sum, item) =>
sum + // sum +
item.quantity), // item.quantity),
subTotal: updatedItems.fold< // subTotal: updatedItems.fold<
int>( // int>(
0, // 0,
(sum, item) => // (sum, item) =>
sum + // sum +
(item.product // (item.product
.price ?? // .price ??
0) * // 0) *
item.quantity), // item.quantity),
); // );
// Update draft order // // Update draft order
await ProductLocalDatasource // await ProductLocalDatasource
.instance // .instance
.updateDraftOrder( // .updateDraftOrder(
updatedDraftOrder); // updatedDraftOrder);
// Tampilkan dialog sukses // // Tampilkan dialog sukses
await showDialog( // await showDialog(
context: context, // context: context,
barrierDismissible: false, // barrierDismissible: false,
builder: (context) => // builder: (context) =>
SaveOrderDialog( // SaveOrderDialog(
data: items, // data: items,
totalQty: totalQty, // totalQty: totalQty,
totalPrice: // totalPrice:
totalPriceFinal, // totalPriceFinal,
totalTax: // totalTax:
finalTax.toInt(), // finalTax.toInt(),
totalDiscount: // totalDiscount:
totalDiscount.toInt(), // totalDiscount.toInt(),
subTotal: // subTotal:
subTotal.toInt(), // subTotal.toInt(),
normalPrice: price, // normalPrice: price,
table: selectTable!, // table: selectTable!,
draftName: // draftName:
customerController // customerController
.text, // .text,
), // ),
); // );
} else { // } else {
// Jika tidak ada draft order, buat baru // // Jika tidak ada draft order, buat baru
context // context
.read<CheckoutBloc>() // .read<CheckoutBloc>()
.add( // .add(
CheckoutEvent // CheckoutEvent
.saveDraftOrder( // .saveDraftOrder(
selectTable!.id!, // selectTable!.id!,
customerController // customerController
.text, // .text,
totalDiscount.toInt(), // totalDiscount.toInt(),
), // ),
); // );
await showDialog( // await showDialog(
context: context, // context: context,
barrierDismissible: false, // barrierDismissible: false,
builder: (context) => // builder: (context) =>
SaveOrderDialog( // SaveOrderDialog(
data: items, // data: items,
totalQty: totalQty, // totalQty: totalQty,
totalPrice: // totalPrice:
totalPriceFinal, // totalPriceFinal,
totalTax: // totalTax:
finalTax.toInt(), // finalTax.toInt(),
totalDiscount: // totalDiscount:
totalDiscount.toInt(), // totalDiscount.toInt(),
subTotal: // subTotal:
subTotal.toInt(), // subTotal.toInt(),
normalPrice: price, // normalPrice: price,
table: selectTable!, // table: selectTable!,
draftName: // draftName:
customerController // customerController
.text, // .text,
), // ),
); // );
} // }
} else { } else {
ScaffoldMessenger.of(context) ScaffoldMessenger.of(context)
.showSnackBar( .showSnackBar(
@ -1640,16 +1641,16 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
); );
} }
} else { } else {
context.read<CheckoutBloc>().add( // context.read<CheckoutBloc>().add(
CheckoutEvent // CheckoutEvent
.saveDraftOrder( // .saveDraftOrder(
widget.isTable == true // widget.isTable == true
? widget.table!.id! // ? widget.table!.id!
: selectTable!.id!, // : selectTable!.id!,
customerController.text, // customerController.text,
totalDiscount.toInt(), // totalDiscount.toInt(),
), // ),
); // );
await showDialog( await showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,

View File

@ -16,7 +16,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/core/extensions/int_ext.dart'; import 'package:enaklo_pos/core/extensions/int_ext.dart';
import 'package:enaklo_pos/core/extensions/string_ext.dart'; import 'package:enaklo_pos/core/extensions/string_ext.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart'; import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/home/bloc/get_table_status/get_table_status_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/payment_methods/payment_methods_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/payment_methods/payment_methods_bloc.dart';
import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart'; import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart';
@ -62,9 +61,7 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
@override @override
void initState() { void initState() {
// Fetch available tables by default // Fetch available tables by default
context
.read<GetTableStatusBloc>()
.add(GetTableStatusEvent.getTablesStatus('available'));
context context
.read<PaymentMethodsBloc>() .read<PaymentMethodsBloc>()
.add(PaymentMethodsEvent.fetchPaymentMethods()); .add(PaymentMethodsEvent.fetchPaymentMethods());
@ -928,9 +925,7 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
customerController customerController
.text, .text,
orderType: orderType, orderType: orderType,
tableNumber: widget.table table: widget.table!,
?.tableName ??
'',
), ),
); );
}, },

View File

@ -134,7 +134,7 @@ class HomeRightTitle extends StatelessWidget {
}, },
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
label: table == null ? 'Pilih Meja' : '${table!.id}', label: table == null ? 'Pilih Meja' : '${table!.tableName}',
), ),
), ),
], ],

View File

@ -97,98 +97,108 @@ class _SaveOrderDialogState extends State<SaveOrderDialog> {
builder: (context, state) { builder: (context, state) {
final orderType = state.maybeWhen( final orderType = state.maybeWhen(
orElse: () => OrderType.dineIn, orElse: () => OrderType.dineIn,
loaded: (items, discountModel, discount, discountAmount, tax, serviceCharge, totalQuantity, totalPrice, draftName, orderType) => orderType, loaded: (items,
discountModel,
discount,
discountAmount,
tax,
serviceCharge,
totalQuantity,
totalPrice,
draftName,
orderType) =>
orderType,
); );
return Button.filled( return Button.filled(
onPressed: () async { onPressed: () async {
final checkerPrinter = await ProductLocalDatasource final checkerPrinter = await ProductLocalDatasource
.instance .instance
.getPrinterByCode('checker'); .getPrinterByCode('checker');
final kitchenPrinter = await ProductLocalDatasource final kitchenPrinter = await ProductLocalDatasource
.instance .instance
.getPrinterByCode('kitchen'); .getPrinterByCode('kitchen');
final barPrinter = await ProductLocalDatasource.instance final barPrinter = await ProductLocalDatasource
.getPrinterByCode('bar'); .instance
.getPrinterByCode('bar');
log("Checker printer: ${checkerPrinter?.toMap()}");
log("Kitchen printer: ${kitchenPrinter?.toMap()}");
log("Bar printer: ${barPrinter?.toMap()}");
// Checker printer
if (checkerPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance
.printChecker(
widget.data,
widget.table.tableName,
widget.draftName,
'kasir',
checkerPrinter.paper.toIntegerFromText,
orderType.value);
await PrinterService().printWithPrinter(
checkerPrinter,
printValue,
context
);
} catch (e) {
log("Error printing checker: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing checker: $e')),
);
}
}
// Kitchen printer log("Checker printer: ${checkerPrinter?.toMap()}");
if (kitchenPrinter != null) { log("Kitchen printer: ${kitchenPrinter?.toMap()}");
try { log("Bar printer: ${barPrinter?.toMap()}");
final printValue = await PrintDataoutputs.instance.printKitchen(
widget.data,
widget.table.tableName,
widget.draftName,
'kasir',
kitchenPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
kitchenPrinter,
printValue,
context
);
} catch (e) {
log("Error printing kitchen order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing kitchen order: $e')),
);
}
}
// Bar printer // Checker printer
if (barPrinter != null) { if (checkerPrinter != null) {
try { try {
final printValue = await PrintDataoutputs.instance.printBar( final printValue = await PrintDataoutputs.instance
widget.data, .printChecker(
widget.table.tableName, widget.data,
widget.draftName, widget.table.tableName!,
'kasir', widget.draftName,
barPrinter.paper.toIntegerFromText, 'kasir',
orderType.value, checkerPrinter.paper.toIntegerFromText,
); orderType.value);
await PrinterService().printWithPrinter( await PrinterService().printWithPrinter(
barPrinter, checkerPrinter, printValue, context);
printValue, } catch (e) {
context log("Error printing checker: $e");
); ScaffoldMessenger.of(context).showSnackBar(
} catch (e) { SnackBar(
log("Error printing bar order: $e"); content:
ScaffoldMessenger.of(context).showSnackBar( Text('Error printing checker: $e')),
SnackBar(content: Text('Error printing bar order: $e')), );
); }
} }
}
// Kitchen printer
if (kitchenPrinter != null) {
try {
final printValue =
await PrintDataoutputs.instance.printKitchen(
widget.data,
widget.table.tableName!,
widget.draftName,
'kasir',
kitchenPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
kitchenPrinter, printValue, context);
} catch (e) {
log("Error printing kitchen order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Error printing kitchen order: $e')),
);
}
}
// Bar printer
if (barPrinter != null) {
try {
final printValue =
await PrintDataoutputs.instance.printBar(
widget.data,
widget.table.tableName!,
widget.draftName,
'kasir',
barPrinter.paper.toIntegerFromText,
orderType.value,
);
await PrinterService().printWithPrinter(
barPrinter, printValue, context);
} catch (e) {
log("Error printing bar order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content:
Text('Error printing bar order: $e')),
);
}
}
}, },
label: 'Print Checker', label: 'Print Checker',
); );

View File

@ -152,8 +152,7 @@ class SuccessSaveOrderPage extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: Button.outlined( child: Button.outlined(
onPressed: () => onPressed: () => context.push(DashboardPage()),
context.pushReplacement(DashboardPage()),
label: 'Kembali', label: 'Kembali',
height: 44, height: 44,
), ),

View File

@ -1,7 +1,7 @@
import 'dart:ui'; import 'dart:ui';
import 'package:bloc/bloc.dart'; 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'; import 'package:freezed_annotation/freezed_annotation.dart';
part 'change_position_table_event.dart'; part 'change_position_table_event.dart';
@ -10,11 +10,19 @@ part 'change_position_table_bloc.freezed.dart';
class ChangePositionTableBloc class ChangePositionTableBloc
extends Bloc<ChangePositionTableEvent, ChangePositionTableState> { extends Bloc<ChangePositionTableEvent, ChangePositionTableState> {
ChangePositionTableBloc() : super(_Initial()) { final TableRemoteDataSource _tableRemoteDataSource;
ChangePositionTableBloc(this._tableRemoteDataSource)
: super(ChangePositionTableState.initial()) {
on<_ChangePositionTable>((event, emit) async { on<_ChangePositionTable>((event, emit) async {
emit(_Loading()); emit(_Loading());
await ProductLocalDatasource.instance final result = await _tableRemoteDataSource.updatePosition(
.changePositionTable(event.tableId, event.position); tableId: event.tableId,
position: event.position,
);
result.fold(
(l) => emit(_Error(l)),
(r) => emit(_Success('Generate Success')),
);
emit(_Success('Generate Success')); emit(_Success('Generate Success'));
}); });
} }

View File

@ -19,19 +19,20 @@ mixin _$ChangePositionTableEvent {
@optionalTypeArgs @optionalTypeArgs
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function() started, required TResult Function() started,
required TResult Function(int tableId, Offset position) changePositionTable, required TResult Function(String tableId, Offset position)
changePositionTable,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started, TResult? Function()? started,
TResult? Function(int tableId, Offset position)? changePositionTable, TResult? Function(String tableId, Offset position)? changePositionTable,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function()? started, TResult Function()? started,
TResult Function(int tableId, Offset position)? changePositionTable, TResult Function(String tableId, Offset position)? changePositionTable,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -120,7 +121,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs @optionalTypeArgs
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function() started, required TResult Function() started,
required TResult Function(int tableId, Offset position) changePositionTable, required TResult Function(String tableId, Offset position)
changePositionTable,
}) { }) {
return started(); return started();
} }
@ -129,7 +131,7 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started, TResult? Function()? started,
TResult? Function(int tableId, Offset position)? changePositionTable, TResult? Function(String tableId, Offset position)? changePositionTable,
}) { }) {
return started?.call(); return started?.call();
} }
@ -138,7 +140,7 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function()? started, TResult Function()? started,
TResult Function(int tableId, Offset position)? changePositionTable, TResult Function(String tableId, Offset position)? changePositionTable,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (started != null) { if (started != null) {
@ -189,7 +191,7 @@ abstract class _$$ChangePositionTableImplCopyWith<$Res> {
$Res Function(_$ChangePositionTableImpl) then) = $Res Function(_$ChangePositionTableImpl) then) =
__$$ChangePositionTableImplCopyWithImpl<$Res>; __$$ChangePositionTableImplCopyWithImpl<$Res>;
@useResult @useResult
$Res call({int tableId, Offset position}); $Res call({String tableId, Offset position});
} }
/// @nodoc /// @nodoc
@ -213,7 +215,7 @@ class __$$ChangePositionTableImplCopyWithImpl<$Res>
tableId: null == tableId tableId: null == tableId
? _value.tableId ? _value.tableId
: tableId // ignore: cast_nullable_to_non_nullable : tableId // ignore: cast_nullable_to_non_nullable
as int, as String,
position: null == position position: null == position
? _value.position ? _value.position
: position // ignore: cast_nullable_to_non_nullable : position // ignore: cast_nullable_to_non_nullable
@ -229,7 +231,7 @@ class _$ChangePositionTableImpl implements _ChangePositionTable {
{required this.tableId, required this.position}); {required this.tableId, required this.position});
@override @override
final int tableId; final String tableId;
@override @override
final Offset position; final Offset position;
@ -264,7 +266,8 @@ class _$ChangePositionTableImpl implements _ChangePositionTable {
@optionalTypeArgs @optionalTypeArgs
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function() started, required TResult Function() started,
required TResult Function(int tableId, Offset position) changePositionTable, required TResult Function(String tableId, Offset position)
changePositionTable,
}) { }) {
return changePositionTable(tableId, position); return changePositionTable(tableId, position);
} }
@ -273,7 +276,7 @@ class _$ChangePositionTableImpl implements _ChangePositionTable {
@optionalTypeArgs @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started, TResult? Function()? started,
TResult? Function(int tableId, Offset position)? changePositionTable, TResult? Function(String tableId, Offset position)? changePositionTable,
}) { }) {
return changePositionTable?.call(tableId, position); return changePositionTable?.call(tableId, position);
} }
@ -282,7 +285,7 @@ class _$ChangePositionTableImpl implements _ChangePositionTable {
@optionalTypeArgs @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function()? started, TResult Function()? started,
TResult Function(int tableId, Offset position)? changePositionTable, TResult Function(String tableId, Offset position)? changePositionTable,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (changePositionTable != null) { if (changePositionTable != null) {
@ -325,10 +328,10 @@ class _$ChangePositionTableImpl implements _ChangePositionTable {
abstract class _ChangePositionTable implements ChangePositionTableEvent { abstract class _ChangePositionTable implements ChangePositionTableEvent {
const factory _ChangePositionTable( const factory _ChangePositionTable(
{required final int tableId, {required final String tableId,
required final Offset position}) = _$ChangePositionTableImpl; required final Offset position}) = _$ChangePositionTableImpl;
int get tableId; String get tableId;
Offset get position; Offset get position;
/// Create a copy of ChangePositionTableEvent /// Create a copy of ChangePositionTableEvent
@ -345,6 +348,7 @@ mixin _$ChangePositionTableState {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -352,6 +356,7 @@ mixin _$ChangePositionTableState {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -359,6 +364,7 @@ mixin _$ChangePositionTableState {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -367,6 +373,7 @@ mixin _$ChangePositionTableState {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -374,6 +381,7 @@ mixin _$ChangePositionTableState {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -381,6 +389,7 @@ mixin _$ChangePositionTableState {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -452,6 +461,7 @@ class _$InitialImpl implements _Initial {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) { }) {
return initial(); return initial();
} }
@ -462,6 +472,7 @@ class _$InitialImpl implements _Initial {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) { }) {
return initial?.call(); return initial?.call();
} }
@ -472,6 +483,7 @@ class _$InitialImpl implements _Initial {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -486,6 +498,7 @@ class _$InitialImpl implements _Initial {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return initial(this); return initial(this);
} }
@ -496,6 +509,7 @@ class _$InitialImpl implements _Initial {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return initial?.call(this); return initial?.call(this);
} }
@ -506,6 +520,7 @@ class _$InitialImpl implements _Initial {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -563,6 +578,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) { }) {
return loading(); return loading();
} }
@ -573,6 +589,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) { }) {
return loading?.call(); return loading?.call();
} }
@ -583,6 +600,7 @@ class _$LoadingImpl implements _Loading {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -597,6 +615,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return loading(this); return loading(this);
} }
@ -607,6 +626,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return loading?.call(this); return loading?.call(this);
} }
@ -617,6 +637,7 @@ class _$LoadingImpl implements _Loading {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -701,6 +722,7 @@ class _$SuccessImpl implements _Success {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) { }) {
return success(message); return success(message);
} }
@ -711,6 +733,7 @@ class _$SuccessImpl implements _Success {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) { }) {
return success?.call(message); return success?.call(message);
} }
@ -721,6 +744,7 @@ class _$SuccessImpl implements _Success {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -735,6 +759,7 @@ class _$SuccessImpl implements _Success {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return success(this); return success(this);
} }
@ -745,6 +770,7 @@ class _$SuccessImpl implements _Success {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return success?.call(this); return success?.call(this);
} }
@ -755,6 +781,7 @@ class _$SuccessImpl implements _Success {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -775,3 +802,155 @@ abstract class _Success implements ChangePositionTableState {
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError; 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 _$ChangePositionTableStateCopyWithImpl<$Res, _$ErrorImpl>
implements _$$ErrorImplCopyWith<$Res> {
__$$ErrorImplCopyWithImpl(
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
: super(_value, _then);
/// Create a copy of ChangePositionTableState
/// 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 'ChangePositionTableState.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 ChangePositionTableState
/// 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 ChangePositionTableState {
const factory _Error(final String message) = _$ErrorImpl;
String get message;
/// Create a copy of ChangePositionTableState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -4,7 +4,7 @@ part of 'change_position_table_bloc.dart';
class ChangePositionTableEvent with _$ChangePositionTableEvent { class ChangePositionTableEvent with _$ChangePositionTableEvent {
const factory ChangePositionTableEvent.started() = _Started; const factory ChangePositionTableEvent.started() = _Started;
const factory ChangePositionTableEvent.changePositionTable({ const factory ChangePositionTableEvent.changePositionTable({
required int tableId, required String tableId,
required Offset position, required Offset position,
}) = _ChangePositionTable; }) = _ChangePositionTable;
} }

View File

@ -7,4 +7,5 @@ class ChangePositionTableState with _$ChangePositionTableState {
const factory ChangePositionTableState.loading() = _Loading; const factory ChangePositionTableState.loading() = _Loading;
const factory ChangePositionTableState.success(String message) = _Success; const factory ChangePositionTableState.success(String message) = _Success;
const factory ChangePositionTableState.error(String message) = _Error;
} }

View File

@ -1,7 +1,5 @@
import 'dart:ui';
import 'package:bloc/bloc.dart'; 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'; import 'package:freezed_annotation/freezed_annotation.dart';
part 'create_table_event.dart'; part 'create_table_event.dart';
@ -9,12 +7,19 @@ part 'create_table_state.dart';
part 'create_table_bloc.freezed.dart'; part 'create_table_bloc.freezed.dart';
class CreateTableBloc extends Bloc<CreateTableEvent, CreateTableState> { class CreateTableBloc extends Bloc<CreateTableEvent, CreateTableState> {
CreateTableBloc() : super(_Initial()) { final TableRemoteDataSource _tableRemoteDataSource;
CreateTableBloc(this._tableRemoteDataSource)
: super(CreateTableState.initial()) {
on<_CreateTable>((event, emit) async { on<_CreateTable>((event, emit) async {
emit(_Loading()); emit(_Loading());
await ProductLocalDatasource.instance final result = await _tableRemoteDataSource.createTable(
.createTableManagement(event.tableName, event.position); tableName: event.tableName,
emit(_Success('Create Table Success')); capacity: event.capacity,
location: event.location,
);
result.fold((l) => emit(_Error(l)),
(r) => emit(_Success('Meja berhasil dibuat')));
}); });
} }
} }

View File

@ -19,19 +19,22 @@ mixin _$CreateTableEvent {
@optionalTypeArgs @optionalTypeArgs
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function() started, required TResult Function() started,
required TResult Function(String tableName, Offset position) createTable, required TResult Function(String tableName, int capacity, String location)
createTable,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started, TResult? Function()? started,
TResult? Function(String tableName, Offset position)? createTable, TResult? Function(String tableName, int capacity, String location)?
createTable,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function()? started, TResult Function()? started,
TResult Function(String tableName, Offset position)? createTable, TResult Function(String tableName, int capacity, String location)?
createTable,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -119,7 +122,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs @optionalTypeArgs
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function() started, required TResult Function() started,
required TResult Function(String tableName, Offset position) createTable, required TResult Function(String tableName, int capacity, String location)
createTable,
}) { }) {
return started(); return started();
} }
@ -128,7 +132,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started, TResult? Function()? started,
TResult? Function(String tableName, Offset position)? createTable, TResult? Function(String tableName, int capacity, String location)?
createTable,
}) { }) {
return started?.call(); return started?.call();
} }
@ -137,7 +142,8 @@ class _$StartedImpl implements _Started {
@optionalTypeArgs @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function()? started, TResult Function()? started,
TResult Function(String tableName, Offset position)? createTable, TResult Function(String tableName, int capacity, String location)?
createTable,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (started != null) { if (started != null) {
@ -188,7 +194,7 @@ abstract class _$$CreateTableImplCopyWith<$Res> {
_$CreateTableImpl value, $Res Function(_$CreateTableImpl) then) = _$CreateTableImpl value, $Res Function(_$CreateTableImpl) then) =
__$$CreateTableImplCopyWithImpl<$Res>; __$$CreateTableImplCopyWithImpl<$Res>;
@useResult @useResult
$Res call({String tableName, Offset position}); $Res call({String tableName, int capacity, String location});
} }
/// @nodoc /// @nodoc
@ -205,17 +211,22 @@ class __$$CreateTableImplCopyWithImpl<$Res>
@override @override
$Res call({ $Res call({
Object? tableName = null, Object? tableName = null,
Object? position = null, Object? capacity = null,
Object? location = null,
}) { }) {
return _then(_$CreateTableImpl( return _then(_$CreateTableImpl(
null == tableName tableName: null == tableName
? _value.tableName ? _value.tableName
: tableName // ignore: cast_nullable_to_non_nullable : tableName // ignore: cast_nullable_to_non_nullable
as String, as String,
null == position capacity: null == capacity
? _value.position ? _value.capacity
: position // ignore: cast_nullable_to_non_nullable : capacity // ignore: cast_nullable_to_non_nullable
as Offset, as int,
location: null == location
? _value.location
: location // ignore: cast_nullable_to_non_nullable
as String,
)); ));
} }
} }
@ -223,16 +234,21 @@ class __$$CreateTableImplCopyWithImpl<$Res>
/// @nodoc /// @nodoc
class _$CreateTableImpl implements _CreateTable { class _$CreateTableImpl implements _CreateTable {
const _$CreateTableImpl(this.tableName, this.position); const _$CreateTableImpl(
{required this.tableName,
required this.capacity,
required this.location});
@override @override
final String tableName; final String tableName;
@override @override
final Offset position; final int capacity;
@override
final String location;
@override @override
String toString() { String toString() {
return 'CreateTableEvent.createTable(tableName: $tableName, position: $position)'; return 'CreateTableEvent.createTable(tableName: $tableName, capacity: $capacity, location: $location)';
} }
@override @override
@ -242,12 +258,14 @@ class _$CreateTableImpl implements _CreateTable {
other is _$CreateTableImpl && other is _$CreateTableImpl &&
(identical(other.tableName, tableName) || (identical(other.tableName, tableName) ||
other.tableName == tableName) && other.tableName == tableName) &&
(identical(other.position, position) || (identical(other.capacity, capacity) ||
other.position == position)); other.capacity == capacity) &&
(identical(other.location, location) ||
other.location == location));
} }
@override @override
int get hashCode => Object.hash(runtimeType, tableName, position); int get hashCode => Object.hash(runtimeType, tableName, capacity, location);
/// Create a copy of CreateTableEvent /// Create a copy of CreateTableEvent
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -261,29 +279,32 @@ class _$CreateTableImpl implements _CreateTable {
@optionalTypeArgs @optionalTypeArgs
TResult when<TResult extends Object?>({ TResult when<TResult extends Object?>({
required TResult Function() started, 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 @override
@optionalTypeArgs @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({ TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? started, 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 @override
@optionalTypeArgs @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({ TResult maybeWhen<TResult extends Object?>({
TResult Function()? started, TResult Function()? started,
TResult Function(String tableName, Offset position)? createTable, TResult Function(String tableName, int capacity, String location)?
createTable,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (createTable != null) { if (createTable != null) {
return createTable(tableName, position); return createTable(tableName, capacity, location);
} }
return orElse(); return orElse();
} }
@ -321,11 +342,14 @@ class _$CreateTableImpl implements _CreateTable {
} }
abstract class _CreateTable implements CreateTableEvent { abstract class _CreateTable implements CreateTableEvent {
const factory _CreateTable(final String tableName, final Offset position) = const factory _CreateTable(
_$CreateTableImpl; {required final String tableName,
required final int capacity,
required final String location}) = _$CreateTableImpl;
String get tableName; String get tableName;
Offset get position; int get capacity;
String get location;
/// Create a copy of CreateTableEvent /// Create a copy of CreateTableEvent
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -341,6 +365,7 @@ mixin _$CreateTableState {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -348,6 +373,7 @@ mixin _$CreateTableState {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -355,6 +381,7 @@ mixin _$CreateTableState {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -363,6 +390,7 @@ mixin _$CreateTableState {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -370,6 +398,7 @@ mixin _$CreateTableState {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -377,6 +406,7 @@ mixin _$CreateTableState {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -447,6 +477,7 @@ class _$InitialImpl implements _Initial {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) { }) {
return initial(); return initial();
} }
@ -457,6 +488,7 @@ class _$InitialImpl implements _Initial {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) { }) {
return initial?.call(); return initial?.call();
} }
@ -467,6 +499,7 @@ class _$InitialImpl implements _Initial {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -481,6 +514,7 @@ class _$InitialImpl implements _Initial {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return initial(this); return initial(this);
} }
@ -491,6 +525,7 @@ class _$InitialImpl implements _Initial {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return initial?.call(this); return initial?.call(this);
} }
@ -501,6 +536,7 @@ class _$InitialImpl implements _Initial {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -558,6 +594,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) { }) {
return loading(); return loading();
} }
@ -568,6 +605,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) { }) {
return loading?.call(); return loading?.call();
} }
@ -578,6 +616,7 @@ class _$LoadingImpl implements _Loading {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -592,6 +631,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return loading(this); return loading(this);
} }
@ -602,6 +642,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return loading?.call(this); return loading?.call(this);
} }
@ -612,6 +653,7 @@ class _$LoadingImpl implements _Loading {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -696,6 +738,7 @@ class _$SuccessImpl implements _Success {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(String message) success, required TResult Function(String message) success,
required TResult Function(String message) error,
}) { }) {
return success(message); return success(message);
} }
@ -706,6 +749,7 @@ class _$SuccessImpl implements _Success {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(String message)? success, TResult? Function(String message)? success,
TResult? Function(String message)? error,
}) { }) {
return success?.call(message); return success?.call(message);
} }
@ -716,6 +760,7 @@ class _$SuccessImpl implements _Success {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(String message)? success, TResult Function(String message)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -730,6 +775,7 @@ class _$SuccessImpl implements _Success {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return success(this); return success(this);
} }
@ -740,6 +786,7 @@ class _$SuccessImpl implements _Success {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return success?.call(this); return success?.call(this);
} }
@ -750,6 +797,7 @@ class _$SuccessImpl implements _Success {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -770,3 +818,155 @@ abstract class _Success implements CreateTableState {
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError; 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;
}

View File

@ -3,6 +3,9 @@ part of 'create_table_bloc.dart';
@freezed @freezed
class CreateTableEvent with _$CreateTableEvent { class CreateTableEvent with _$CreateTableEvent {
const factory CreateTableEvent.started() = _Started; const factory CreateTableEvent.started() = _Started;
const factory CreateTableEvent.createTable( const factory CreateTableEvent.createTable({
String tableName, Offset position) = _CreateTable; required String tableName,
required int capacity,
required String location,
}) = _CreateTable;
} }

View File

@ -7,4 +7,5 @@ class CreateTableState with _$CreateTableState {
const factory CreateTableState.loading() = _Loading; const factory CreateTableState.loading() = _Loading;
// success // success
const factory CreateTableState.success(String message) = _Success; const factory CreateTableState.success(String message) = _Success;
const factory CreateTableState.error(String message) = _Error;
} }

View File

@ -1,3 +1,4 @@
import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/table_model.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'; part 'get_table_bloc.freezed.dart';
class GetTableBloc extends Bloc<GetTableEvent, GetTableState> { class GetTableBloc extends Bloc<GetTableEvent, GetTableState> {
GetTableBloc() : super(_Initial()) { final TableRemoteDataSource _tableRemoteDataSource;
GetTableBloc(this._tableRemoteDataSource) : super(GetTableState.initial()) {
on<_GetTables>((event, emit) async { on<_GetTables>((event, emit) async {
emit(_Loading()); emit(_Loading());
final tables = await ProductLocalDatasource.instance.getAllTable(); final tables = await _tableRemoteDataSource.getTable();
emit(_Success(tables)); tables.fold(
(l) => emit(_Error(l)),
(r) => emit(
_Success(r.data!.tables!),
),
);
}); });
} }
} }

View File

@ -294,6 +294,7 @@ mixin _$GetTableState {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -301,6 +302,7 @@ mixin _$GetTableState {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -308,6 +310,7 @@ mixin _$GetTableState {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -316,6 +319,7 @@ mixin _$GetTableState {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -323,6 +327,7 @@ mixin _$GetTableState {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@optionalTypeArgs @optionalTypeArgs
@ -330,6 +335,7 @@ mixin _$GetTableState {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) => }) =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -400,6 +406,7 @@ class _$InitialImpl implements _Initial {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) { }) {
return initial(); return initial();
} }
@ -410,6 +417,7 @@ class _$InitialImpl implements _Initial {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) { }) {
return initial?.call(); return initial?.call();
} }
@ -420,6 +428,7 @@ class _$InitialImpl implements _Initial {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -434,6 +443,7 @@ class _$InitialImpl implements _Initial {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return initial(this); return initial(this);
} }
@ -444,6 +454,7 @@ class _$InitialImpl implements _Initial {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return initial?.call(this); return initial?.call(this);
} }
@ -454,6 +465,7 @@ class _$InitialImpl implements _Initial {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (initial != null) { if (initial != null) {
@ -511,6 +523,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) { }) {
return loading(); return loading();
} }
@ -521,6 +534,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) { }) {
return loading?.call(); return loading?.call();
} }
@ -531,6 +545,7 @@ class _$LoadingImpl implements _Loading {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -545,6 +560,7 @@ class _$LoadingImpl implements _Loading {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return loading(this); return loading(this);
} }
@ -555,6 +571,7 @@ class _$LoadingImpl implements _Loading {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return loading?.call(this); return loading?.call(this);
} }
@ -565,6 +582,7 @@ class _$LoadingImpl implements _Loading {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (loading != null) { if (loading != null) {
@ -655,6 +673,7 @@ class _$SuccessImpl implements _Success {
required TResult Function() initial, required TResult Function() initial,
required TResult Function() loading, required TResult Function() loading,
required TResult Function(List<TableModel> tables) success, required TResult Function(List<TableModel> tables) success,
required TResult Function(String message) error,
}) { }) {
return success(tables); return success(tables);
} }
@ -665,6 +684,7 @@ class _$SuccessImpl implements _Success {
TResult? Function()? initial, TResult? Function()? initial,
TResult? Function()? loading, TResult? Function()? loading,
TResult? Function(List<TableModel> tables)? success, TResult? Function(List<TableModel> tables)? success,
TResult? Function(String message)? error,
}) { }) {
return success?.call(tables); return success?.call(tables);
} }
@ -675,6 +695,7 @@ class _$SuccessImpl implements _Success {
TResult Function()? initial, TResult Function()? initial,
TResult Function()? loading, TResult Function()? loading,
TResult Function(List<TableModel> tables)? success, TResult Function(List<TableModel> tables)? success,
TResult Function(String message)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -689,6 +710,7 @@ class _$SuccessImpl implements _Success {
required TResult Function(_Initial value) initial, required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading, required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success, required TResult Function(_Success value) success,
required TResult Function(_Error value) error,
}) { }) {
return success(this); return success(this);
} }
@ -699,6 +721,7 @@ class _$SuccessImpl implements _Success {
TResult? Function(_Initial value)? initial, TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading, TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success, TResult? Function(_Success value)? success,
TResult? Function(_Error value)? error,
}) { }) {
return success?.call(this); return success?.call(this);
} }
@ -709,6 +732,7 @@ class _$SuccessImpl implements _Success {
TResult Function(_Initial value)? initial, TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading, TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success, TResult Function(_Success value)? success,
TResult Function(_Error value)? error,
required TResult orElse(), required TResult orElse(),
}) { }) {
if (success != null) { if (success != null) {
@ -729,3 +753,155 @@ abstract class _Success implements GetTableState {
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError; 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 _$GetTableStateCopyWithImpl<$Res, _$ErrorImpl>
implements _$$ErrorImplCopyWith<$Res> {
__$$ErrorImplCopyWithImpl(
_$ErrorImpl _value, $Res Function(_$ErrorImpl) _then)
: super(_value, _then);
/// Create a copy of GetTableState
/// 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 'GetTableState.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 GetTableState
/// 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(List<TableModel> tables) 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(List<TableModel> tables)? 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(List<TableModel> tables)? 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 GetTableState {
const factory _Error(final String message) = _$ErrorImpl;
String get message;
/// Create a copy of GetTableState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ErrorImplCopyWith<_$ErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@ -5,4 +5,5 @@ class GetTableState with _$GetTableState {
const factory GetTableState.initial() = _Initial; const factory GetTableState.initial() = _Initial;
const factory GetTableState.loading() = _Loading; const factory GetTableState.loading() = _Loading;
const factory GetTableState.success(List<TableModel> tables) = _Success; const factory GetTableState.success(List<TableModel> tables) = _Success;
const factory GetTableState.error(String message) = _Error;
} }

View File

@ -0,0 +1,86 @@
import 'package:enaklo_pos/core/components/buttons.dart';
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
import 'package:enaklo_pos/core/components/custom_text_field.dart';
import 'package:enaklo_pos/core/components/flushbar.dart';
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class FormTableNewDialog extends StatefulWidget {
const FormTableNewDialog({super.key});
@override
State<FormTableNewDialog> createState() => _FormTableNewDialogState();
}
class _FormTableNewDialogState extends State<FormTableNewDialog> {
TextEditingController tableNameController = TextEditingController();
TextEditingController capacityController = TextEditingController();
TextEditingController locationController = TextEditingController();
@override
Widget build(BuildContext context) {
return CustomModalDialog(
title: 'Tambah Meja',
subtitle: 'Silahkan isi data meja',
contentPadding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
child: Column(
children: [
CustomTextField(
controller: tableNameController,
label: 'Nama Meja',
),
SpaceHeight(16),
CustomTextField(
controller: capacityController,
label: 'Kapasitas',
keyboardType: TextInputType.number,
),
SpaceHeight(16),
CustomTextField(
controller: locationController,
label: 'Lokasi',
),
SpaceHeight(24),
BlocListener<CreateTableBloc, CreateTableState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: (message) {
context.pop();
AppFlushbar.showSuccess(context, message);
},
error: (message) {
AppFlushbar.showError(context, message);
},
);
},
child: BlocBuilder<CreateTableBloc, CreateTableState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => Button.filled(
onPressed: () {
context.read<CreateTableBloc>().add(
CreateTableEvent.createTable(
capacity: int.parse(capacityController.text),
location: locationController.text,
tableName: tableNameController.text,
),
);
},
label: 'Simpan',
),
loading: () =>
Center(child: const CircularProgressIndicator()),
);
},
),
),
],
),
);
}
}

View File

@ -1,18 +1,12 @@
import 'dart:developer'; import 'package:enaklo_pos/presentation/table/dialogs/form_table_new_dialog.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/core/components/components.dart'; import 'package:enaklo_pos/core/components/components.dart';
import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/table/blocs/change_position_table/change_position_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/change_position_table/change_position_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart';
import 'package:enaklo_pos/presentation/table/widgets/table_widget.dart'; import 'package:enaklo_pos/presentation/table/widgets/table_widget.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
class TableManagementScreen extends StatefulWidget { class TableManagementScreen extends StatefulWidget {
const TableManagementScreen({super.key}); const TableManagementScreen({super.key});
@ -64,55 +58,9 @@ class _TableManagementScreenState extends State<TableManagementScreen> {
onPressed: () { onPressed: () {
// show dialaog adn input table name // show dialaog adn input table name
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) => FormTableNewDialog(),
return AlertDialog( );
title: Text('Add Table'),
content: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 180,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CustomTextField(
controller: tableNameController!,
label: 'Table Name',
),
SpaceHeight(16),
Row(
children: [
Expanded(
child: Button.outlined(
onPressed: () {
context.pop();
},
label: 'close',
),
),
SpaceWidth(16),
Expanded(
child: Button.filled(
onPressed: () {
context.read<CreateTableBloc>().add(
CreateTableEvent.createTable(
tableNameController!.text,
Offset(200, 200)));
context
.pop(); // close dialog after adding
},
label: 'Add',
),
),
],
)
],
),
),
),
actions: []);
});
}, },
), ),
), ),
@ -145,8 +93,8 @@ class _TableManagementScreenState extends State<TableManagementScreen> {
return Stack( return Stack(
children: tables.map((table) { children: tables.map((table) {
return Positioned( return Positioned(
left: table.position.dx - 116, left: (table.positionX ?? 0) - 116,
top: table.position.dy - 80, top: (table.positionY ?? 0) - 80,
child: BlocListener<ChangePositionTableBloc, child: BlocListener<ChangePositionTableBloc,
ChangePositionTableState>( ChangePositionTableState>(
listener: (context, state) { listener: (context, state) {
@ -165,7 +113,7 @@ class _TableManagementScreenState extends State<TableManagementScreen> {
context context
.read<ChangePositionTableBloc>() .read<ChangePositionTableBloc>()
.add(ChangePositionTableEvent.changePositionTable( .add(ChangePositionTableEvent.changePositionTable(
tableId: table.id!, tableId: table.id ?? "",
position: details.offset, position: details.offset,
)); ));
}, },

View File

@ -51,18 +51,18 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
Future<void> _handlePostPaymentCleanup() async { Future<void> _handlePostPaymentCleanup() async {
if (widget.table != null && widget.draftOrder?.id != null) { if (widget.table != null && widget.draftOrder?.id != null) {
// Update table status to available // Update table status to available
final newTable = TableModel( // final newTable = TableModel(
id: widget.table!.id, // id: widget.table!.id,
tableName: widget.table!.tableName, // tableName: widget.table!.tableName,
status: 'available', // status: 'available',
orderId: 0, // orderId: 0,
paymentAmount: 0, // paymentAmount: 0,
startTime: DateTime.now().toIso8601String(), // startTime: DateTime.now().toIso8601String(),
position: widget.table!.position, // position: widget.table!.position,
); // );
// Update table status // Update table status
await ProductLocalDatasource.instance.updateStatusTable(newTable); // await ProductLocalDatasource.instance.updateStatusTable(newTable);
// Remove draft order // Remove draft order
await ProductLocalDatasource.instance await ProductLocalDatasource.instance
@ -965,25 +965,25 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
onPressed: () { onPressed: () {
// Void the order // Void the order
if (widget.table != null) { if (widget.table != null) {
final newTable = TableModel( // final newTable = TableModel(
id: widget.table!.id, // id: widget.table!.id,
tableName: widget // tableName: widget
.table!.tableName, // .table!.tableName,
status: 'available', // status: 'available',
orderId: 0, // orderId: 0,
paymentAmount: 0, // paymentAmount: 0,
startTime: DateTime.now() // startTime: DateTime.now()
.toIso8601String(), // .toIso8601String(),
position: widget // position: widget
.table!.position, // .table!.position,
); // );
context // context
.read<StatusTableBloc>() // .read<StatusTableBloc>()
.add( // .add(
StatusTableEvent // StatusTableEvent
.statusTabel( // .statusTabel(
newTable), // newTable),
); // );
} }
// Remove draft order from local storage // Remove draft order from local storage
if (widget.draftOrder?.id != if (widget.draftOrder?.id !=
@ -1013,21 +1013,21 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
const SpaceWidth(8.0), const SpaceWidth(8.0),
BlocListener<OrderBloc, OrderState>( BlocListener<OrderBloc, OrderState>(
listener: (context, state) { listener: (context, state) {
final newTable = TableModel( // final newTable = TableModel(
id: widget.table!.id, // id: widget.table!.id,
tableName: widget.table!.tableName, // tableName: widget.table!.tableName,
status: 'available', // status: 'available',
orderId: 0, // orderId: 0,
paymentAmount: 0, // paymentAmount: 0,
startTime: // startTime:
DateTime.now().toIso8601String(), // DateTime.now().toIso8601String(),
position: widget.table!.position, // position: widget.table!.position,
); // );
context.read<StatusTableBloc>().add( // context.read<StatusTableBloc>().add(
StatusTableEvent.statusTabel( // StatusTableEvent.statusTabel(
newTable, // newTable,
), // ),
); // );
ProductLocalDatasource.instance ProductLocalDatasource.instance
.removeDraftOrderById( .removeDraftOrderById(
widget.draftOrder!.id!); widget.draftOrder!.id!);
@ -1160,24 +1160,24 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
'uang tunai' || 'uang tunai' ||
paymentMethodName == paymentMethodName ==
'cash payment') { 'cash payment') {
context.read<OrderBloc>().add( // context.read<OrderBloc>().add(
OrderEvent.order( // OrderEvent.order(
items, // items,
discount, // discount,
discountAmountFinal, // discountAmountFinal,
finalTax.toInt(), // finalTax.toInt(),
0, // 0,
totalPriceController.text // totalPriceController.text
.toIntegerFromText, // .toIntegerFromText,
customerController.text, // customerController.text,
widget.table?.id ?? 0, // widget.table?.id ?? 0,
'completed', // 'completed',
'paid', // 'paid',
selectedPaymentMethod // selectedPaymentMethod
?.name ?? // ?.name ??
'Cash', // 'Cash',
totalPriceFinal, // totalPriceFinal,
orderType)); // orderType));
await showDialog( await showDialog(
context: context, context: context,
@ -1202,24 +1202,24 @@ class _PaymentTablePageState extends State<PaymentTablePage> {
await _handlePostPaymentCleanup(); await _handlePostPaymentCleanup();
} else { } else {
log("Processing non-cash payment: ${selectedPaymentMethod?.name}"); log("Processing non-cash payment: ${selectedPaymentMethod?.name}");
context.read<OrderBloc>().add( // context.read<OrderBloc>().add(
OrderEvent.order( // OrderEvent.order(
items, // items,
discount, // discount,
discountAmountFinal, // discountAmountFinal,
finalTax.toInt(), // finalTax.toInt(),
0, // 0,
totalPriceController.text // totalPriceController.text
.toIntegerFromText, // .toIntegerFromText,
customerController.text, // customerController.text,
widget.table?.id ?? 0, // widget.table?.id ?? 0,
'completed', // 'completed',
'paid', // 'paid',
selectedPaymentMethod // selectedPaymentMethod
?.name ?? // ?.name ??
'Unknown Payment Method', // 'Unknown Payment Method',
totalPriceFinal, // totalPriceFinal,
orderType)); // orderType));
await showDialog( await showDialog(
context: context, context: context,

View File

@ -39,8 +39,8 @@ class _CardTableWidgetState extends State<CardTableWidget> {
loadData() async { loadData() async {
if (widget.table.status != 'available') { if (widget.table.status != 'available') {
data = await ProductLocalDatasource.instance // data = await ProductLocalDatasource.instance
.getDraftOrderById(widget.table.orderId); // .getDraftOrderById(widget.table.orderId);
} }
} }
@ -70,9 +70,10 @@ class _CardTableWidgetState extends State<CardTableWidget> {
), ),
), ),
Text( Text(
widget.table.status == 'available' // widget.table.status == 'available'
? widget.table.status // ? widget.table.status
: "${widget.table.status} - ${DateTime.parse(widget.table.startTime).toFormattedTime()}", // : "${widget.table.status} - ${DateTime.parse(widget.table.startTime).toFormattedTime()}",
"",
style: TextStyle( style: TextStyle(
color: AppColors.black, color: AppColors.black,
fontSize: 24, fontSize: 24,

View File

@ -51,8 +51,8 @@ class _TableWidgetState extends State<TableWidget> {
loadData() async { loadData() async {
if (widget.table.status != 'available') { if (widget.table.status != 'available') {
data = await ProductLocalDatasource.instance // data = await ProductLocalDatasource.instance
.getDraftOrderById(widget.table.orderId); // .getDraftOrderById(widget.table.orderId);
} }
} }
@ -136,33 +136,33 @@ class _TableWidgetState extends State<TableWidget> {
Expanded( Expanded(
child: Button.filled( child: Button.filled(
onPressed: () { onPressed: () {
final newData = // final newData =
TableModel( // TableModel(
id: widget.table.id, // id: widget.table.id,
tableName: // tableName:
tableNameController! // tableNameController!
.text, // .text,
status: // status:
widget.table.status, // widget.table.status,
startTime: widget // startTime: widget
.table.startTime, // .table.startTime,
orderId: widget // orderId: widget
.table.orderId, // .table.orderId,
paymentAmount: widget // paymentAmount: widget
.table // .table
.paymentAmount, // .paymentAmount,
position: widget // position: widget
.table.position, // .table.position,
); // );
context // context
.read< // .read<
UpdateTableBloc>() // UpdateTableBloc>()
.add( // .add(
UpdateTableEvent // UpdateTableEvent
.updateTable( // .updateTable(
newData, // newData,
), // ),
); // );
context context
.pop(); // close dialog after adding .pop(); // close dialog after adding
}, },
@ -194,16 +194,16 @@ class _TableWidgetState extends State<TableWidget> {
color: widget.table.status == 'available' color: widget.table.status == 'available'
? Colors.green ? Colors.green
: Colors.red), : Colors.red),
widget.table.status == 'available' // widget.table.status == 'available'
? SizedBox.shrink() // ? SizedBox.shrink()
: _buildInfoRow( // : _buildInfoRow(
'Start Time:', // 'Start Time:',
DateFormatter.formatDateTime2( // DateFormatter.formatDateTime2(
widget.table.startTime)), // widget.table.startTime)),
widget.table.status == 'available' // widget.table.status == 'available'
? SizedBox.shrink() // ? SizedBox.shrink()
: _buildInfoRow( // : _buildInfoRow(
'Order ID:', widget.table.orderId.toString()), // 'Order ID:', widget.table.orderId.toString()),
widget.table.status == 'available' widget.table.status == 'available'
? SizedBox.shrink() ? SizedBox.shrink()
: SpaceHeight(16), : SpaceHeight(16),
@ -267,29 +267,29 @@ class _TableWidgetState extends State<TableWidget> {
backgroundColor: AppColors.red, backgroundColor: AppColors.red,
), ),
onPressed: () { onPressed: () {
// Void the order // // Void the order
final newTable = TableModel( // final newTable = TableModel(
id: widget.table.id, // id: widget.table.id,
tableName: // tableName:
widget.table.tableName, // widget.table.tableName,
status: 'available', // status: 'available',
orderId: 0, // orderId: 0,
paymentAmount: 0, // paymentAmount: 0,
startTime: DateTime.now() // startTime: DateTime.now()
.toIso8601String(), // .toIso8601String(),
position: widget.table.position, // position: widget.table.position,
); // );
context // context
.read<StatusTableBloc>() // .read<StatusTableBloc>()
.add( // .add(
StatusTableEvent // StatusTableEvent
.statusTabel(newTable), // .statusTabel(newTable),
); // );
// Remove draft order from local storage // // Remove draft order from local storage
ProductLocalDatasource.instance // ProductLocalDatasource.instance
.removeDraftOrderById( // .removeDraftOrderById(
widget.table.orderId); // widget.table.orderId);
log("Voided order for table: ${widget.table.tableName}"); // log("Voided order for table: ${widget.table.tableName}");
}, },
child: const Text( child: const Text(
"Ya, Batalkan", "Ya, Batalkan",