Compare commits

..
121 Commits
Author SHA1 Message Date
Efril f5b0e66706 config: update version 2026-07-22 14:57:06 +07:00
Efril 1ff144a1a2 feat: sort order printer 2026-07-22 14:56:38 +07:00
Efril eb031d4c2a config: prod and dev 2026-07-09 23:08:50 +07:00
Efril 7161f523c2 feat: update api url 2026-07-03 16:04:08 +07:00
Efril d097df1592 update 2026-06-04 07:22:58 +07:00
Efril e8bbef03b0 config: update version 2026-06-04 00:50:34 +07:00
Efril b228538725 feat: implement idempotency key for critical API endpoints 2026-06-04 00:48:50 +07:00
Efril 2ab20a1150 add printer checker checks 2026-05-28 18:11:02 +07:00
Efril b9fcd79962 update version 2026-05-27 19:52:47 +07:00
Efril 9a5f0c7415 fix printer 2026-05-27 19:51:43 +07:00
Efril d345294a2f update printer bar and kitchen 2026-05-27 16:19:11 +07:00
Efril beb86f6259 update printer checker 2026-05-27 16:13:12 +07:00
efrilm ea29c62af1 update build number 2026-05-26 12:14:30 +07:00
efrilm c8a84ffe5f update kitchen printer 2026-05-26 12:14:02 +07:00
Efril 539c70be17 update 2026-05-25 23:35:24 +07:00
Efril c45848bcf2 update printer 2026-05-25 23:33:49 +07:00
Efril 6d9377f4ab update printer 2026-05-25 20:35:40 +07:00
Efril 56e720e253 update checker print 2026-05-25 19:34:31 +07:00
Efril c7ed45a374 fix printer 2026-05-24 00:59:02 +07:00
Efril a0610459bf update login with device info 2026-05-10 22:51:04 +07:00
Efril 842b7a5041 fix fcm 2026-05-07 18:03:41 +07:00
Efril dc09aabbe8 setup fcm 2026-05-07 17:44:03 +07:00
Efril cdc65f8f8f update success add item user before customer name 2026-04-29 12:46:52 +07:00
Efril e7260ea0e2 fix success add item order 2026-04-27 17:39:15 +07:00
Efril b173654a9c update print ui and report dashboard 2026-04-27 17:28:34 +07:00
Efril 699ca4cfb7 handler error print 2026-04-27 12:53:55 +07:00
Efril d790262fd4 update version 2026-04-26 22:33:33 +07:00
Efril 60fec68a92 fix void 2026-04-26 22:32:48 +07:00
Efril ab2d7d7be5 fix void 2026-04-26 22:31:26 +07:00
Efril 6ac88b92ae fix add order item 2026-04-26 22:27:44 +07:00
Efril 9e4e2ebbd1 fix printer fc 2026-04-26 22:15:50 +07:00
Efril 3513c63259 fix qty split bill 2026-04-10 09:50:44 +07:00
Efril 46dfb7e44e update print all segment 2026-04-03 17:44:04 +07:00
Efril a0db13feb4 update version 2026-03-04 23:33:08 +07:00
Efril f626b18d31 fix date range picker 2026-03-04 23:32:47 +07:00
Efril 200f996d3e fix split bill 2026-03-04 23:30:52 +07:00
Efril a739e1c29e update payment page 2026-03-04 22:43:18 +07:00
Efril 4481d24375 update 2026-03-03 19:35:11 +07:00
Efril 59d8f06d75 update printer 2026-03-03 19:11:29 +07:00
Efril e625bd3d2a const constructure 2026-03-01 20:02:12 +07:00
Efril 5058f99fe0 update printer 2026-03-01 19:37:23 +07:00
Efril f7cafeb583 change package calendar 2026-03-01 19:11:08 +07:00
efrilm 37d747c0ba update report 2025-11-13 17:47:00 +07:00
efrilm e3b9444a08 fix printer 2025-11-13 15:57:43 +07:00
efrilm d8a28c084d update printer bar 2025-11-13 13:04:32 +07:00
efrilm d3974b8eda fix printer 2025-11-13 12:56:28 +07:00
efrilm 97313371c3 fix table 2025-11-13 12:45:09 +07:00
efrilm 6fa45c8ac0 fix outlet, fix category, fix printer 2025-11-13 12:01:24 +07:00
efrilm b2b2e2b111 logout 2025-11-10 17:23:26 +07:00
efrilm 0a8f8d93bb Sync Page 2025-11-10 16:56:12 +07:00
efrilm f5256fb33d split struct 2025-11-10 13:28:18 +07:00
efrilm c5673a147c void struck 2025-11-10 13:06:06 +07:00
efrilm af182b6f5a print payment 2025-11-07 17:08:57 +07:00
efrilm d78b6165c2 print bill 2025-11-07 16:59:46 +07:00
efrilm 0886e8c912 print order add item 2025-11-07 16:45:36 +07:00
efrilm 93560b85cb print order 2025-11-07 16:29:26 +07:00
efrilm 4eece81eb1 print ticket 2025-11-06 18:59:10 +07:00
efrilm 873dd7e224 print bar 2025-11-06 18:48:28 +07:00
efrilm 3e6dce93fb print kitchen 2025-11-06 18:45:14 +07:00
efrilm 8923ce737d print kitchen 2025-11-06 18:41:34 +07:00
efrilm c0cf63a176 print checker 2025-11-06 18:28:14 +07:00
efrilm bf7a5708f5 print receipt 2025-11-06 18:15:54 +07:00
efrilm 896ea6c28c printer delete 2025-11-04 22:49:05 +07:00
efrilm 4ed7721bbe setting printer ticket 2025-11-04 22:29:06 +07:00
efrilm f12614cec9 printer kitchen 2025-11-04 22:24:03 +07:00
efrilm 98b152cbc2 printer checker 2025-11-04 22:22:13 +07:00
efrilm 1b24bae23a printer receipt 2025-11-04 22:13:15 +07:00
efrilm a87b62ca9f printer form, bluetooth 2025-11-04 14:58:51 +07:00
efrilm dca0f546f9 report inventory 2025-11-04 00:21:15 +07:00
efrilm 2a44ce023e report category 2025-11-03 23:24:16 +07:00
efrilm 13941d4881 fix report 2025-11-03 21:33:42 +07:00
efrilm 07932d688f report profit loss 2025-11-03 21:28:36 +07:00
efrilm 5a7892aa99 report payment method 2025-11-03 20:32:46 +07:00
efrilm 14c3c69ad6 report product 2025-11-03 19:34:46 +07:00
efrilm 3bb6bd653e report sales 2025-11-03 17:18:29 +07:00
efrilm b4a9cf31fc report dashboard 2025-11-03 16:24:11 +07:00
efrilm 069c2296de refund 2025-11-01 16:17:45 +07:00
efrilm ef23839761 update order detail 2025-11-01 04:20:03 +07:00
efrilm d37a4993df fix nav rails 2025-11-01 04:17:43 +07:00
efrilm 2f155a2f8d report page 2025-11-01 04:11:29 +07:00
efrilm d111025aa6 update order page 2025-11-01 03:29:13 +07:00
efrilm fecb4fb5c1 Success Split Bill Page 2025-11-01 03:24:39 +07:00
efrilm 35f02e6b76 split bill 2025-10-31 20:43:37 +07:00
efrilm 6b42cd86ff split bill 2025-10-31 19:24:15 +07:00
efrilm 7961c9d8c5 success void 2025-10-31 15:14:28 +07:00
efrilm 8d9e622121 void 2025-10-31 14:33:02 +07:00
efrilm bf43c398d2 payment success page 2025-10-30 17:08:11 +07:00
efrilm b335102677 payment 2025-10-30 16:35:47 +07:00
efrilm adc90a90a0 add items order 2025-10-28 20:55:10 +07:00
efrilm 0693411cf7 confirm order save 2025-10-28 17:10:47 +07:00
efrilm a514a8abdb save order pay later page 2025-10-28 16:26:35 +07:00
efrilm a6e58a8cc0 fix order 2025-10-28 15:46:12 +07:00
efrilm 59d4d4c0e5 success order page 2025-10-28 15:43:51 +07:00
efrilm 137f3d9636 create order with payment 2025-10-28 00:58:39 +07:00
efrilm 37f0008ec8 create order 2025-10-28 00:08:12 +07:00
efrilm 34555dd789 order load more 2025-10-27 21:57:25 +07:00
efrilm 8bd61eb58e order page 2025-10-27 21:55:19 +07:00
efrilm b8eefcbac0 checkout page 2025-10-27 15:27:21 +07:00
efrilm 9e5a6cc7ae payment method 2025-10-27 14:24:29 +07:00
efrilm 3135dde317 checkout page 2025-10-27 01:54:35 +07:00
efrilm e8fd683077 change table 2025-10-27 01:18:46 +07:00
efrilm 08bbfc393b delivery dialog 2025-10-27 01:07:05 +07:00
efrilm 8fec9c8cd0 order type 2025-10-26 23:10:23 +07:00
efrilm 0bffd92a08 customer page 2025-10-26 22:57:22 +07:00
efrilm 5c683eda8d transfer table 2025-10-26 19:36:59 +07:00
efrilm d5ed3f62ff create table 2025-10-26 18:47:51 +07:00
efrilm 634b331716 update position table, set selected table 2025-10-26 18:06:09 +07:00
efrilm 655902a659 update 2025-10-26 16:09:56 +07:00
efrilm 0e83d213fc update total price 2025-10-25 03:03:44 +07:00
efrilm 013f313e35 checkout form 2025-10-25 02:09:47 +07:00
efrilm e85138f27e home right title 2025-10-25 00:28:17 +07:00
efrilm 9c38d001d1 variant dialog 2025-10-25 00:19:51 +07:00
efrilm 9243e0948b update 2025-10-25 00:14:45 +07:00
efrilm 754048b565 product and category loader 2025-10-25 00:13:43 +07:00
efrilm 7bcf54c555 update 2025-10-24 23:23:58 +07:00
efrilm 79e109cfe4 sync page 2025-10-24 23:20:41 +07:00
efrilm 6892895021 sync bloc 2025-10-24 22:25:01 +07:00
efrilm 4fdd1e44f8 product repo 2025-10-24 22:03:35 +07:00
efrilm dea5de8828 sync page 2025-10-24 20:25:30 +07:00
efrilm 71fa4823fc category repo 2025-10-24 20:06:42 +07:00
efrilm 683fff6eeb outlet dialog 2025-10-24 14:28:04 +07:00
435 changed files with 107252 additions and 271 deletions
+17
View File
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Dev",
"request": "launch",
"type": "dart",
"args": ["--dart-define=ENV=dev"]
},
{
"name": "Prod",
"request": "launch",
"type": "dart",
"args": ["--dart-define=ENV=prod"]
}
]
}
+209 -10
View File
@@ -1,16 +1,215 @@
# apskel_pos_flutter_v2
# Apskel POS Flutter
A new Flutter project.
Aplikasi Point of Sale (POS) berbasis Flutter untuk manajemen kasir restoran. Mendukung manajemen order, produk, meja, pelanggan, pembayaran, printer bluetooth/network, analitik, dan push notification via FCM.
## Getting Started
---
This project is a starting point for a Flutter application.
## Fitur Utama
A few resources to get you started if this is your first Flutter project:
- **Autentikasi** — Login dengan email & password, logout, session management
- **Order Management** — Buat, kelola, dan proses order
- **Produk & Kategori** — Manajemen menu dan kategori produk
- **Meja** — Manajemen meja restoran
- **Pelanggan** — Data pelanggan dan riwayat transaksi
- **Checkout & Pembayaran** — Proses checkout dengan berbagai metode pembayaran
- **Split Bill** — Pembagian tagihan
- **Void & Refund** — Pembatalan dan pengembalian transaksi
- **Printer** — Cetak struk via Bluetooth dan Network printer
- **Analitik** — Dashboard, laporan penjualan, produk, kategori, payment method, profit/loss, inventory
- **Sinkronisasi** — Sinkronisasi data offline/online
- **Push Notification (FCM)** — Notifikasi real-time via Firebase Cloud Messaging
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
---
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
## Tech Stack
| Kategori | Library |
|---|---|
| State Management | `flutter_bloc` + `bloc` |
| Dependency Injection | `get_it` + `injectable` |
| Navigation | `auto_route` |
| HTTP Client | `dio` |
| Local Database | `sqflite` |
| Local Storage | `shared_preferences` |
| Firebase | `firebase_core`, `firebase_crashlytics`, `firebase_messaging` |
| Push Notification | `flutter_local_notifications` |
| Device Info | `device_info_plus`, `package_info_plus` |
| Code Generation | `freezed`, `json_serializable` |
| Printer | `print_bluetooth_thermal`, `flutter_esc_pos_network` |
| Chart | `fl_chart` |
| Connectivity | `connectivity_plus` |
---
## Arsitektur
Project menggunakan **Clean Architecture** dengan 4 layer:
```
lib/
├── application/ # BLoC — state management per fitur
├── domain/ # Entity, repository interface, failure
├── infrastructure/ # Implementasi repository, DTO, datasource
├── presentation/ # UI — pages, components, router
└── common/ # Shared utilities, DI modules, service, theme
```
### Struktur per Fitur
```
feature/
├── application/
│ └── feature_bloc.dart # BLoC
├── domain/
│ ├── entities/ # Domain model (freezed)
│ ├── repositories/ # Interface repository
│ └── failures/ # Failure types
└── infrastructure/
├── datasources/
│ ├── remote_data_provider.dart
│ └── local_data_provider.dart
├── dtos/ # Data Transfer Object (json_serializable)
└── repositories/ # Implementasi repository
```
---
## Setup & Menjalankan
### Prasyarat
- Flutter SDK `^3.8.1`
- Dart SDK `^3.8.1`
- Android SDK / Xcode (untuk iOS)
- Firebase project yang sudah dikonfigurasi
### Instalasi
```bash
# Clone repository
git clone <repo-url>
cd apskel-pos-flutter-v2
# Install dependencies
flutter pub get
# Generate kode (freezed, injectable, auto_route, json_serializable)
dart run build_runner build --delete-conflicting-outputs
```
### Menjalankan App
```bash
# Development
flutter run
# Release
flutter run --release
```
App otomatis menggunakan environment `dev` saat debug dan `prod` saat release.
---
## Environment
Konfigurasi environment ada di `lib/env.dart`:
| Environment | Base URL | Database |
|---|---|---|
| `dev` | `https://api-pos.apskel.id` | `apskel_pos_dev.db` |
| `prod` | `https://api-pos.apskel.id` | `apskel_pos_dev.db` |
Environment dipilih otomatis di `main.dart`:
```dart
await configureDependencies(
kReleaseMode ? Environment.prod : Environment.dev,
);
```
---
## Dependency Injection
DI menggunakan `get_it` + `injectable`. Semua service, repository, dan BLoC didaftarkan via annotation.
### Modul DI
| File | Isi |
|---|---|
| `di_firebase.dart` | `FirebaseMessaging`, `FlutterLocalNotificationsPlugin`, `DeviceInfoPlugin`, `PackageInfo` |
| `di_dio.dart` | `Dio` HTTP client |
| `di_shared_preferences.dart` | `SharedPreferences` |
| `di_database.dart` | `DatabaseHelper` (SQLite) |
| `di_auto_route.dart` | `AppRouter` |
| `di_connectivity.dart` | `Connectivity` |
Setelah menambah atau mengubah class yang menggunakan annotation injectable, jalankan:
```bash
dart run build_runner build --delete-conflicting-outputs
```
---
## Firebase & FCM
### Setup
Firebase sudah dikonfigurasi di `android/app/google-services.json`. Inisialisasi dilakukan di `main.dart` sebelum app berjalan.
### FCM Service
`FcmService` (`lib/common/service/fcm_service.dart`) menangani:
- Request permission notifikasi (Android 13+ / iOS)
- Ambil dan log FCM token
- Foreground notification via `flutter_local_notifications`
- Background & terminated message handler
- Subscribe/unsubscribe topic
FCM token dikirim ke server saat login bersama device info.
### Login Payload
Saat login, app mengirim data berikut ke API:
```json
{
"email": "user@example.com",
"password": "secret",
"fcm_token": "dXj3k9...",
"device_id": "abc123",
"device_name": "Samsung Galaxy Tab S8",
"device_type": "tablet",
"platform": "android",
"app_version": "1.0.4+9",
"os_version": "Android 13 (SDK 33)"
}
```
Nilai valid: `device_type` → `mobile | tablet | desktop`, `platform` → `android | ios | web`
---
## Printer
Mendukung dua jenis printer:
- **Bluetooth** — via `print_bluetooth_thermal`
- **Network (LAN)** — via `flutter_esc_pos_network`
---
## Orientasi Layar
App dikunci ke mode **landscape** (kiri & kanan) karena didesain untuk tablet POS.
---
## Catatan Development
- Jangan edit `injection.config.dart` dan file `*.freezed.dart` / `*.g.dart` secara manual — file tersebut di-generate otomatis
- Gunakan `log()` dari `dart:developer` untuk logging, bukan `print()`
- `print()` dinonaktifkan di release mode
+3
View File
@@ -4,6 +4,9 @@ linter:
rules:
sort_pub_dependencies: false
prefer_relative_imports: true
prefer_const_constructors: true
prefer_const_literals_to_create_immutables: true
prefer_const_declarations: true
analyzer:
errors:
+3
View File
@@ -14,6 +14,7 @@ android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
isCoreLibraryDesugaringEnabled = true
}
kotlinOptions {
@@ -45,6 +46,8 @@ flutter {
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")
// Import the Firebase BoM
implementation(platform("com.google.firebase:firebase-bom:34.4.0"))
+9
View File
@@ -10,6 +10,8 @@
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<!-- Izin khusus untuk akses foto (media images) di Android 33 ke atas -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<!-- Izin notifikasi untuk Android 13+ -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
android:label="Apskel POS"
android:name="${applicationName}"
@@ -41,6 +43,13 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<!-- FCM: default notification icon dan channel -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

+4
View File
@@ -1,3 +1,7 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false
# This newDsl flag was added automatically by Flutter migrator
android.newDsl=false
Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

+3
View File
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
@@ -0,0 +1,52 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'category_analytic_loader_event.dart';
part 'category_analytic_loader_state.dart';
part 'category_analytic_loader_bloc.freezed.dart';
@injectable
class CategoryAnalyticLoaderBloc
extends Bloc<CategoryAnalyticLoaderEvent, CategoryAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
CategoryAnalyticLoaderBloc(this._analyticRepository)
: super(CategoryAnalyticLoaderState.initial()) {
on<CategoryAnalyticLoaderEvent>(_onCategoryAnalyticLoaderEvent);
}
Future<void> _onCategoryAnalyticLoaderEvent(
CategoryAnalyticLoaderEvent event,
Emitter<CategoryAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getCategories(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(categories) async {
emit(
state.copyWith(isFetching: false, categoryAnalytic: categories),
);
},
);
},
);
}
}
@@ -0,0 +1,476 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'category_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$CategoryAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of CategoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CategoryAnalyticLoaderEventCopyWith<CategoryAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CategoryAnalyticLoaderEventCopyWith<$Res> {
factory $CategoryAnalyticLoaderEventCopyWith(
CategoryAnalyticLoaderEvent value,
$Res Function(CategoryAnalyticLoaderEvent) then,
) =
_$CategoryAnalyticLoaderEventCopyWithImpl<
$Res,
CategoryAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$CategoryAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends CategoryAnalyticLoaderEvent
>
implements $CategoryAnalyticLoaderEventCopyWith<$Res> {
_$CategoryAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CategoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $CategoryAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$CategoryAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of CategoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'CategoryAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of CategoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements CategoryAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of CategoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$CategoryAnalyticLoaderState {
CategoryAnalytic get categoryAnalytic => throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of CategoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CategoryAnalyticLoaderStateCopyWith<CategoryAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CategoryAnalyticLoaderStateCopyWith<$Res> {
factory $CategoryAnalyticLoaderStateCopyWith(
CategoryAnalyticLoaderState value,
$Res Function(CategoryAnalyticLoaderState) then,
) =
_$CategoryAnalyticLoaderStateCopyWithImpl<
$Res,
CategoryAnalyticLoaderState
>;
@useResult
$Res call({
CategoryAnalytic categoryAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$CategoryAnalyticCopyWith<$Res> get categoryAnalytic;
}
/// @nodoc
class _$CategoryAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends CategoryAnalyticLoaderState
>
implements $CategoryAnalyticLoaderStateCopyWith<$Res> {
_$CategoryAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CategoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? categoryAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
categoryAnalytic: null == categoryAnalytic
? _value.categoryAnalytic
: categoryAnalytic // ignore: cast_nullable_to_non_nullable
as CategoryAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of CategoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$CategoryAnalyticCopyWith<$Res> get categoryAnalytic {
return $CategoryAnalyticCopyWith<$Res>(_value.categoryAnalytic, (value) {
return _then(_value.copyWith(categoryAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$CategoryAnalyticLoaderStateImplCopyWith<$Res>
implements $CategoryAnalyticLoaderStateCopyWith<$Res> {
factory _$$CategoryAnalyticLoaderStateImplCopyWith(
_$CategoryAnalyticLoaderStateImpl value,
$Res Function(_$CategoryAnalyticLoaderStateImpl) then,
) = __$$CategoryAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
CategoryAnalytic categoryAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$CategoryAnalyticCopyWith<$Res> get categoryAnalytic;
}
/// @nodoc
class __$$CategoryAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$CategoryAnalyticLoaderStateCopyWithImpl<
$Res,
_$CategoryAnalyticLoaderStateImpl
>
implements _$$CategoryAnalyticLoaderStateImplCopyWith<$Res> {
__$$CategoryAnalyticLoaderStateImplCopyWithImpl(
_$CategoryAnalyticLoaderStateImpl _value,
$Res Function(_$CategoryAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of CategoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? categoryAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$CategoryAnalyticLoaderStateImpl(
categoryAnalytic: null == categoryAnalytic
? _value.categoryAnalytic
: categoryAnalytic // ignore: cast_nullable_to_non_nullable
as CategoryAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$CategoryAnalyticLoaderStateImpl
implements _CategoryAnalyticLoaderState {
_$CategoryAnalyticLoaderStateImpl({
required this.categoryAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final CategoryAnalytic categoryAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'CategoryAnalyticLoaderState(categoryAnalytic: $categoryAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CategoryAnalyticLoaderStateImpl &&
(identical(other.categoryAnalytic, categoryAnalytic) ||
other.categoryAnalytic == categoryAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, categoryAnalytic, failureOption, isFetching);
/// Create a copy of CategoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CategoryAnalyticLoaderStateImplCopyWith<_$CategoryAnalyticLoaderStateImpl>
get copyWith =>
__$$CategoryAnalyticLoaderStateImplCopyWithImpl<
_$CategoryAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _CategoryAnalyticLoaderState
implements CategoryAnalyticLoaderState {
factory _CategoryAnalyticLoaderState({
required final CategoryAnalytic categoryAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$CategoryAnalyticLoaderStateImpl;
@override
CategoryAnalytic get categoryAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of CategoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CategoryAnalyticLoaderStateImplCopyWith<_$CategoryAnalyticLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'category_analytic_loader_bloc.dart';
@freezed
class CategoryAnalyticLoaderEvent with _$CategoryAnalyticLoaderEvent {
const factory CategoryAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,15 @@
part of 'category_analytic_loader_bloc.dart';
@freezed
class CategoryAnalyticLoaderState with _$CategoryAnalyticLoaderState {
factory CategoryAnalyticLoaderState({
required CategoryAnalytic categoryAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _CategoryAnalyticLoaderState;
factory CategoryAnalyticLoaderState.initial() => CategoryAnalyticLoaderState(
categoryAnalytic: CategoryAnalytic.empty(),
failureOption: none(),
);
}
@@ -0,0 +1,53 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'dashboard_analytic_loader_event.dart';
part 'dashboard_analytic_loader_state.dart';
part 'dashboard_analytic_loader_bloc.freezed.dart';
@injectable
class DashboardAnalyticLoaderBloc
extends Bloc<DashboardAnalyticLoaderEvent, DashboardAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
DashboardAnalyticLoaderBloc(this._analyticRepository)
: super(DashboardAnalyticLoaderState.initial()) {
on<DashboardAnalyticLoaderEvent>(_onDashboardAnalyticLoader);
}
Future<void> _onDashboardAnalyticLoader(
DashboardAnalyticLoaderEvent event,
Emitter<DashboardAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getDashboard(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(dashboard) async {
emit(
state.copyWith(isFetching: false, dashboardAnalytic: dashboard),
);
},
);
},
);
}
}
@@ -0,0 +1,480 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'dashboard_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$DashboardAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of DashboardAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$DashboardAnalyticLoaderEventCopyWith<DashboardAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $DashboardAnalyticLoaderEventCopyWith<$Res> {
factory $DashboardAnalyticLoaderEventCopyWith(
DashboardAnalyticLoaderEvent value,
$Res Function(DashboardAnalyticLoaderEvent) then,
) =
_$DashboardAnalyticLoaderEventCopyWithImpl<
$Res,
DashboardAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$DashboardAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends DashboardAnalyticLoaderEvent
>
implements $DashboardAnalyticLoaderEventCopyWith<$Res> {
_$DashboardAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of DashboardAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $DashboardAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$DashboardAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of DashboardAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'DashboardAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of DashboardAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements DashboardAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of DashboardAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$DashboardAnalyticLoaderState {
DashboardAnalytic get dashboardAnalytic => throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of DashboardAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$DashboardAnalyticLoaderStateCopyWith<DashboardAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $DashboardAnalyticLoaderStateCopyWith<$Res> {
factory $DashboardAnalyticLoaderStateCopyWith(
DashboardAnalyticLoaderState value,
$Res Function(DashboardAnalyticLoaderState) then,
) =
_$DashboardAnalyticLoaderStateCopyWithImpl<
$Res,
DashboardAnalyticLoaderState
>;
@useResult
$Res call({
DashboardAnalytic dashboardAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$DashboardAnalyticCopyWith<$Res> get dashboardAnalytic;
}
/// @nodoc
class _$DashboardAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends DashboardAnalyticLoaderState
>
implements $DashboardAnalyticLoaderStateCopyWith<$Res> {
_$DashboardAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of DashboardAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? dashboardAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
dashboardAnalytic: null == dashboardAnalytic
? _value.dashboardAnalytic
: dashboardAnalytic // ignore: cast_nullable_to_non_nullable
as DashboardAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of DashboardAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$DashboardAnalyticCopyWith<$Res> get dashboardAnalytic {
return $DashboardAnalyticCopyWith<$Res>(_value.dashboardAnalytic, (value) {
return _then(_value.copyWith(dashboardAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$DashboardAnalyticLoaderStateImplCopyWith<$Res>
implements $DashboardAnalyticLoaderStateCopyWith<$Res> {
factory _$$DashboardAnalyticLoaderStateImplCopyWith(
_$DashboardAnalyticLoaderStateImpl value,
$Res Function(_$DashboardAnalyticLoaderStateImpl) then,
) = __$$DashboardAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
DashboardAnalytic dashboardAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$DashboardAnalyticCopyWith<$Res> get dashboardAnalytic;
}
/// @nodoc
class __$$DashboardAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$DashboardAnalyticLoaderStateCopyWithImpl<
$Res,
_$DashboardAnalyticLoaderStateImpl
>
implements _$$DashboardAnalyticLoaderStateImplCopyWith<$Res> {
__$$DashboardAnalyticLoaderStateImplCopyWithImpl(
_$DashboardAnalyticLoaderStateImpl _value,
$Res Function(_$DashboardAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of DashboardAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? dashboardAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$DashboardAnalyticLoaderStateImpl(
dashboardAnalytic: null == dashboardAnalytic
? _value.dashboardAnalytic
: dashboardAnalytic // ignore: cast_nullable_to_non_nullable
as DashboardAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$DashboardAnalyticLoaderStateImpl
implements _DashboardAnalyticLoaderState {
_$DashboardAnalyticLoaderStateImpl({
required this.dashboardAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final DashboardAnalytic dashboardAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'DashboardAnalyticLoaderState(dashboardAnalytic: $dashboardAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$DashboardAnalyticLoaderStateImpl &&
(identical(other.dashboardAnalytic, dashboardAnalytic) ||
other.dashboardAnalytic == dashboardAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, dashboardAnalytic, failureOption, isFetching);
/// Create a copy of DashboardAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$DashboardAnalyticLoaderStateImplCopyWith<
_$DashboardAnalyticLoaderStateImpl
>
get copyWith =>
__$$DashboardAnalyticLoaderStateImplCopyWithImpl<
_$DashboardAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _DashboardAnalyticLoaderState
implements DashboardAnalyticLoaderState {
factory _DashboardAnalyticLoaderState({
required final DashboardAnalytic dashboardAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$DashboardAnalyticLoaderStateImpl;
@override
DashboardAnalytic get dashboardAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of DashboardAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$DashboardAnalyticLoaderStateImplCopyWith<
_$DashboardAnalyticLoaderStateImpl
>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'dashboard_analytic_loader_bloc.dart';
@freezed
class DashboardAnalyticLoaderEvent with _$DashboardAnalyticLoaderEvent {
const factory DashboardAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,16 @@
part of 'dashboard_analytic_loader_bloc.dart';
@freezed
class DashboardAnalyticLoaderState with _$DashboardAnalyticLoaderState {
factory DashboardAnalyticLoaderState({
required DashboardAnalytic dashboardAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _DashboardAnalyticLoaderState;
factory DashboardAnalyticLoaderState.initial() =>
DashboardAnalyticLoaderState(
dashboardAnalytic: DashboardAnalytic.empty(),
failureOption: none(),
);
}
@@ -0,0 +1,47 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'inventory_analytic_loader_event.dart';
part 'inventory_analytic_loader_state.dart';
part 'inventory_analytic_loader_bloc.freezed.dart';
@injectable
class InventoryAnalyticLoaderBloc
extends Bloc<InventoryAnalyticLoaderEvent, InventoryAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
InventoryAnalyticLoaderBloc(this._analyticRepository)
: super(InventoryAnalyticLoaderState.initial()) {
on<InventoryAnalyticLoaderEvent>(_onInventoryAnalyticLoaderEvent);
}
Future<void> _onInventoryAnalyticLoaderEvent(
InventoryAnalyticLoaderEvent event,
Emitter<InventoryAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getInventory(
dateFrom: e.startDate,
dateTo: e.endDate,
);
emit(
result.fold(
(l) => state.copyWith(isFetching: false, failureOption: some(l)),
(r) => state.copyWith(
isFetching: false,
failureOption: none(),
inventoryAnalytic: r,
),
),
);
},
);
}
}
@@ -0,0 +1,480 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'inventory_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$InventoryAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of InventoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$InventoryAnalyticLoaderEventCopyWith<InventoryAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $InventoryAnalyticLoaderEventCopyWith<$Res> {
factory $InventoryAnalyticLoaderEventCopyWith(
InventoryAnalyticLoaderEvent value,
$Res Function(InventoryAnalyticLoaderEvent) then,
) =
_$InventoryAnalyticLoaderEventCopyWithImpl<
$Res,
InventoryAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$InventoryAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends InventoryAnalyticLoaderEvent
>
implements $InventoryAnalyticLoaderEventCopyWith<$Res> {
_$InventoryAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of InventoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $InventoryAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$InventoryAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of InventoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'InventoryAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of InventoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements InventoryAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of InventoryAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$InventoryAnalyticLoaderState {
InventoryAnalytic get inventoryAnalytic => throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of InventoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$InventoryAnalyticLoaderStateCopyWith<InventoryAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $InventoryAnalyticLoaderStateCopyWith<$Res> {
factory $InventoryAnalyticLoaderStateCopyWith(
InventoryAnalyticLoaderState value,
$Res Function(InventoryAnalyticLoaderState) then,
) =
_$InventoryAnalyticLoaderStateCopyWithImpl<
$Res,
InventoryAnalyticLoaderState
>;
@useResult
$Res call({
InventoryAnalytic inventoryAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$InventoryAnalyticCopyWith<$Res> get inventoryAnalytic;
}
/// @nodoc
class _$InventoryAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends InventoryAnalyticLoaderState
>
implements $InventoryAnalyticLoaderStateCopyWith<$Res> {
_$InventoryAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of InventoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? inventoryAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
inventoryAnalytic: null == inventoryAnalytic
? _value.inventoryAnalytic
: inventoryAnalytic // ignore: cast_nullable_to_non_nullable
as InventoryAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of InventoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$InventoryAnalyticCopyWith<$Res> get inventoryAnalytic {
return $InventoryAnalyticCopyWith<$Res>(_value.inventoryAnalytic, (value) {
return _then(_value.copyWith(inventoryAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$InventoryAnalyticLoaderStateImplCopyWith<$Res>
implements $InventoryAnalyticLoaderStateCopyWith<$Res> {
factory _$$InventoryAnalyticLoaderStateImplCopyWith(
_$InventoryAnalyticLoaderStateImpl value,
$Res Function(_$InventoryAnalyticLoaderStateImpl) then,
) = __$$InventoryAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
InventoryAnalytic inventoryAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$InventoryAnalyticCopyWith<$Res> get inventoryAnalytic;
}
/// @nodoc
class __$$InventoryAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$InventoryAnalyticLoaderStateCopyWithImpl<
$Res,
_$InventoryAnalyticLoaderStateImpl
>
implements _$$InventoryAnalyticLoaderStateImplCopyWith<$Res> {
__$$InventoryAnalyticLoaderStateImplCopyWithImpl(
_$InventoryAnalyticLoaderStateImpl _value,
$Res Function(_$InventoryAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of InventoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? inventoryAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$InventoryAnalyticLoaderStateImpl(
inventoryAnalytic: null == inventoryAnalytic
? _value.inventoryAnalytic
: inventoryAnalytic // ignore: cast_nullable_to_non_nullable
as InventoryAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$InventoryAnalyticLoaderStateImpl
implements _InventoryAnalyticLoaderState {
_$InventoryAnalyticLoaderStateImpl({
required this.inventoryAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final InventoryAnalytic inventoryAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'InventoryAnalyticLoaderState(inventoryAnalytic: $inventoryAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$InventoryAnalyticLoaderStateImpl &&
(identical(other.inventoryAnalytic, inventoryAnalytic) ||
other.inventoryAnalytic == inventoryAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, inventoryAnalytic, failureOption, isFetching);
/// Create a copy of InventoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$InventoryAnalyticLoaderStateImplCopyWith<
_$InventoryAnalyticLoaderStateImpl
>
get copyWith =>
__$$InventoryAnalyticLoaderStateImplCopyWithImpl<
_$InventoryAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _InventoryAnalyticLoaderState
implements InventoryAnalyticLoaderState {
factory _InventoryAnalyticLoaderState({
required final InventoryAnalytic inventoryAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$InventoryAnalyticLoaderStateImpl;
@override
InventoryAnalytic get inventoryAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of InventoryAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$InventoryAnalyticLoaderStateImplCopyWith<
_$InventoryAnalyticLoaderStateImpl
>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'inventory_analytic_loader_bloc.dart';
@freezed
class InventoryAnalyticLoaderEvent with _$InventoryAnalyticLoaderEvent {
const factory InventoryAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,16 @@
part of 'inventory_analytic_loader_bloc.dart';
@freezed
class InventoryAnalyticLoaderState with _$InventoryAnalyticLoaderState {
factory InventoryAnalyticLoaderState({
required InventoryAnalytic inventoryAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _InventoryAnalyticLoaderState;
factory InventoryAnalyticLoaderState.initial() =>
InventoryAnalyticLoaderState(
inventoryAnalytic: InventoryAnalytic.empty(),
failureOption: none(),
);
}
@@ -0,0 +1,59 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'payment_method_analytic_loader_event.dart';
part 'payment_method_analytic_loader_state.dart';
part 'payment_method_analytic_loader_bloc.freezed.dart';
@injectable
class PaymentMethodAnalyticLoaderBloc
extends
Bloc<
PaymentMethodAnalyticLoaderEvent,
PaymentMethodAnalyticLoaderState
> {
final IAnalyticRepository _analyticRepository;
PaymentMethodAnalyticLoaderBloc(this._analyticRepository)
: super(PaymentMethodAnalyticLoaderState.initial()) {
on<PaymentMethodAnalyticLoaderEvent>(_onPaymentMethodAnalyticLoaderEvent);
}
Future<void> _onPaymentMethodAnalyticLoaderEvent(
PaymentMethodAnalyticLoaderEvent event,
Emitter<PaymentMethodAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getPaymentMethod(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(paymentMethod) async {
emit(
state.copyWith(
isFetching: false,
paymentMethodAnalytic: paymentMethod,
),
);
},
);
},
);
}
}
@@ -0,0 +1,487 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'payment_method_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$PaymentMethodAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of PaymentMethodAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PaymentMethodAnalyticLoaderEventCopyWith<PaymentMethodAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PaymentMethodAnalyticLoaderEventCopyWith<$Res> {
factory $PaymentMethodAnalyticLoaderEventCopyWith(
PaymentMethodAnalyticLoaderEvent value,
$Res Function(PaymentMethodAnalyticLoaderEvent) then,
) =
_$PaymentMethodAnalyticLoaderEventCopyWithImpl<
$Res,
PaymentMethodAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$PaymentMethodAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends PaymentMethodAnalyticLoaderEvent
>
implements $PaymentMethodAnalyticLoaderEventCopyWith<$Res> {
_$PaymentMethodAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PaymentMethodAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $PaymentMethodAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$PaymentMethodAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of PaymentMethodAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'PaymentMethodAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of PaymentMethodAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements PaymentMethodAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of PaymentMethodAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$PaymentMethodAnalyticLoaderState {
PaymentMethodAnalytic get paymentMethodAnalytic =>
throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of PaymentMethodAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PaymentMethodAnalyticLoaderStateCopyWith<PaymentMethodAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PaymentMethodAnalyticLoaderStateCopyWith<$Res> {
factory $PaymentMethodAnalyticLoaderStateCopyWith(
PaymentMethodAnalyticLoaderState value,
$Res Function(PaymentMethodAnalyticLoaderState) then,
) =
_$PaymentMethodAnalyticLoaderStateCopyWithImpl<
$Res,
PaymentMethodAnalyticLoaderState
>;
@useResult
$Res call({
PaymentMethodAnalytic paymentMethodAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$PaymentMethodAnalyticCopyWith<$Res> get paymentMethodAnalytic;
}
/// @nodoc
class _$PaymentMethodAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends PaymentMethodAnalyticLoaderState
>
implements $PaymentMethodAnalyticLoaderStateCopyWith<$Res> {
_$PaymentMethodAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PaymentMethodAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? paymentMethodAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
paymentMethodAnalytic: null == paymentMethodAnalytic
? _value.paymentMethodAnalytic
: paymentMethodAnalytic // ignore: cast_nullable_to_non_nullable
as PaymentMethodAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of PaymentMethodAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$PaymentMethodAnalyticCopyWith<$Res> get paymentMethodAnalytic {
return $PaymentMethodAnalyticCopyWith<$Res>(_value.paymentMethodAnalytic, (
value,
) {
return _then(_value.copyWith(paymentMethodAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$PaymentMethodAnalyticLoaderStateImplCopyWith<$Res>
implements $PaymentMethodAnalyticLoaderStateCopyWith<$Res> {
factory _$$PaymentMethodAnalyticLoaderStateImplCopyWith(
_$PaymentMethodAnalyticLoaderStateImpl value,
$Res Function(_$PaymentMethodAnalyticLoaderStateImpl) then,
) = __$$PaymentMethodAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
PaymentMethodAnalytic paymentMethodAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$PaymentMethodAnalyticCopyWith<$Res> get paymentMethodAnalytic;
}
/// @nodoc
class __$$PaymentMethodAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$PaymentMethodAnalyticLoaderStateCopyWithImpl<
$Res,
_$PaymentMethodAnalyticLoaderStateImpl
>
implements _$$PaymentMethodAnalyticLoaderStateImplCopyWith<$Res> {
__$$PaymentMethodAnalyticLoaderStateImplCopyWithImpl(
_$PaymentMethodAnalyticLoaderStateImpl _value,
$Res Function(_$PaymentMethodAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of PaymentMethodAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? paymentMethodAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$PaymentMethodAnalyticLoaderStateImpl(
paymentMethodAnalytic: null == paymentMethodAnalytic
? _value.paymentMethodAnalytic
: paymentMethodAnalytic // ignore: cast_nullable_to_non_nullable
as PaymentMethodAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$PaymentMethodAnalyticLoaderStateImpl
implements _PaymentMethodAnalyticLoaderState {
_$PaymentMethodAnalyticLoaderStateImpl({
required this.paymentMethodAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final PaymentMethodAnalytic paymentMethodAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'PaymentMethodAnalyticLoaderState(paymentMethodAnalytic: $paymentMethodAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PaymentMethodAnalyticLoaderStateImpl &&
(identical(other.paymentMethodAnalytic, paymentMethodAnalytic) ||
other.paymentMethodAnalytic == paymentMethodAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode => Object.hash(
runtimeType,
paymentMethodAnalytic,
failureOption,
isFetching,
);
/// Create a copy of PaymentMethodAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$PaymentMethodAnalyticLoaderStateImplCopyWith<
_$PaymentMethodAnalyticLoaderStateImpl
>
get copyWith =>
__$$PaymentMethodAnalyticLoaderStateImplCopyWithImpl<
_$PaymentMethodAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _PaymentMethodAnalyticLoaderState
implements PaymentMethodAnalyticLoaderState {
factory _PaymentMethodAnalyticLoaderState({
required final PaymentMethodAnalytic paymentMethodAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$PaymentMethodAnalyticLoaderStateImpl;
@override
PaymentMethodAnalytic get paymentMethodAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of PaymentMethodAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$PaymentMethodAnalyticLoaderStateImplCopyWith<
_$PaymentMethodAnalyticLoaderStateImpl
>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'payment_method_analytic_loader_bloc.dart';
@freezed
class PaymentMethodAnalyticLoaderEvent with _$PaymentMethodAnalyticLoaderEvent {
const factory PaymentMethodAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,16 @@
part of 'payment_method_analytic_loader_bloc.dart';
@freezed
class PaymentMethodAnalyticLoaderState with _$PaymentMethodAnalyticLoaderState {
factory PaymentMethodAnalyticLoaderState({
required PaymentMethodAnalytic paymentMethodAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _PaymentMethodAnalyticLoaderState;
factory PaymentMethodAnalyticLoaderState.initial() =>
PaymentMethodAnalyticLoaderState(
paymentMethodAnalytic: PaymentMethodAnalytic.empty(),
failureOption: none(),
);
}
@@ -0,0 +1,50 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'product_analytic_loader_event.dart';
part 'product_analytic_loader_state.dart';
part 'product_analytic_loader_bloc.freezed.dart';
@injectable
class ProductAnalyticLoaderBloc
extends Bloc<ProductAnalyticLoaderEvent, ProductAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
ProductAnalyticLoaderBloc(this._analyticRepository)
: super(ProductAnalyticLoaderState.initial()) {
on<ProductAnalyticLoaderEvent>(_onProductAnalyticLoaderEvent);
}
Future<void> _onProductAnalyticLoaderEvent(
ProductAnalyticLoaderEvent event,
Emitter<ProductAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getProducts(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(products) async {
emit(state.copyWith(isFetching: false, productAnalytic: products));
},
);
},
);
}
}
@@ -0,0 +1,475 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'product_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$ProductAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of ProductAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProductAnalyticLoaderEventCopyWith<ProductAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProductAnalyticLoaderEventCopyWith<$Res> {
factory $ProductAnalyticLoaderEventCopyWith(
ProductAnalyticLoaderEvent value,
$Res Function(ProductAnalyticLoaderEvent) then,
) =
_$ProductAnalyticLoaderEventCopyWithImpl<
$Res,
ProductAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$ProductAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends ProductAnalyticLoaderEvent
>
implements $ProductAnalyticLoaderEventCopyWith<$Res> {
_$ProductAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProductAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $ProductAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$ProductAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of ProductAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'ProductAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of ProductAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements ProductAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of ProductAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$ProductAnalyticLoaderState {
ProductAnalytic get productAnalytic => throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of ProductAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProductAnalyticLoaderStateCopyWith<ProductAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProductAnalyticLoaderStateCopyWith<$Res> {
factory $ProductAnalyticLoaderStateCopyWith(
ProductAnalyticLoaderState value,
$Res Function(ProductAnalyticLoaderState) then,
) =
_$ProductAnalyticLoaderStateCopyWithImpl<
$Res,
ProductAnalyticLoaderState
>;
@useResult
$Res call({
ProductAnalytic productAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$ProductAnalyticCopyWith<$Res> get productAnalytic;
}
/// @nodoc
class _$ProductAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends ProductAnalyticLoaderState
>
implements $ProductAnalyticLoaderStateCopyWith<$Res> {
_$ProductAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProductAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
productAnalytic: null == productAnalytic
? _value.productAnalytic
: productAnalytic // ignore: cast_nullable_to_non_nullable
as ProductAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of ProductAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProductAnalyticCopyWith<$Res> get productAnalytic {
return $ProductAnalyticCopyWith<$Res>(_value.productAnalytic, (value) {
return _then(_value.copyWith(productAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$ProductAnalyticLoaderStateImplCopyWith<$Res>
implements $ProductAnalyticLoaderStateCopyWith<$Res> {
factory _$$ProductAnalyticLoaderStateImplCopyWith(
_$ProductAnalyticLoaderStateImpl value,
$Res Function(_$ProductAnalyticLoaderStateImpl) then,
) = __$$ProductAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
ProductAnalytic productAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$ProductAnalyticCopyWith<$Res> get productAnalytic;
}
/// @nodoc
class __$$ProductAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$ProductAnalyticLoaderStateCopyWithImpl<
$Res,
_$ProductAnalyticLoaderStateImpl
>
implements _$$ProductAnalyticLoaderStateImplCopyWith<$Res> {
__$$ProductAnalyticLoaderStateImplCopyWithImpl(
_$ProductAnalyticLoaderStateImpl _value,
$Res Function(_$ProductAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of ProductAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? productAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$ProductAnalyticLoaderStateImpl(
productAnalytic: null == productAnalytic
? _value.productAnalytic
: productAnalytic // ignore: cast_nullable_to_non_nullable
as ProductAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$ProductAnalyticLoaderStateImpl implements _ProductAnalyticLoaderState {
_$ProductAnalyticLoaderStateImpl({
required this.productAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final ProductAnalytic productAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'ProductAnalyticLoaderState(productAnalytic: $productAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProductAnalyticLoaderStateImpl &&
(identical(other.productAnalytic, productAnalytic) ||
other.productAnalytic == productAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, productAnalytic, failureOption, isFetching);
/// Create a copy of ProductAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProductAnalyticLoaderStateImplCopyWith<_$ProductAnalyticLoaderStateImpl>
get copyWith =>
__$$ProductAnalyticLoaderStateImplCopyWithImpl<
_$ProductAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _ProductAnalyticLoaderState
implements ProductAnalyticLoaderState {
factory _ProductAnalyticLoaderState({
required final ProductAnalytic productAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$ProductAnalyticLoaderStateImpl;
@override
ProductAnalytic get productAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of ProductAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProductAnalyticLoaderStateImplCopyWith<_$ProductAnalyticLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'product_analytic_loader_bloc.dart';
@freezed
class ProductAnalyticLoaderEvent with _$ProductAnalyticLoaderEvent {
const factory ProductAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,15 @@
part of 'product_analytic_loader_bloc.dart';
@freezed
class ProductAnalyticLoaderState with _$ProductAnalyticLoaderState {
factory ProductAnalyticLoaderState({
required ProductAnalytic productAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _ProductAnalyticLoaderState;
factory ProductAnalyticLoaderState.initial() => ProductAnalyticLoaderState(
productAnalytic: ProductAnalytic.empty(),
failureOption: none(),
);
}
@@ -0,0 +1,52 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'profit_loss_analytic_loader_event.dart';
part 'profit_loss_analytic_loader_state.dart';
part 'profit_loss_analytic_loader_bloc.freezed.dart';
@injectable
class ProfitLossAnalyticLoaderBloc
extends Bloc<ProfitLossAnalyticLoaderEvent, ProfitLossAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
ProfitLossAnalyticLoaderBloc(this._analyticRepository)
: super(ProfitLossAnalyticLoaderState.initial()) {
on<ProfitLossAnalyticLoaderEvent>(_onProfitLossAnalyticLoaderEvent);
}
Future<void> _onProfitLossAnalyticLoaderEvent(
ProfitLossAnalyticLoaderEvent event,
Emitter<ProfitLossAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getProfitLoss(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(profitLoss) async {
emit(
state.copyWith(isFetching: false, profitLossAnalytic: profitLoss),
);
},
);
},
);
}
}
@@ -0,0 +1,483 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'profit_loss_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$ProfitLossAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProfitLossAnalyticLoaderEventCopyWith<ProfitLossAnalyticLoaderEvent>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProfitLossAnalyticLoaderEventCopyWith<$Res> {
factory $ProfitLossAnalyticLoaderEventCopyWith(
ProfitLossAnalyticLoaderEvent value,
$Res Function(ProfitLossAnalyticLoaderEvent) then,
) =
_$ProfitLossAnalyticLoaderEventCopyWithImpl<
$Res,
ProfitLossAnalyticLoaderEvent
>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$ProfitLossAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends ProfitLossAnalyticLoaderEvent
>
implements $ProfitLossAnalyticLoaderEventCopyWith<$Res> {
_$ProfitLossAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $ProfitLossAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$ProfitLossAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'ProfitLossAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements ProfitLossAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of ProfitLossAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$ProfitLossAnalyticLoaderState {
ProfitLossAnalytic get profitLossAnalytic =>
throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ProfitLossAnalyticLoaderStateCopyWith<ProfitLossAnalyticLoaderState>
get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProfitLossAnalyticLoaderStateCopyWith<$Res> {
factory $ProfitLossAnalyticLoaderStateCopyWith(
ProfitLossAnalyticLoaderState value,
$Res Function(ProfitLossAnalyticLoaderState) then,
) =
_$ProfitLossAnalyticLoaderStateCopyWithImpl<
$Res,
ProfitLossAnalyticLoaderState
>;
@useResult
$Res call({
ProfitLossAnalytic profitLossAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$ProfitLossAnalyticCopyWith<$Res> get profitLossAnalytic;
}
/// @nodoc
class _$ProfitLossAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends ProfitLossAnalyticLoaderState
>
implements $ProfitLossAnalyticLoaderStateCopyWith<$Res> {
_$ProfitLossAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? profitLossAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
profitLossAnalytic: null == profitLossAnalytic
? _value.profitLossAnalytic
: profitLossAnalytic // ignore: cast_nullable_to_non_nullable
as ProfitLossAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProfitLossAnalyticCopyWith<$Res> get profitLossAnalytic {
return $ProfitLossAnalyticCopyWith<$Res>(_value.profitLossAnalytic, (
value,
) {
return _then(_value.copyWith(profitLossAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$ProfitLossAnalyticLoaderStateImplCopyWith<$Res>
implements $ProfitLossAnalyticLoaderStateCopyWith<$Res> {
factory _$$ProfitLossAnalyticLoaderStateImplCopyWith(
_$ProfitLossAnalyticLoaderStateImpl value,
$Res Function(_$ProfitLossAnalyticLoaderStateImpl) then,
) = __$$ProfitLossAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
ProfitLossAnalytic profitLossAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$ProfitLossAnalyticCopyWith<$Res> get profitLossAnalytic;
}
/// @nodoc
class __$$ProfitLossAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$ProfitLossAnalyticLoaderStateCopyWithImpl<
$Res,
_$ProfitLossAnalyticLoaderStateImpl
>
implements _$$ProfitLossAnalyticLoaderStateImplCopyWith<$Res> {
__$$ProfitLossAnalyticLoaderStateImplCopyWithImpl(
_$ProfitLossAnalyticLoaderStateImpl _value,
$Res Function(_$ProfitLossAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? profitLossAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$ProfitLossAnalyticLoaderStateImpl(
profitLossAnalytic: null == profitLossAnalytic
? _value.profitLossAnalytic
: profitLossAnalytic // ignore: cast_nullable_to_non_nullable
as ProfitLossAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$ProfitLossAnalyticLoaderStateImpl
implements _ProfitLossAnalyticLoaderState {
_$ProfitLossAnalyticLoaderStateImpl({
required this.profitLossAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final ProfitLossAnalytic profitLossAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'ProfitLossAnalyticLoaderState(profitLossAnalytic: $profitLossAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProfitLossAnalyticLoaderStateImpl &&
(identical(other.profitLossAnalytic, profitLossAnalytic) ||
other.profitLossAnalytic == profitLossAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, profitLossAnalytic, failureOption, isFetching);
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ProfitLossAnalyticLoaderStateImplCopyWith<
_$ProfitLossAnalyticLoaderStateImpl
>
get copyWith =>
__$$ProfitLossAnalyticLoaderStateImplCopyWithImpl<
_$ProfitLossAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _ProfitLossAnalyticLoaderState
implements ProfitLossAnalyticLoaderState {
factory _ProfitLossAnalyticLoaderState({
required final ProfitLossAnalytic profitLossAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$ProfitLossAnalyticLoaderStateImpl;
@override
ProfitLossAnalytic get profitLossAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of ProfitLossAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ProfitLossAnalyticLoaderStateImplCopyWith<
_$ProfitLossAnalyticLoaderStateImpl
>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'profit_loss_analytic_loader_bloc.dart';
@freezed
class ProfitLossAnalyticLoaderEvent with _$ProfitLossAnalyticLoaderEvent {
const factory ProfitLossAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,16 @@
part of 'profit_loss_analytic_loader_bloc.dart';
@freezed
class ProfitLossAnalyticLoaderState with _$ProfitLossAnalyticLoaderState {
factory ProfitLossAnalyticLoaderState({
required ProfitLossAnalytic profitLossAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _ProfitLossAnalyticLoaderState;
factory ProfitLossAnalyticLoaderState.initial() =>
ProfitLossAnalyticLoaderState(
profitLossAnalytic: ProfitLossAnalytic.empty(),
failureOption: none(),
);
}
@@ -0,0 +1,50 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/analytic/analytic.dart';
part 'sales_analytic_loader_event.dart';
part 'sales_analytic_loader_state.dart';
part 'sales_analytic_loader_bloc.freezed.dart';
@injectable
class SalesAnalyticLoaderBloc
extends Bloc<SalesAnalyticLoaderEvent, SalesAnalyticLoaderState> {
final IAnalyticRepository _analyticRepository;
SalesAnalyticLoaderBloc(this._analyticRepository)
: super(SalesAnalyticLoaderState.initial()) {
on<SalesAnalyticLoaderEvent>(_onSalesAnalyticLoaderEvent);
}
Future<void> _onSalesAnalyticLoaderEvent(
SalesAnalyticLoaderEvent event,
Emitter<SalesAnalyticLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _analyticRepository.getSales(
dateFrom: e.startDate,
dateTo: e.endDate,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isFetching: false,
failureOption: optionOf(failure),
),
);
},
(sales) async {
emit(state.copyWith(isFetching: false, salesAnalytic: sales));
},
);
},
);
}
}
@@ -0,0 +1,466 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'sales_analytic_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$SalesAnalyticLoaderEvent {
DateTime get startDate => throw _privateConstructorUsedError;
DateTime get endDate => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of SalesAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$SalesAnalyticLoaderEventCopyWith<SalesAnalyticLoaderEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SalesAnalyticLoaderEventCopyWith<$Res> {
factory $SalesAnalyticLoaderEventCopyWith(
SalesAnalyticLoaderEvent value,
$Res Function(SalesAnalyticLoaderEvent) then,
) = _$SalesAnalyticLoaderEventCopyWithImpl<$Res, SalesAnalyticLoaderEvent>;
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class _$SalesAnalyticLoaderEventCopyWithImpl<
$Res,
$Val extends SalesAnalyticLoaderEvent
>
implements $SalesAnalyticLoaderEventCopyWith<$Res> {
_$SalesAnalyticLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SalesAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_value.copyWith(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $SalesAnalyticLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({DateTime startDate, DateTime endDate});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$SalesAnalyticLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of SalesAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? startDate = null, Object? endDate = null}) {
return _then(
_$FetchedImpl(
startDate: null == startDate
? _value.startDate
: startDate // ignore: cast_nullable_to_non_nullable
as DateTime,
endDate: null == endDate
? _value.endDate
: endDate // ignore: cast_nullable_to_non_nullable
as DateTime,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({required this.startDate, required this.endDate});
@override
final DateTime startDate;
@override
final DateTime endDate;
@override
String toString() {
return 'SalesAnalyticLoaderEvent.fetched(startDate: $startDate, endDate: $endDate)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.startDate, startDate) ||
other.startDate == startDate) &&
(identical(other.endDate, endDate) || other.endDate == endDate));
}
@override
int get hashCode => Object.hash(runtimeType, startDate, endDate);
/// Create a copy of SalesAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(DateTime startDate, DateTime endDate) fetched,
}) {
return fetched(startDate, endDate);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(DateTime startDate, DateTime endDate)? fetched,
}) {
return fetched?.call(startDate, endDate);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DateTime startDate, DateTime endDate)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(startDate, endDate);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements SalesAnalyticLoaderEvent {
const factory _Fetched({
required final DateTime startDate,
required final DateTime endDate,
}) = _$FetchedImpl;
@override
DateTime get startDate;
@override
DateTime get endDate;
/// Create a copy of SalesAnalyticLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$SalesAnalyticLoaderState {
SalesAnalytic get salesAnalytic => throw _privateConstructorUsedError;
Option<AnalyticFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of SalesAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$SalesAnalyticLoaderStateCopyWith<SalesAnalyticLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $SalesAnalyticLoaderStateCopyWith<$Res> {
factory $SalesAnalyticLoaderStateCopyWith(
SalesAnalyticLoaderState value,
$Res Function(SalesAnalyticLoaderState) then,
) = _$SalesAnalyticLoaderStateCopyWithImpl<$Res, SalesAnalyticLoaderState>;
@useResult
$Res call({
SalesAnalytic salesAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
$SalesAnalyticCopyWith<$Res> get salesAnalytic;
}
/// @nodoc
class _$SalesAnalyticLoaderStateCopyWithImpl<
$Res,
$Val extends SalesAnalyticLoaderState
>
implements $SalesAnalyticLoaderStateCopyWith<$Res> {
_$SalesAnalyticLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of SalesAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? salesAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
salesAnalytic: null == salesAnalytic
? _value.salesAnalytic
: salesAnalytic // ignore: cast_nullable_to_non_nullable
as SalesAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
/// Create a copy of SalesAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$SalesAnalyticCopyWith<$Res> get salesAnalytic {
return $SalesAnalyticCopyWith<$Res>(_value.salesAnalytic, (value) {
return _then(_value.copyWith(salesAnalytic: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$SalesAnalyticLoaderStateImplCopyWith<$Res>
implements $SalesAnalyticLoaderStateCopyWith<$Res> {
factory _$$SalesAnalyticLoaderStateImplCopyWith(
_$SalesAnalyticLoaderStateImpl value,
$Res Function(_$SalesAnalyticLoaderStateImpl) then,
) = __$$SalesAnalyticLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
SalesAnalytic salesAnalytic,
Option<AnalyticFailure> failureOption,
bool isFetching,
});
@override
$SalesAnalyticCopyWith<$Res> get salesAnalytic;
}
/// @nodoc
class __$$SalesAnalyticLoaderStateImplCopyWithImpl<$Res>
extends
_$SalesAnalyticLoaderStateCopyWithImpl<
$Res,
_$SalesAnalyticLoaderStateImpl
>
implements _$$SalesAnalyticLoaderStateImplCopyWith<$Res> {
__$$SalesAnalyticLoaderStateImplCopyWithImpl(
_$SalesAnalyticLoaderStateImpl _value,
$Res Function(_$SalesAnalyticLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of SalesAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? salesAnalytic = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$SalesAnalyticLoaderStateImpl(
salesAnalytic: null == salesAnalytic
? _value.salesAnalytic
: salesAnalytic // ignore: cast_nullable_to_non_nullable
as SalesAnalytic,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<AnalyticFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$SalesAnalyticLoaderStateImpl implements _SalesAnalyticLoaderState {
_$SalesAnalyticLoaderStateImpl({
required this.salesAnalytic,
required this.failureOption,
this.isFetching = false,
});
@override
final SalesAnalytic salesAnalytic;
@override
final Option<AnalyticFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'SalesAnalyticLoaderState(salesAnalytic: $salesAnalytic, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SalesAnalyticLoaderStateImpl &&
(identical(other.salesAnalytic, salesAnalytic) ||
other.salesAnalytic == salesAnalytic) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode =>
Object.hash(runtimeType, salesAnalytic, failureOption, isFetching);
/// Create a copy of SalesAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SalesAnalyticLoaderStateImplCopyWith<_$SalesAnalyticLoaderStateImpl>
get copyWith =>
__$$SalesAnalyticLoaderStateImplCopyWithImpl<
_$SalesAnalyticLoaderStateImpl
>(this, _$identity);
}
abstract class _SalesAnalyticLoaderState implements SalesAnalyticLoaderState {
factory _SalesAnalyticLoaderState({
required final SalesAnalytic salesAnalytic,
required final Option<AnalyticFailure> failureOption,
final bool isFetching,
}) = _$SalesAnalyticLoaderStateImpl;
@override
SalesAnalytic get salesAnalytic;
@override
Option<AnalyticFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of SalesAnalyticLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SalesAnalyticLoaderStateImplCopyWith<_$SalesAnalyticLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'sales_analytic_loader_bloc.dart';
@freezed
class SalesAnalyticLoaderEvent with _$SalesAnalyticLoaderEvent {
const factory SalesAnalyticLoaderEvent.fetched({
required DateTime startDate,
required DateTime endDate,
}) = _Fetched;
}
@@ -0,0 +1,15 @@
part of 'sales_analytic_loader_bloc.dart';
@freezed
class SalesAnalyticLoaderState with _$SalesAnalyticLoaderState {
factory SalesAnalyticLoaderState({
required SalesAnalytic salesAnalytic,
required Option<AnalyticFailure> failureOption,
@Default(false) bool isFetching,
}) = _SalesAnalyticLoaderState;
factory SalesAnalyticLoaderState.initial() => SalesAnalyticLoaderState(
failureOption: none(),
salesAnalytic: SalesAnalytic.empty(),
);
}
+4 -4
View File
@@ -33,16 +33,16 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
state.copyWith(
failureOption: optionOf(f),
status: token
? AuthStatus.authenticated()
: AuthStatus.unauthenticated(),
? const AuthStatus.authenticated()
: const AuthStatus.unauthenticated(),
),
),
(user) => emit(
state.copyWith(
user: user,
status: token
? AuthStatus.authenticated()
: AuthStatus.unauthenticated(),
? const AuthStatus.authenticated()
: const AuthStatus.unauthenticated(),
),
),
);
@@ -5,6 +5,8 @@ import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../common/service/device_info_service.dart';
import '../../../common/service/fcm_service.dart';
import '../../../domain/auth/auth.dart';
part 'login_form_event.dart';
@@ -14,7 +16,14 @@ part 'login_form_bloc.freezed.dart';
@injectable
class LoginFormBloc extends Bloc<LoginFormEvent, LoginFormState> {
final IAuthRepository _authRepository;
LoginFormBloc(this._authRepository) : super(LoginFormState.initial()) {
final FcmService _fcmService;
final DeviceInfoService _deviceInfoService;
LoginFormBloc(
this._authRepository,
this._fcmService,
this._deviceInfoService,
) : super(LoginFormState.initial()) {
on<LoginFormEvent>(_onLoginFormEvent);
}
@@ -43,9 +52,14 @@ class LoginFormBloc extends Bloc<LoginFormEvent, LoginFormState> {
);
if (emailValid && passwordValid) {
final fcmToken = await _fcmService.getToken() ?? '';
final devicePayload = await _deviceInfoService.getDevicePayload();
failureOrLogin = await _authRepository.login(
email: state.email,
password: state.password,
fcmToken: fcmToken,
devicePayload: devicePayload,
);
emit(
@@ -0,0 +1,38 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/auth/auth.dart';
part 'logout_event.dart';
part 'logout_state.dart';
part 'logout_bloc.freezed.dart';
@injectable
class LogoutBloc extends Bloc<LogoutEvent, LogoutState> {
final IAuthRepository _authRepository;
LogoutBloc(this._authRepository) : super(LogoutState.initial()) {
on<LogoutEvent>(_onLogoutEvent);
}
Future<void> _onLogoutEvent(LogoutEvent event, Emitter<LogoutState> emit) {
return event.map(
logout: (e) async {
Either<AuthFailure, Unit>? failureOrSuccess;
emit(
state.copyWith(isLoggingOut: true, logoutFailureOrSuccess: none()),
);
failureOrSuccess = await _authRepository.logout();
emit(
state.copyWith(
isLoggingOut: false,
logoutFailureOrSuccess: optionOf(failureOrSuccess),
),
);
},
);
}
}
@@ -0,0 +1,332 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'logout_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$LogoutEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() logout}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? logout}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? logout,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Logout value) logout,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Logout value)? logout,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Logout value)? logout,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LogoutEventCopyWith<$Res> {
factory $LogoutEventCopyWith(
LogoutEvent value,
$Res Function(LogoutEvent) then,
) = _$LogoutEventCopyWithImpl<$Res, LogoutEvent>;
}
/// @nodoc
class _$LogoutEventCopyWithImpl<$Res, $Val extends LogoutEvent>
implements $LogoutEventCopyWith<$Res> {
_$LogoutEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LogoutEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$LogoutImplCopyWith<$Res> {
factory _$$LogoutImplCopyWith(
_$LogoutImpl value,
$Res Function(_$LogoutImpl) then,
) = __$$LogoutImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LogoutImplCopyWithImpl<$Res>
extends _$LogoutEventCopyWithImpl<$Res, _$LogoutImpl>
implements _$$LogoutImplCopyWith<$Res> {
__$$LogoutImplCopyWithImpl(
_$LogoutImpl _value,
$Res Function(_$LogoutImpl) _then,
) : super(_value, _then);
/// Create a copy of LogoutEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LogoutImpl implements _Logout {
const _$LogoutImpl();
@override
String toString() {
return 'LogoutEvent.logout()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$LogoutImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() logout}) {
return logout();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? logout}) {
return logout?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? logout,
required TResult orElse(),
}) {
if (logout != null) {
return logout();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Logout value) logout,
}) {
return logout(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Logout value)? logout,
}) {
return logout?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Logout value)? logout,
required TResult orElse(),
}) {
if (logout != null) {
return logout(this);
}
return orElse();
}
}
abstract class _Logout implements LogoutEvent {
const factory _Logout() = _$LogoutImpl;
}
/// @nodoc
mixin _$LogoutState {
Option<Either<AuthFailure, Unit>> get logoutFailureOrSuccess =>
throw _privateConstructorUsedError;
bool get isLoggingOut => throw _privateConstructorUsedError;
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$LogoutStateCopyWith<LogoutState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LogoutStateCopyWith<$Res> {
factory $LogoutStateCopyWith(
LogoutState value,
$Res Function(LogoutState) then,
) = _$LogoutStateCopyWithImpl<$Res, LogoutState>;
@useResult
$Res call({
Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
bool isLoggingOut,
});
}
/// @nodoc
class _$LogoutStateCopyWithImpl<$Res, $Val extends LogoutState>
implements $LogoutStateCopyWith<$Res> {
_$LogoutStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? logoutFailureOrSuccess = null,
Object? isLoggingOut = null,
}) {
return _then(
_value.copyWith(
logoutFailureOrSuccess: null == logoutFailureOrSuccess
? _value.logoutFailureOrSuccess
: logoutFailureOrSuccess // ignore: cast_nullable_to_non_nullable
as Option<Either<AuthFailure, Unit>>,
isLoggingOut: null == isLoggingOut
? _value.isLoggingOut
: isLoggingOut // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$LogoutStateImplCopyWith<$Res>
implements $LogoutStateCopyWith<$Res> {
factory _$$LogoutStateImplCopyWith(
_$LogoutStateImpl value,
$Res Function(_$LogoutStateImpl) then,
) = __$$LogoutStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
bool isLoggingOut,
});
}
/// @nodoc
class __$$LogoutStateImplCopyWithImpl<$Res>
extends _$LogoutStateCopyWithImpl<$Res, _$LogoutStateImpl>
implements _$$LogoutStateImplCopyWith<$Res> {
__$$LogoutStateImplCopyWithImpl(
_$LogoutStateImpl _value,
$Res Function(_$LogoutStateImpl) _then,
) : super(_value, _then);
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? logoutFailureOrSuccess = null,
Object? isLoggingOut = null,
}) {
return _then(
_$LogoutStateImpl(
logoutFailureOrSuccess: null == logoutFailureOrSuccess
? _value.logoutFailureOrSuccess
: logoutFailureOrSuccess // ignore: cast_nullable_to_non_nullable
as Option<Either<AuthFailure, Unit>>,
isLoggingOut: null == isLoggingOut
? _value.isLoggingOut
: isLoggingOut // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$LogoutStateImpl implements _LogoutState {
_$LogoutStateImpl({
required this.logoutFailureOrSuccess,
this.isLoggingOut = false,
});
@override
final Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess;
@override
@JsonKey()
final bool isLoggingOut;
@override
String toString() {
return 'LogoutState(logoutFailureOrSuccess: $logoutFailureOrSuccess, isLoggingOut: $isLoggingOut)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LogoutStateImpl &&
(identical(other.logoutFailureOrSuccess, logoutFailureOrSuccess) ||
other.logoutFailureOrSuccess == logoutFailureOrSuccess) &&
(identical(other.isLoggingOut, isLoggingOut) ||
other.isLoggingOut == isLoggingOut));
}
@override
int get hashCode =>
Object.hash(runtimeType, logoutFailureOrSuccess, isLoggingOut);
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LogoutStateImplCopyWith<_$LogoutStateImpl> get copyWith =>
__$$LogoutStateImplCopyWithImpl<_$LogoutStateImpl>(this, _$identity);
}
abstract class _LogoutState implements LogoutState {
factory _LogoutState({
required final Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
final bool isLoggingOut,
}) = _$LogoutStateImpl;
@override
Option<Either<AuthFailure, Unit>> get logoutFailureOrSuccess;
@override
bool get isLoggingOut;
/// Create a copy of LogoutState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LogoutStateImplCopyWith<_$LogoutStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'logout_bloc.dart';
@freezed
class LogoutEvent with _$LogoutEvent {
const factory LogoutEvent.logout() = _Logout;
}
@@ -0,0 +1,11 @@
part of 'logout_bloc.dart';
@freezed
class LogoutState with _$LogoutState {
factory LogoutState({
required Option<Either<AuthFailure, Unit>> logoutFailureOrSuccess,
@Default(false) bool isLoggingOut,
}) = _LogoutState;
factory LogoutState.initial() => LogoutState(logoutFailureOrSuccess: none());
}
@@ -0,0 +1,314 @@
import 'dart:async';
import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/category/category.dart';
part 'category_loader_event.dart';
part 'category_loader_state.dart';
part 'category_loader_bloc.freezed.dart';
@injectable
class CategoryLoaderBloc
extends Bloc<CategoryLoaderEvent, CategoryLoaderState> {
final ICategoryRepository _categoryRepository;
Timer? _searchDebounce;
bool _isLoadingMore = false;
CategoryLoaderBloc(this._categoryRepository)
: super(CategoryLoaderState.initial()) {
on<CategoryLoaderEvent>(_onCategoryLoaderEvent);
}
Future<void> _onCategoryLoaderEvent(
CategoryLoaderEvent event,
Emitter<CategoryLoaderState> emit,
) {
return event.map(
getCategories: (e) async {
emit(state.copyWith(isLoadingMore: true));
log(
'📱 Loading categories - isActive: ${e.isActive}, forceRemote: ${e.forceRemote}',
);
final result = await _categoryRepository.getCategories(
page: 1,
limit: 50,
isActive: e.isActive,
search: e.search,
forceRemote: e.forceRemote,
);
await result.fold(
(failure) async {
emit(
state.copyWith(
isLoadingMore: false,
failureOptionCategory: optionOf(failure),
),
);
},
(response) async {
final categories = [Category.all(), ...response.categories];
final totalPages = response.totalPages;
final hasReachedMax = categories.length < 50 || 1 >= totalPages;
log(
'âś… Categories loaded: ${categories.length}, hasReachedMax: $hasReachedMax',
);
emit(
state.copyWith(
categories: categories,
page: 1,
hasReachedMax: hasReachedMax,
isLoadingMore: false,
failureOptionCategory: none(),
),
);
},
);
},
loadMore: (e) async {
final currentState = state;
// ❌ HAPUS pengecekan is! _Loaded karena state cuma 1 class doang
if (currentState.hasReachedMax ||
_isLoadingMore ||
currentState.isLoadingMore) {
log(
'⏹️ Load more blocked - hasReachedMax: ${currentState.hasReachedMax}, isLoadingMore: $_isLoadingMore',
);
return;
}
_isLoadingMore = true;
emit(currentState.copyWith(isLoadingMore: true));
final nextPage = currentState.page + 1; // âś… Ganti currentPage jadi page
log('đź“„ Loading more categories - page: $nextPage');
try {
final result = await _categoryRepository.getCategories(
page: nextPage,
limit: 10,
isActive: true,
search: currentState.searchQuery,
);
await result.fold(
(failure) async {
log('❌ Error loading more categories: $failure');
emit(currentState.copyWith(isLoadingMore: false));
},
(response) async {
final newCategories = response.categories;
final totalPages = response.totalPages;
// Prevent duplicate categories
final currentCategoryIds = currentState.categories
.map((c) => c.id)
.toSet();
final filteredNewCategories = newCategories
.where(
(category) => !currentCategoryIds.contains(category.id),
)
.toList();
final allCategories = List<Category>.from(currentState.categories)
..addAll(filteredNewCategories);
final hasReachedMax =
newCategories.length < 10 || nextPage >= totalPages;
log(
'âś… More categories loaded: ${filteredNewCategories.length} new, total: ${allCategories.length}',
);
emit(
currentState.copyWith(
categories: allCategories,
hasReachedMax: hasReachedMax,
page: nextPage, // âś… Update page
isLoadingMore: false,
),
);
},
);
} catch (e) {
log('❌ Exception loading more categories: $e');
emit(currentState.copyWith(isLoadingMore: false));
} finally {
_isLoadingMore = false;
}
},
refresh: (e) async {
final currentState = state;
bool isActive = true;
String? searchQuery = currentState.searchQuery;
_isLoadingMore = false;
_searchDebounce?.cancel();
log('🔄 Refreshing categories');
// Clear local cache
_categoryRepository.clearCache();
add(
CategoryLoaderEvent.getCategories(
isActive: isActive,
search: searchQuery,
forceRemote: true, // Force remote refresh
),
);
},
search: (e) async {
// Cancel previous search
_searchDebounce?.cancel();
// Debounce search for better UX
_searchDebounce = Timer(const Duration(milliseconds: 300), () async {
emit(state.copyWith(isLoadingMore: true));
_isLoadingMore = false;
log('🔍 Searching categories: "${e.query}"');
final result = await _categoryRepository.getCategories(
page: 1,
limit: 20, // More results for search
isActive: e.isActive,
search: e.query,
);
await result.fold(
(failure) async {
log('❌ Search error: $failure');
emit(
state.copyWith(
isLoadingMore: false,
failureOptionCategory: optionOf(failure),
),
);
},
(response) async {
final categories = [Category.all(), ...response.categories];
final totalPages = response.totalPages;
final hasReachedMax = categories.length < 20 || 1 >= totalPages;
log('âś… Search results: ${categories.length} categories found');
emit(
state.copyWith(
categories: categories,
hasReachedMax: hasReachedMax,
page: 1,
isLoadingMore: false,
failureOptionCategory: none(),
searchQuery: e.query,
),
);
},
);
});
},
syncAll: (e) async {
emit(state.copyWith(isLoadingMore: true));
log('🔄 Starting full category sync...');
final result = await _categoryRepository.syncAllCategories();
await result.fold(
(failure) async {
log('❌ Sync failed: $failure');
emit(
state.copyWith(
isLoadingMore: false,
failureOptionCategory: optionOf(failure),
),
);
// After sync error, try to load local data
Timer(const Duration(seconds: 2), () {
add(const CategoryLoaderEvent.getCategories());
});
},
(successMessage) async {
log('âś… Sync completed: $successMessage');
emit(
state.copyWith(
isLoadingMore: false,
failureOptionCategory: none(),
),
);
// After successful sync, load the updated data
Timer(const Duration(seconds: 1), () {
add(const CategoryLoaderEvent.getCategories());
});
},
);
},
getAllCategories: (e) async {
try {
log('đź“‹ Loading all categories for dropdown...');
// final categories = await _categoryRepository.getAllCategories();
// emit(
// state.copyWith(
// categories: categories,
// isLoadingMore: false,
// failureOptionCategory: none(),
// ),
// );
// log('âś… All categories loaded: ${categories.length}');
} catch (e) {
log('❌ Error loading all categories: $e');
emit(
state.copyWith(
isLoadingMore: false,
failureOptionCategory: optionOf(
CategoryFailure.dynamicErrorMessage(
'Gagal memuat semua kategori: $e',
),
),
),
);
}
},
getDatabaseStats: (e) async {
try {
final stats = await _categoryRepository.getDatabaseStats();
log('📊 Category database stats retrieved: $stats');
// You can emit a special state here if needed for UI updates
// For now, just log the stats
} catch (e) {
log('❌ Error getting category database stats: $e');
}
},
clearCache: (e) async {
log('đź§ą Manually clearing category cache');
_categoryRepository.clearCache();
// Refresh current data after cache clear
add(const CategoryLoaderEvent.refresh());
},
);
}
@override
Future<void> close() {
_searchDebounce?.cancel();
return super.close();
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,27 @@
part of 'category_loader_bloc.dart';
@freezed
class CategoryLoaderEvent with _$CategoryLoaderEvent {
const factory CategoryLoaderEvent.getCategories({
@Default(true) bool isActive,
String? search,
@Default(false) bool forceRemote,
}) = _GetCategories;
const factory CategoryLoaderEvent.loadMore() = _LoadMore;
const factory CategoryLoaderEvent.refresh() = _Refresh;
const factory CategoryLoaderEvent.search({
required String query,
@Default(true) bool isActive,
}) = _Search;
const factory CategoryLoaderEvent.syncAll() = _SyncAll;
const factory CategoryLoaderEvent.getAllCategories() = _GetAllCategories;
const factory CategoryLoaderEvent.getDatabaseStats() = _GetDatabaseStats;
const factory CategoryLoaderEvent.clearCache() = _ClearCache;
}
@@ -0,0 +1,16 @@
part of 'category_loader_bloc.dart';
@freezed
class CategoryLoaderState with _$CategoryLoaderState {
factory CategoryLoaderState({
required List<Category> categories,
required Option<CategoryFailure> failureOptionCategory,
@Default(false) bool hasReachedMax,
@Default(1) int page,
@Default(false) bool isLoadingMore,
String? searchQuery,
}) = _CategoryLoaderState;
factory CategoryLoaderState.initial() =>
CategoryLoaderState(categories: [], failureOptionCategory: none());
}
@@ -0,0 +1,188 @@
import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart' hide Order;
import '../../../common/types/order_type.dart';
import '../../../domain/delivery/delivery.dart';
import '../../../domain/order/order.dart';
import '../../../domain/product/product.dart';
import '../../../domain/table/table.dart';
part 'checkout_form_event.dart';
part 'checkout_form_state.dart';
part 'checkout_form_bloc.freezed.dart';
@injectable
class CheckoutFormBloc extends Bloc<CheckoutFormEvent, CheckoutFormState> {
CheckoutFormBloc() : super(CheckoutFormState.initial()) {
on<CheckoutFormEvent>(_onCheckoutFormEvent);
}
Future<void> _onCheckoutFormEvent(
CheckoutFormEvent event,
Emitter<CheckoutFormState> emit,
) {
return event.map(
addItem: (e) async {
final currentState = state;
emit(currentState.copyWith(isLoading: true));
List<ProductQuantity> items = [...currentState.items];
final index = items.indexWhere(
(element) =>
element.product.id == e.product.id &&
element.variant?.id == e.variant?.id,
);
if (index != -1) {
// Jika sudah ada → tambah quantity
items[index] = items[index].copyWith(
quantity: items[index].quantity + 1,
);
} else {
// Jika belum ada → tambahkan item baru
items.add(
ProductQuantity(
product: e.product,
quantity: 1,
variant: e.variant,
notes: '',
),
);
}
log('đź›’ Items updated: ${items.length} items total ${items.toList()}');
final totalQuantity = items.fold<int>(
0,
(sum, item) => sum + item.quantity,
);
final totalPrice = state.items.isEmpty
? 0.0
: state.items
.map(
(e) =>
(e.product.price * e.quantity) +
(e.variant?.priceModifier ?? 0),
)
.reduce((value, element) => value + element);
emit(
currentState.copyWith(
items: items,
totalQuantity: totalQuantity,
totalPrice: totalPrice.toInt(),
isLoading: false,
),
);
},
removeItem: (e) async {
final currentState = state;
emit(currentState.copyWith(isLoading: true));
List<ProductQuantity> items = [...currentState.items];
final index = items.indexWhere(
(element) =>
element.product.id == e.product.id &&
element.variant?.id == e.variant?.id,
);
if (index != -1) {
final currentItem = items[index];
if (currentItem.quantity > 1) {
// Kurangi quantity
items[index] = currentItem.copyWith(
quantity: currentItem.quantity - 1,
);
} else {
// Hapus item kalau quantity = 1
items.removeAt(index);
}
}
final totalQuantity = items.fold<int>(
0,
(sum, item) => sum + item.quantity,
);
final totalPrice = items.fold<int>(
0,
(sum, item) =>
sum +
(item.quantity *
(item.variant?.priceModifier.toInt() ??
item.product.price.toInt())),
);
log(
'🗑️ Item removed. Total items: ${items.length}, totalQuantity: $totalQuantity, totalPrice: $totalPrice',
);
// Emit state baru
emit(
currentState.copyWith(
items: items,
totalQuantity: totalQuantity,
totalPrice: totalPrice,
isLoading: false,
),
);
},
started: (e) async {
emit(CheckoutFormState.initial().copyWith(isLoading: true));
try {
emit(
CheckoutFormState.initial().copyWith(
items: e.items,
tax: 0,
serviceCharge: 0,
isLoading: false,
),
);
} catch (e) {
// Kalau gagal, pakai default values
log('⚠️ Failed to load settings: $e');
emit(
CheckoutFormState.initial().copyWith(
tax: 10,
serviceCharge: 5,
isLoading: false,
),
);
}
},
updateItemNotes: (e) async {
final currentState = state;
// Clone list items agar tidak mutasi langsung
final items = [...currentState.items];
final index = items.indexWhere(
(element) => element.product.id == e.product.id,
);
if (index != -1) {
items[index] = items[index].copyWith(notes: e.notes);
}
emit(currentState.copyWith(items: items, isLoading: false));
},
updateOrderType: (e) async {
emit(state.copyWith(orderType: e.orderType));
},
updateDelivery: (e) async {
emit(state.copyWith(delivery: e.delivery));
},
updateTable: (e) async {
emit(state.copyWith(table: e.table));
},
orderAddedItems: (e) async {
emit(state.copyWith(orderAdded: e.order));
},
customerNameChanged: (e) async {
emit(state.copyWith(customerName: e.name,));
}
);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
part of 'checkout_form_bloc.dart';
@freezed
class CheckoutFormEvent with _$CheckoutFormEvent {
const factory CheckoutFormEvent.started(List<ProductQuantity> items) =
_Started;
const factory CheckoutFormEvent.addItem(
Product product,
ProductVariant? variant,
) = _AddItem;
const factory CheckoutFormEvent.removeItem(
Product product,
ProductVariant? variant,
) = _RemoveItem;
const factory CheckoutFormEvent.updateItemNotes(
Product product,
String notes,
) = _UpdateItemNotes;
const factory CheckoutFormEvent.updateOrderType(OrderType orderType) =
_UpdateOrderType;
const factory CheckoutFormEvent.updateDelivery(Delivery delivery) =
_UpdateDelivery;
const factory CheckoutFormEvent.updateTable(Table? table) = _UpdateTable;
const factory CheckoutFormEvent.orderAddedItems(Order? order) =
_OrderAddedItems;
const factory CheckoutFormEvent.customerNameChanged(String name) =
_CustomerNameChanged;
}
@@ -0,0 +1,34 @@
part of 'checkout_form_bloc.dart';
@freezed
class CheckoutFormState with _$CheckoutFormState {
factory CheckoutFormState({
Order? orderAdded,
required List<ProductQuantity> items,
required int discount,
required int discountAmount,
required int tax,
required int serviceCharge,
required int totalQuantity,
required int totalPrice,
required String draftName,
required OrderType orderType,
required String customerName,
Delivery? delivery,
Table? table,
@Default(false) bool isLoading,
}) = _CheckoutFormState;
factory CheckoutFormState.initial() => CheckoutFormState(
items: [],
discount: 0,
discountAmount: 0,
tax: 0,
serviceCharge: 0,
totalQuantity: 0,
totalPrice: 0,
draftName: '',
customerName: '',
orderType: OrderType.dineIn,
);
}
@@ -0,0 +1,82 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/customer/customer.dart';
part 'customer_loader_event.dart';
part 'customer_loader_state.dart';
part 'customer_loader_bloc.freezed.dart';
@injectable
class CustomerLoaderBloc
extends Bloc<CustomerLoaderEvent, CustomerLoaderState> {
final ICustomerRepository _repository;
CustomerLoaderBloc(this._repository) : super(CustomerLoaderState.initial()) {
on<CustomerLoaderEvent>(_onCustomerLoaderEvent);
}
Future<void> _onCustomerLoaderEvent(
CustomerLoaderEvent event,
Emitter<CustomerLoaderState> emit,
) {
return event.map(
fetched: (e) async {
var newState = state;
if (e.isRefresh) {
newState = newState.copyWith(isFetching: true);
emit(newState);
}
newState = await _mapFetchedToState(newState, isRefresh: e.isRefresh);
emit(newState);
},
setSelectedCustomer: (e) async {
emit(state.copyWith(selectedCustomer: e.customer));
},
);
}
Future<CustomerLoaderState> _mapFetchedToState(
CustomerLoaderState state, {
bool isRefresh = false,
}) async {
state = state.copyWith(isFetching: false);
if (state.hasReachedMax && state.customers.isNotEmpty && !isRefresh) {
return state;
}
if (isRefresh) {
state = state.copyWith(
page: 1,
failureOrOption: none(),
hasReachedMax: false,
customers: [],
);
}
final failureOrCustomer = await _repository.getCustomer(page: state.page);
state = failureOrCustomer.fold(
(f) {
if (state.customers.isNotEmpty) {
return state.copyWith(hasReachedMax: true);
}
return state.copyWith(failureOrOption: optionOf(f));
},
(customers) {
return state.copyWith(
customers: List.from(state.customers)..addAll(customers.customers),
failureOrOption: none(),
page: state.page + 1,
hasReachedMax: customers.customers.length < 10,
);
},
);
return state;
}
}
@@ -0,0 +1,668 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'customer_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$CustomerLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(Customer customer) setSelectedCustomer,
required TResult Function(bool isRefresh) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Customer customer)? setSelectedCustomer,
TResult? Function(bool isRefresh)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(Customer customer)? setSelectedCustomer,
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_SetSelectedCustomer value) setSelectedCustomer,
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_SetSelectedCustomer value)? setSelectedCustomer,
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_SetSelectedCustomer value)? setSelectedCustomer,
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CustomerLoaderEventCopyWith<$Res> {
factory $CustomerLoaderEventCopyWith(
CustomerLoaderEvent value,
$Res Function(CustomerLoaderEvent) then,
) = _$CustomerLoaderEventCopyWithImpl<$Res, CustomerLoaderEvent>;
}
/// @nodoc
class _$CustomerLoaderEventCopyWithImpl<$Res, $Val extends CustomerLoaderEvent>
implements $CustomerLoaderEventCopyWith<$Res> {
_$CustomerLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$SetSelectedCustomerImplCopyWith<$Res> {
factory _$$SetSelectedCustomerImplCopyWith(
_$SetSelectedCustomerImpl value,
$Res Function(_$SetSelectedCustomerImpl) then,
) = __$$SetSelectedCustomerImplCopyWithImpl<$Res>;
@useResult
$Res call({Customer customer});
$CustomerCopyWith<$Res> get customer;
}
/// @nodoc
class __$$SetSelectedCustomerImplCopyWithImpl<$Res>
extends _$CustomerLoaderEventCopyWithImpl<$Res, _$SetSelectedCustomerImpl>
implements _$$SetSelectedCustomerImplCopyWith<$Res> {
__$$SetSelectedCustomerImplCopyWithImpl(
_$SetSelectedCustomerImpl _value,
$Res Function(_$SetSelectedCustomerImpl) _then,
) : super(_value, _then);
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? customer = null}) {
return _then(
_$SetSelectedCustomerImpl(
null == customer
? _value.customer
: customer // ignore: cast_nullable_to_non_nullable
as Customer,
),
);
}
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$CustomerCopyWith<$Res> get customer {
return $CustomerCopyWith<$Res>(_value.customer, (value) {
return _then(_value.copyWith(customer: value));
});
}
}
/// @nodoc
class _$SetSelectedCustomerImpl implements _SetSelectedCustomer {
const _$SetSelectedCustomerImpl(this.customer);
@override
final Customer customer;
@override
String toString() {
return 'CustomerLoaderEvent.setSelectedCustomer(customer: $customer)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SetSelectedCustomerImpl &&
(identical(other.customer, customer) ||
other.customer == customer));
}
@override
int get hashCode => Object.hash(runtimeType, customer);
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SetSelectedCustomerImplCopyWith<_$SetSelectedCustomerImpl> get copyWith =>
__$$SetSelectedCustomerImplCopyWithImpl<_$SetSelectedCustomerImpl>(
this,
_$identity,
);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(Customer customer) setSelectedCustomer,
required TResult Function(bool isRefresh) fetched,
}) {
return setSelectedCustomer(customer);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Customer customer)? setSelectedCustomer,
TResult? Function(bool isRefresh)? fetched,
}) {
return setSelectedCustomer?.call(customer);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(Customer customer)? setSelectedCustomer,
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) {
if (setSelectedCustomer != null) {
return setSelectedCustomer(customer);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_SetSelectedCustomer value) setSelectedCustomer,
required TResult Function(_Fetched value) fetched,
}) {
return setSelectedCustomer(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_SetSelectedCustomer value)? setSelectedCustomer,
TResult? Function(_Fetched value)? fetched,
}) {
return setSelectedCustomer?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_SetSelectedCustomer value)? setSelectedCustomer,
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (setSelectedCustomer != null) {
return setSelectedCustomer(this);
}
return orElse();
}
}
abstract class _SetSelectedCustomer implements CustomerLoaderEvent {
const factory _SetSelectedCustomer(final Customer customer) =
_$SetSelectedCustomerImpl;
Customer get customer;
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SetSelectedCustomerImplCopyWith<_$SetSelectedCustomerImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@useResult
$Res call({bool isRefresh});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$CustomerLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? isRefresh = null}) {
return _then(
_$FetchedImpl(
isRefresh: null == isRefresh
? _value.isRefresh
: isRefresh // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({this.isRefresh = false});
@override
@JsonKey()
final bool isRefresh;
@override
String toString() {
return 'CustomerLoaderEvent.fetched(isRefresh: $isRefresh)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.isRefresh, isRefresh) ||
other.isRefresh == isRefresh));
}
@override
int get hashCode => Object.hash(runtimeType, isRefresh);
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(Customer customer) setSelectedCustomer,
required TResult Function(bool isRefresh) fetched,
}) {
return fetched(isRefresh);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(Customer customer)? setSelectedCustomer,
TResult? Function(bool isRefresh)? fetched,
}) {
return fetched?.call(isRefresh);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(Customer customer)? setSelectedCustomer,
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(isRefresh);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_SetSelectedCustomer value) setSelectedCustomer,
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_SetSelectedCustomer value)? setSelectedCustomer,
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_SetSelectedCustomer value)? setSelectedCustomer,
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements CustomerLoaderEvent {
const factory _Fetched({final bool isRefresh}) = _$FetchedImpl;
bool get isRefresh;
/// Create a copy of CustomerLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$CustomerLoaderState {
List<Customer> get customers => throw _privateConstructorUsedError;
Option<CustomerFailure> get failureOrOption =>
throw _privateConstructorUsedError;
Customer? get selectedCustomer => throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
bool get hasReachedMax => throw _privateConstructorUsedError;
int get page => throw _privateConstructorUsedError;
/// Create a copy of CustomerLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CustomerLoaderStateCopyWith<CustomerLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CustomerLoaderStateCopyWith<$Res> {
factory $CustomerLoaderStateCopyWith(
CustomerLoaderState value,
$Res Function(CustomerLoaderState) then,
) = _$CustomerLoaderStateCopyWithImpl<$Res, CustomerLoaderState>;
@useResult
$Res call({
List<Customer> customers,
Option<CustomerFailure> failureOrOption,
Customer? selectedCustomer,
bool isFetching,
bool hasReachedMax,
int page,
});
$CustomerCopyWith<$Res>? get selectedCustomer;
}
/// @nodoc
class _$CustomerLoaderStateCopyWithImpl<$Res, $Val extends CustomerLoaderState>
implements $CustomerLoaderStateCopyWith<$Res> {
_$CustomerLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CustomerLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? customers = null,
Object? failureOrOption = null,
Object? selectedCustomer = freezed,
Object? isFetching = null,
Object? hasReachedMax = null,
Object? page = null,
}) {
return _then(
_value.copyWith(
customers: null == customers
? _value.customers
: customers // ignore: cast_nullable_to_non_nullable
as List<Customer>,
failureOrOption: null == failureOrOption
? _value.failureOrOption
: failureOrOption // ignore: cast_nullable_to_non_nullable
as Option<CustomerFailure>,
selectedCustomer: freezed == selectedCustomer
? _value.selectedCustomer
: selectedCustomer // ignore: cast_nullable_to_non_nullable
as Customer?,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
hasReachedMax: null == hasReachedMax
? _value.hasReachedMax
: hasReachedMax // ignore: cast_nullable_to_non_nullable
as bool,
page: null == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int,
)
as $Val,
);
}
/// Create a copy of CustomerLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$CustomerCopyWith<$Res>? get selectedCustomer {
if (_value.selectedCustomer == null) {
return null;
}
return $CustomerCopyWith<$Res>(_value.selectedCustomer!, (value) {
return _then(_value.copyWith(selectedCustomer: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$CustomerLoaderStateImplCopyWith<$Res>
implements $CustomerLoaderStateCopyWith<$Res> {
factory _$$CustomerLoaderStateImplCopyWith(
_$CustomerLoaderStateImpl value,
$Res Function(_$CustomerLoaderStateImpl) then,
) = __$$CustomerLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
List<Customer> customers,
Option<CustomerFailure> failureOrOption,
Customer? selectedCustomer,
bool isFetching,
bool hasReachedMax,
int page,
});
@override
$CustomerCopyWith<$Res>? get selectedCustomer;
}
/// @nodoc
class __$$CustomerLoaderStateImplCopyWithImpl<$Res>
extends _$CustomerLoaderStateCopyWithImpl<$Res, _$CustomerLoaderStateImpl>
implements _$$CustomerLoaderStateImplCopyWith<$Res> {
__$$CustomerLoaderStateImplCopyWithImpl(
_$CustomerLoaderStateImpl _value,
$Res Function(_$CustomerLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of CustomerLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? customers = null,
Object? failureOrOption = null,
Object? selectedCustomer = freezed,
Object? isFetching = null,
Object? hasReachedMax = null,
Object? page = null,
}) {
return _then(
_$CustomerLoaderStateImpl(
customers: null == customers
? _value._customers
: customers // ignore: cast_nullable_to_non_nullable
as List<Customer>,
failureOrOption: null == failureOrOption
? _value.failureOrOption
: failureOrOption // ignore: cast_nullable_to_non_nullable
as Option<CustomerFailure>,
selectedCustomer: freezed == selectedCustomer
? _value.selectedCustomer
: selectedCustomer // ignore: cast_nullable_to_non_nullable
as Customer?,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
hasReachedMax: null == hasReachedMax
? _value.hasReachedMax
: hasReachedMax // ignore: cast_nullable_to_non_nullable
as bool,
page: null == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int,
),
);
}
}
/// @nodoc
class _$CustomerLoaderStateImpl implements _CustomerLoaderState {
_$CustomerLoaderStateImpl({
required final List<Customer> customers,
required this.failureOrOption,
this.selectedCustomer,
this.isFetching = false,
this.hasReachedMax = false,
this.page = 1,
}) : _customers = customers;
final List<Customer> _customers;
@override
List<Customer> get customers {
if (_customers is EqualUnmodifiableListView) return _customers;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_customers);
}
@override
final Option<CustomerFailure> failureOrOption;
@override
final Customer? selectedCustomer;
@override
@JsonKey()
final bool isFetching;
@override
@JsonKey()
final bool hasReachedMax;
@override
@JsonKey()
final int page;
@override
String toString() {
return 'CustomerLoaderState(customers: $customers, failureOrOption: $failureOrOption, selectedCustomer: $selectedCustomer, isFetching: $isFetching, hasReachedMax: $hasReachedMax, page: $page)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CustomerLoaderStateImpl &&
const DeepCollectionEquality().equals(
other._customers,
_customers,
) &&
(identical(other.failureOrOption, failureOrOption) ||
other.failureOrOption == failureOrOption) &&
(identical(other.selectedCustomer, selectedCustomer) ||
other.selectedCustomer == selectedCustomer) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching) &&
(identical(other.hasReachedMax, hasReachedMax) ||
other.hasReachedMax == hasReachedMax) &&
(identical(other.page, page) || other.page == page));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_customers),
failureOrOption,
selectedCustomer,
isFetching,
hasReachedMax,
page,
);
/// Create a copy of CustomerLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CustomerLoaderStateImplCopyWith<_$CustomerLoaderStateImpl> get copyWith =>
__$$CustomerLoaderStateImplCopyWithImpl<_$CustomerLoaderStateImpl>(
this,
_$identity,
);
}
abstract class _CustomerLoaderState implements CustomerLoaderState {
factory _CustomerLoaderState({
required final List<Customer> customers,
required final Option<CustomerFailure> failureOrOption,
final Customer? selectedCustomer,
final bool isFetching,
final bool hasReachedMax,
final int page,
}) = _$CustomerLoaderStateImpl;
@override
List<Customer> get customers;
@override
Option<CustomerFailure> get failureOrOption;
@override
Customer? get selectedCustomer;
@override
bool get isFetching;
@override
bool get hasReachedMax;
@override
int get page;
/// Create a copy of CustomerLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CustomerLoaderStateImplCopyWith<_$CustomerLoaderStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'customer_loader_bloc.dart';
@freezed
class CustomerLoaderEvent with _$CustomerLoaderEvent {
const factory CustomerLoaderEvent.setSelectedCustomer(Customer customer) =
_SetSelectedCustomer;
const factory CustomerLoaderEvent.fetched({@Default(false) bool isRefresh}) =
_Fetched;
}
@@ -0,0 +1,16 @@
part of 'customer_loader_bloc.dart';
@freezed
class CustomerLoaderState with _$CustomerLoaderState {
factory CustomerLoaderState({
required List<Customer> customers,
required Option<CustomerFailure> failureOrOption,
Customer? selectedCustomer,
@Default(false) bool isFetching,
@Default(false) bool hasReachedMax,
@Default(1) int page,
}) = _CustomerLoaderState;
factory CustomerLoaderState.initial() =>
CustomerLoaderState(customers: [], failureOrOption: none());
}
@@ -0,0 +1,169 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart' hide Order;
import 'package:uuid/uuid.dart';
import '../../../common/types/order_type.dart';
import '../../../domain/customer/customer.dart';
import '../../../domain/order/order.dart';
import '../../../domain/outlet/outlet.dart';
import '../../../domain/payment_method/payment_method.dart';
import '../../../domain/product/product.dart';
import '../../../domain/table/table.dart';
part 'order_form_event.dart';
part 'order_form_state.dart';
part 'order_form_bloc.freezed.dart';
@injectable
class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
final IOrderRepository _repository;
final IOutletRepository _outletRepository;
OrderFormBloc(this._repository, this._outletRepository)
: super(OrderFormState.initial()) {
on<OrderFormEvent>(_onOrderFormBloc);
}
Future<void> _onOrderFormBloc(
OrderFormEvent event,
Emitter<OrderFormState> emit,
) {
return event.map(
customerNameChanged: (e) async {
emit(state.copyWith(customerName: e.customerName));
},
paymentMethodChanged: (e) async {
emit(state.copyWith(paymentMethod: e.payment));
},
customerChanged: (e) async {
emit(state.copyWith(customer: e.customer));
},
createOrderWithPayment: (e) async {
Either<OrderFailure, Order> failureOrOrder;
emit(
state.copyWith(
isCreatingWithPayment: true,
failureOrCreateOrderWithPayment: none(),
),
);
final outlet = await _outletRepository.currentOutlet();
final request = OrderRequest(
outletId: outlet.id,
customerId: state.customer?.id ?? '',
tableNumber: e.table?.tableName ?? '',
tableId: e.table?.id ?? '',
orderType: e.orderType.name,
notes: '',
customerName: state.customerName ?? "",
orderItems: e.items
.map(
(item) => OrderItemRequest(
productId: item.product.id,
productVariantId: item.variant?.id ?? "",
quantity: item.quantity,
unitPrice: item.product.price.toInt(),
notes: item.notes,
),
)
.toList(),
);
failureOrOrder = await _repository.createOrderWithPayment(
request: request,
paymentMethodId: state.paymentMethod?.id ?? '',
);
emit(
state.copyWith(
isCreatingWithPayment: false,
failureOrCreateOrderWithPayment: optionOf(failureOrOrder),
),
);
},
createOrder: (e) async {
Either<OrderFailure, Order> failureOrOrder;
emit(state.copyWith(isCreating: true, failureOrCreateOrder: none()));
final outlet = await _outletRepository.currentOutlet();
final request = OrderRequest(
outletId: outlet.id,
customerId: state.customer?.id ?? '',
tableNumber: e.table?.tableName ?? '',
tableId: e.table?.id ?? '',
orderType: e.orderType.name,
notes: '',
customerName: state.customerName ?? "",
orderItems: e.items
.map(
(item) => OrderItemRequest(
productId: item.product.id,
productVariantId: item.variant?.id ?? "",
quantity: item.quantity,
unitPrice: item.product.price.toInt(),
notes: item.notes,
),
)
.toList(),
);
failureOrOrder = await _repository.createOrder(request: request);
emit(
state.copyWith(
isCreating: false,
failureOrCreateOrder: optionOf(failureOrOrder),
),
);
},
addItemOrder: (e) async {
Either<OrderFailure, Order> failureOrAddItemOrder;
// Generate new idempotency key saat user intent (tap Add Items)
// Kalau sedang retry, pakai key yang sama
final idempotencyKey = state.addItemIdempotencyKey ?? const Uuid().v4();
emit(
state.copyWith(
isAddingItemOrder: true,
failureOrAddItemOrder: none(),
addItemIdempotencyKey: idempotencyKey,
),
);
final request = e.items
.map(
(item) => AddItemOrderRequest(
productId: item.product.id,
productVariantId: item.variant?.id ?? '',
quantity: item.quantity,
unitPrice: item.product.price.toInt(),
notes: item.notes,
),
)
.toList();
failureOrAddItemOrder = await _repository.addItemOrder(
id: e.orderId,
request: request,
idempotencyKey: idempotencyKey,
);
emit(
state.copyWith(
isAddingItemOrder: false,
failureOrAddItemOrder: optionOf(failureOrAddItemOrder),
// Clear key on success, keep on failure for retry
addItemIdempotencyKey:
failureOrAddItemOrder.isRight() ? null : idempotencyKey,
),
);
},
);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,27 @@
part of 'order_form_bloc.dart';
@freezed
class OrderFormEvent with _$OrderFormEvent {
const factory OrderFormEvent.customerNameChanged(String customerName) =
_CustomerNameChanged;
const factory OrderFormEvent.paymentMethodChanged(PaymentMethod payment) =
_PaymentMethodChanged;
const factory OrderFormEvent.customerChanged(Customer? customer) =
_CustomerChanged;
const factory OrderFormEvent.createOrderWithPayment({
required List<ProductQuantity> items,
required OrderType orderType,
Table? table,
}) = _CreateOrderWithPayment;
const factory OrderFormEvent.createOrder({
required List<ProductQuantity> items,
required OrderType orderType,
Table? table,
}) = _CreateOrder;
const factory OrderFormEvent.addItemOrder({
required String orderId,
required List<ProductQuantity> items,
}) = _AddItemOrder;
}
@@ -0,0 +1,27 @@
part of 'order_form_bloc.dart';
@freezed
class OrderFormState with _$OrderFormState {
factory OrderFormState({
PaymentMethod? paymentMethod,
String? customerName,
Customer? customer,
required Option<Either<OrderFailure, Order>> failureOrCreateOrder,
required Option<Either<OrderFailure, Order>>
failureOrCreateOrderWithPayment,
required Option<Either<OrderFailure, Order>> failureOrAddItemOrder,
@Default(false) bool isCreating,
@Default(false) bool isCreatingWithPayment,
@Default(false) bool isAddingItemOrder,
/// Idempotency key untuk add item order.
/// Di-generate saat user tap "Add Items", dipakai ulang saat retry,
/// di-clear setelah sukses.
String? addItemIdempotencyKey,
}) = _OrderFormState;
factory OrderFormState.initial() => OrderFormState(
failureOrCreateOrder: none(),
failureOrCreateOrderWithPayment: none(),
failureOrAddItemOrder: none(),
);
}
@@ -0,0 +1,118 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart' hide Order;
import '../../../domain/order/order.dart';
part 'order_loader_event.dart';
part 'order_loader_state.dart';
part 'order_loader_bloc.freezed.dart';
@injectable
class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
final IOrderRepository _repository;
OrderLoaderBloc(this._repository) : super(OrderLoaderState.initial()) {
on<OrderLoaderEvent>(_onOrderLoaderEvent);
}
Future<void> _onOrderLoaderEvent(
OrderLoaderEvent event,
Emitter<OrderLoaderState> emit,
) {
return event.map(
setSelectedOrder: (e) async {
emit(state.copyWith(selectedOrder: e.order));
},
dateTimeRangeChange: (e) async {
emit(state.copyWith(startDate: e.startDate, endDate: e.endDate));
},
searchChange: (e) async {
emit(state.copyWith(search: e.search));
},
fetched: (e) async {
var newState = state;
if (e.isRefresh) {
newState = newState.copyWith(isFetching: true);
emit(newState);
}
newState = await _mapFetchedToState(
newState,
isRefresh: e.isRefresh,
status: e.status,
);
emit(newState);
},
getById: (e) async {
emit(state.copyWith(isFetchingById: true, failureOption: none()));
final failureOrOrder = await _repository.getOrderById(e.id);
failureOrOrder.fold(
(f) => emit(
state.copyWith(failureOption: optionOf(f), isFetching: false),
),
(order) => emit(
state.copyWith(
order: order,
isFetching: false,
failureOption: none(),
),
),
);
emit(state.copyWith(isFetchingById: false));
},
);
}
Future<OrderLoaderState> _mapFetchedToState(
OrderLoaderState state, {
bool isRefresh = false,
String status = 'completed',
}) async {
state = state.copyWith(isFetching: false);
if (state.hasReachedMax && state.orders.isNotEmpty && !isRefresh) {
return state;
}
if (isRefresh) {
state = state.copyWith(
page: 1,
failureOption: none(),
hasReachedMax: false,
orders: [],
);
}
final failureOrTable = await _repository.getOrders(
page: state.page,
status: status,
startDate: state.startDate,
endDate: state.endDate,
search: state.search,
);
state = failureOrTable.fold(
(f) {
if (state.orders.isNotEmpty) {
return state.copyWith(hasReachedMax: true);
}
return state.copyWith(failureOption: optionOf(f));
},
(orders) {
return state.copyWith(
orders: List.from(state.orders)..addAll(orders.orders),
failureOption: none(),
page: state.page + 1,
hasReachedMax: orders.orders.length < 10,
totalOrder: orders.totalCount,
);
},
);
return state;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,17 @@
part of 'order_loader_bloc.dart';
@freezed
class OrderLoaderEvent with _$OrderLoaderEvent {
const factory OrderLoaderEvent.dateTimeRangeChange(
DateTime startDate,
DateTime endDate,
) = _DateTimeRangeChange;
const factory OrderLoaderEvent.searchChange(String search) = _SearchChange;
const factory OrderLoaderEvent.setSelectedOrder(Order order) =
_SetSelectedOrder;
const factory OrderLoaderEvent.getById(String id) = _GetById;
const factory OrderLoaderEvent.fetched({
@Default(false) bool isRefresh,
required String status,
}) = _Fetched;
}
@@ -0,0 +1,29 @@
part of 'order_loader_bloc.dart';
@freezed
class OrderLoaderState with _$OrderLoaderState {
factory OrderLoaderState({
required List<Order> orders,
required Option<OrderFailure> failureOption,
required Option<OrderFailure> failureOptionGetById,
required Order order,
Order? selectedOrder,
String? search,
required DateTime startDate,
required DateTime endDate,
@Default(0) int totalOrder,
@Default(false) bool isFetching,
@Default(false) bool isFetchingById,
@Default(false) bool hasReachedMax,
@Default(1) int page,
}) = _OrderLoaderState;
factory OrderLoaderState.initial() => OrderLoaderState(
orders: [],
failureOption: none(),
startDate: DateTime.now(),
endDate: DateTime.now(),
failureOptionGetById: none(),
order: Order.empty(),
);
}
@@ -0,0 +1,84 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/outlet/outlet.dart';
part 'outlet_loader_event.dart';
part 'outlet_loader_state.dart';
part 'outlet_loader_bloc.freezed.dart';
@injectable
class OutletLoaderBloc extends Bloc<OutletLoaderEvent, OutletLoaderState> {
final IOutletRepository _outletRepository;
OutletLoaderBloc(this._outletRepository)
: super(OutletLoaderState.initial()) {
on<OutletLoaderEvent>(_onOutletLoaderEvent);
}
Future<void> _onOutletLoaderEvent(
OutletLoaderEvent event,
Emitter<OutletLoaderState> emit,
) {
return event.map(
fetched: (e) async {
var newState = state;
if (e.isRefresh) {
newState = state.copyWith(isFetching: true);
emit(newState);
}
newState = await _mapFetchedToState(state, isRefresh: e.isRefresh);
emit(newState);
},
);
}
Future<OutletLoaderState> _mapFetchedToState(
OutletLoaderState state, {
bool isRefresh = false,
}) async {
state = state.copyWith(isFetching: false);
if (state.hasReachedMax && state.outlets.isNotEmpty && !isRefresh) {
return state;
}
if (isRefresh) {
state = state.copyWith(
page: 1,
failureOptionOutlet: none(),
hasReachedMax: false,
outlets: [],
);
}
final failureOrOutlet = await _outletRepository.getOutlets(
page: state.page,
);
state = failureOrOutlet.fold(
(f) {
if (state.outlets.isNotEmpty) {
return state.copyWith(hasReachedMax: true);
}
return state.copyWith(failureOptionOutlet: optionOf(f));
},
(outlets) {
return state.copyWith(
outlets: List.from(state.outlets)..addAll(outlets),
failureOptionOutlet: none(),
page: state.page + 1,
hasReachedMax: outlets.length < 10,
);
},
);
return state;
}
}
@@ -0,0 +1,479 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'outlet_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$OutletLoaderEvent {
bool get isRefresh => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(bool isRefresh) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(bool isRefresh)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of OutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OutletLoaderEventCopyWith<OutletLoaderEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OutletLoaderEventCopyWith<$Res> {
factory $OutletLoaderEventCopyWith(
OutletLoaderEvent value,
$Res Function(OutletLoaderEvent) then,
) = _$OutletLoaderEventCopyWithImpl<$Res, OutletLoaderEvent>;
@useResult
$Res call({bool isRefresh});
}
/// @nodoc
class _$OutletLoaderEventCopyWithImpl<$Res, $Val extends OutletLoaderEvent>
implements $OutletLoaderEventCopyWith<$Res> {
_$OutletLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? isRefresh = null}) {
return _then(
_value.copyWith(
isRefresh: null == isRefresh
? _value.isRefresh
: isRefresh // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $OutletLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool isRefresh});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$OutletLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of OutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? isRefresh = null}) {
return _then(
_$FetchedImpl(
isRefresh: null == isRefresh
? _value.isRefresh
: isRefresh // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({this.isRefresh = false});
@override
@JsonKey()
final bool isRefresh;
@override
String toString() {
return 'OutletLoaderEvent.fetched(isRefresh: $isRefresh)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.isRefresh, isRefresh) ||
other.isRefresh == isRefresh));
}
@override
int get hashCode => Object.hash(runtimeType, isRefresh);
/// Create a copy of OutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(bool isRefresh) fetched,
}) {
return fetched(isRefresh);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(bool isRefresh)? fetched,
}) {
return fetched?.call(isRefresh);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(isRefresh);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements OutletLoaderEvent {
const factory _Fetched({final bool isRefresh}) = _$FetchedImpl;
@override
bool get isRefresh;
/// Create a copy of OutletLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$OutletLoaderState {
List<Outlet> get outlets => throw _privateConstructorUsedError;
Option<OutletFailure> get failureOptionOutlet =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
bool get hasReachedMax => throw _privateConstructorUsedError;
int get page => throw _privateConstructorUsedError;
/// Create a copy of OutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$OutletLoaderStateCopyWith<OutletLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $OutletLoaderStateCopyWith<$Res> {
factory $OutletLoaderStateCopyWith(
OutletLoaderState value,
$Res Function(OutletLoaderState) then,
) = _$OutletLoaderStateCopyWithImpl<$Res, OutletLoaderState>;
@useResult
$Res call({
List<Outlet> outlets,
Option<OutletFailure> failureOptionOutlet,
bool isFetching,
bool hasReachedMax,
int page,
});
}
/// @nodoc
class _$OutletLoaderStateCopyWithImpl<$Res, $Val extends OutletLoaderState>
implements $OutletLoaderStateCopyWith<$Res> {
_$OutletLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of OutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outlets = null,
Object? failureOptionOutlet = null,
Object? isFetching = null,
Object? hasReachedMax = null,
Object? page = null,
}) {
return _then(
_value.copyWith(
outlets: null == outlets
? _value.outlets
: outlets // ignore: cast_nullable_to_non_nullable
as List<Outlet>,
failureOptionOutlet: null == failureOptionOutlet
? _value.failureOptionOutlet
: failureOptionOutlet // ignore: cast_nullable_to_non_nullable
as Option<OutletFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
hasReachedMax: null == hasReachedMax
? _value.hasReachedMax
: hasReachedMax // ignore: cast_nullable_to_non_nullable
as bool,
page: null == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$OutletLoaderStateImplCopyWith<$Res>
implements $OutletLoaderStateCopyWith<$Res> {
factory _$$OutletLoaderStateImplCopyWith(
_$OutletLoaderStateImpl value,
$Res Function(_$OutletLoaderStateImpl) then,
) = __$$OutletLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
List<Outlet> outlets,
Option<OutletFailure> failureOptionOutlet,
bool isFetching,
bool hasReachedMax,
int page,
});
}
/// @nodoc
class __$$OutletLoaderStateImplCopyWithImpl<$Res>
extends _$OutletLoaderStateCopyWithImpl<$Res, _$OutletLoaderStateImpl>
implements _$$OutletLoaderStateImplCopyWith<$Res> {
__$$OutletLoaderStateImplCopyWithImpl(
_$OutletLoaderStateImpl _value,
$Res Function(_$OutletLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of OutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? outlets = null,
Object? failureOptionOutlet = null,
Object? isFetching = null,
Object? hasReachedMax = null,
Object? page = null,
}) {
return _then(
_$OutletLoaderStateImpl(
outlets: null == outlets
? _value._outlets
: outlets // ignore: cast_nullable_to_non_nullable
as List<Outlet>,
failureOptionOutlet: null == failureOptionOutlet
? _value.failureOptionOutlet
: failureOptionOutlet // ignore: cast_nullable_to_non_nullable
as Option<OutletFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
hasReachedMax: null == hasReachedMax
? _value.hasReachedMax
: hasReachedMax // ignore: cast_nullable_to_non_nullable
as bool,
page: null == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int,
),
);
}
}
/// @nodoc
class _$OutletLoaderStateImpl implements _OutletLoaderState {
const _$OutletLoaderStateImpl({
required final List<Outlet> outlets,
required this.failureOptionOutlet,
this.isFetching = false,
this.hasReachedMax = false,
this.page = 1,
}) : _outlets = outlets;
final List<Outlet> _outlets;
@override
List<Outlet> get outlets {
if (_outlets is EqualUnmodifiableListView) return _outlets;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_outlets);
}
@override
final Option<OutletFailure> failureOptionOutlet;
@override
@JsonKey()
final bool isFetching;
@override
@JsonKey()
final bool hasReachedMax;
@override
@JsonKey()
final int page;
@override
String toString() {
return 'OutletLoaderState(outlets: $outlets, failureOptionOutlet: $failureOptionOutlet, isFetching: $isFetching, hasReachedMax: $hasReachedMax, page: $page)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OutletLoaderStateImpl &&
const DeepCollectionEquality().equals(other._outlets, _outlets) &&
(identical(other.failureOptionOutlet, failureOptionOutlet) ||
other.failureOptionOutlet == failureOptionOutlet) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching) &&
(identical(other.hasReachedMax, hasReachedMax) ||
other.hasReachedMax == hasReachedMax) &&
(identical(other.page, page) || other.page == page));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_outlets),
failureOptionOutlet,
isFetching,
hasReachedMax,
page,
);
/// Create a copy of OutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$OutletLoaderStateImplCopyWith<_$OutletLoaderStateImpl> get copyWith =>
__$$OutletLoaderStateImplCopyWithImpl<_$OutletLoaderStateImpl>(
this,
_$identity,
);
}
abstract class _OutletLoaderState implements OutletLoaderState {
const factory _OutletLoaderState({
required final List<Outlet> outlets,
required final Option<OutletFailure> failureOptionOutlet,
final bool isFetching,
final bool hasReachedMax,
final int page,
}) = _$OutletLoaderStateImpl;
@override
List<Outlet> get outlets;
@override
Option<OutletFailure> get failureOptionOutlet;
@override
bool get isFetching;
@override
bool get hasReachedMax;
@override
int get page;
/// Create a copy of OutletLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$OutletLoaderStateImplCopyWith<_$OutletLoaderStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,7 @@
part of 'outlet_loader_bloc.dart';
@freezed
class OutletLoaderEvent with _$OutletLoaderEvent {
const factory OutletLoaderEvent.fetched({@Default(false) bool isRefresh}) =
_Fetched;
}
@@ -0,0 +1,15 @@
part of 'outlet_loader_bloc.dart';
@freezed
class OutletLoaderState with _$OutletLoaderState {
const factory OutletLoaderState({
required List<Outlet> outlets,
required Option<OutletFailure> failureOptionOutlet,
@Default(false) bool isFetching,
@Default(false) bool hasReachedMax,
@Default(1) int page,
}) = _OutletLoaderState;
factory OutletLoaderState.initial() =>
OutletLoaderState(outlets: [], failureOptionOutlet: none());
}
@@ -0,0 +1,134 @@
import 'dart:developer';
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart' hide Order;
import 'package:uuid/uuid.dart';
import '../../../common/types/split_type.dart';
import '../../../domain/order/order.dart';
import '../../../domain/payment_method/payment_method.dart';
part 'payment_form_event.dart';
part 'payment_form_state.dart';
part 'payment_form_bloc.freezed.dart';
@injectable
class PaymentFormBloc extends Bloc<PaymentFormEvent, PaymentFormState> {
final IOrderRepository _repository;
PaymentFormBloc(this._repository) : super(PaymentFormState.initial()) {
on<PaymentFormEvent>(_onPaymentFormEvent);
}
Future<void> _onPaymentFormEvent(
PaymentFormEvent event,
Emitter<PaymentFormState> emit,
) {
return event.map(
setOrder: (e) async {
List<OrderItem> pendingItems = e.order.orderItems
.where((item) => item.status == 'pending')
.toList();
emit(state.copyWith(order: e.order, pendingItems: pendingItems));
},
setPaymentMethod: (e) async {
emit(state.copyWith(paymentMethod: e.paymentMethod));
},
submitted: (e) async {
Either<OrderFailure, Payment> failureOrPayment;
// Generate new idempotency key saat user intent (tap Bayar)
// Kalau sedang retry (isSubmitting sebelumnya gagal), pakai key yang sama
final idempotencyKey = state.idempotencyKey ?? const Uuid().v4();
emit(state.copyWith(
isSubmitting: true,
failureOrPayment: none(),
idempotencyKey: idempotencyKey,
));
final request = PaymentRequest(
orderId: state.order.id,
paymentMethodId: state.paymentMethod?.id ?? '',
amount: state.order.totalAmount,
transactionId: '',
splitNumber: 1,
splitTotal: 1,
splitDescription: '',
paymentOrderItems: state.pendingItems
.map(
(item) => PaymentItemRequest(
orderItemId: item.id,
amount: item.totalPrice,
),
)
.toList(),
);
failureOrPayment = await _repository.createPayment(
request: request,
idempotencyKey: idempotencyKey,
);
emit(
state.copyWith(
isSubmitting: false,
failureOrPayment: optionOf(failureOrPayment),
// Clear key on success, keep on failure for retry
idempotencyKey: failureOrPayment.isRight() ? null : idempotencyKey,
),
);
},
submittedSplitBill: (e) async {
Either<OrderFailure, Payment> failureOrPayment;
// Generate new idempotency key untuk split bill
final idempotencyKey = state.splitBillIdempotencyKey ?? const Uuid().v4();
emit(
state.copyWith(
isSubmitting: true,
failureOrPaymentSplitBill: none(),
splitBillIdempotencyKey: idempotencyKey,
),
);
final request = PaymentSplitBillRequest(
orderId: state.order.id,
paymentMethodId: state.paymentMethod?.id ?? '',
amount: state.order.totalAmount,
customerId: e.customerId ?? '',
type: e.splitType ?? SplitType.unknown,
customerName: e.customerName ?? '',
items: state.pendingItems
.map(
(item) => PaymentItemSplitBillRequest(
orderItemId: item.id,
quantity: item.quantity,
),
)
.toList(),
);
log(request.toString());
failureOrPayment = await _repository.createSplitBill(
request,
idempotencyKey: idempotencyKey,
);
emit(
state.copyWith(
isSubmitting: false,
failureOrPaymentSplitBill: optionOf(failureOrPayment),
// Clear key on success, keep on failure for retry
splitBillIdempotencyKey:
failureOrPayment.isRight() ? null : idempotencyKey,
),
);
},
);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,14 @@
part of 'payment_form_bloc.dart';
@freezed
class PaymentFormEvent with _$PaymentFormEvent {
const factory PaymentFormEvent.setOrder(Order order) = _SetOrder;
const factory PaymentFormEvent.setPaymentMethod(PaymentMethod paymentMethod) =
_SetPayment;
const factory PaymentFormEvent.submitted() = _Submitted;
const factory PaymentFormEvent.submittedSplitBill({
SplitType? splitType,
String? customerId,
String? customerName,
}) = _SubmittedSplitBill;
}
@@ -0,0 +1,26 @@
part of 'payment_form_bloc.dart';
@freezed
class PaymentFormState with _$PaymentFormState {
factory PaymentFormState({
required Order order,
required List<OrderItem> pendingItems,
required Option<Either<OrderFailure, Payment>> failureOrPayment,
required Option<Either<OrderFailure, Payment>> failureOrPaymentSplitBill,
PaymentMethod? paymentMethod,
@Default(false) bool isSubmitting,
/// Idempotency key untuk payment submission.
/// Di-generate saat user tap "Bayar", dipakai ulang saat retry,
/// di-clear setelah sukses.
String? idempotencyKey,
/// Idempotency key untuk split bill submission.
String? splitBillIdempotencyKey,
}) = _PaymentFormState;
factory PaymentFormState.initial() => PaymentFormState(
order: Order.empty(),
pendingItems: [],
failureOrPayment: none(),
failureOrPaymentSplitBill: none(),
);
}
@@ -0,0 +1,83 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../domain/payment_method/payment_method.dart';
part 'payment_method_loader_event.dart';
part 'payment_method_loader_state.dart';
part 'payment_method_loader_bloc.freezed.dart';
@injectable
class PaymentMethodLoaderBloc
extends Bloc<PaymentMethodLoaderEvent, PaymentMethodLoaderState> {
final IPaymentMethodRepository _repository;
PaymentMethodLoaderBloc(this._repository)
: super(PaymentMethodLoaderState.initial()) {
on<PaymentMethodLoaderEvent>(_onPaymentMethodLoaderEvent);
}
Future<void> _onPaymentMethodLoaderEvent(
PaymentMethodLoaderEvent event,
Emitter<PaymentMethodLoaderState> emit,
) {
return event.map(
fetched: (e) async {
var newState = state;
if (e.isRefresh) {
newState = newState.copyWith(isFetching: true);
emit(newState);
}
newState = await _mapFetchedToState(newState, isRefresh: e.isRefresh);
emit(newState);
},
);
}
Future<PaymentMethodLoaderState> _mapFetchedToState(
PaymentMethodLoaderState state, {
bool isRefresh = false,
}) async {
state = state.copyWith(isFetching: false);
if (state.hasReachedMax && state.paymentMethods.isNotEmpty && !isRefresh) {
return state;
}
if (isRefresh) {
state = state.copyWith(
page: 1,
failureOption: none(),
hasReachedMax: false,
paymentMethods: [],
);
}
final failureOrTable = await _repository.getPaymentMethods(
page: state.page,
);
state = failureOrTable.fold(
(f) {
if (state.paymentMethods.isNotEmpty) {
return state.copyWith(hasReachedMax: true);
}
return state.copyWith(failureOption: optionOf(f));
},
(paymentMethods) {
return state.copyWith(
paymentMethods: List.from(state.paymentMethods)
..addAll(paymentMethods.paymentMethods),
failureOption: none(),
page: state.page + 1,
hasReachedMax: paymentMethods.paymentMethods.length < 10,
);
},
);
return state;
}
}
@@ -0,0 +1,492 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'payment_method_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$PaymentMethodLoaderEvent {
bool get isRefresh => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(bool isRefresh) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(bool isRefresh)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of PaymentMethodLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PaymentMethodLoaderEventCopyWith<PaymentMethodLoaderEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PaymentMethodLoaderEventCopyWith<$Res> {
factory $PaymentMethodLoaderEventCopyWith(
PaymentMethodLoaderEvent value,
$Res Function(PaymentMethodLoaderEvent) then,
) = _$PaymentMethodLoaderEventCopyWithImpl<$Res, PaymentMethodLoaderEvent>;
@useResult
$Res call({bool isRefresh});
}
/// @nodoc
class _$PaymentMethodLoaderEventCopyWithImpl<
$Res,
$Val extends PaymentMethodLoaderEvent
>
implements $PaymentMethodLoaderEventCopyWith<$Res> {
_$PaymentMethodLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PaymentMethodLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? isRefresh = null}) {
return _then(
_value.copyWith(
isRefresh: null == isRefresh
? _value.isRefresh
: isRefresh // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res>
implements $PaymentMethodLoaderEventCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool isRefresh});
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$PaymentMethodLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of PaymentMethodLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? isRefresh = null}) {
return _then(
_$FetchedImpl(
isRefresh: null == isRefresh
? _value.isRefresh
: isRefresh // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl({this.isRefresh = false});
@override
@JsonKey()
final bool isRefresh;
@override
String toString() {
return 'PaymentMethodLoaderEvent.fetched(isRefresh: $isRefresh)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FetchedImpl &&
(identical(other.isRefresh, isRefresh) ||
other.isRefresh == isRefresh));
}
@override
int get hashCode => Object.hash(runtimeType, isRefresh);
/// Create a copy of PaymentMethodLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
__$$FetchedImplCopyWithImpl<_$FetchedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(bool isRefresh) fetched,
}) {
return fetched(isRefresh);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(bool isRefresh)? fetched,
}) {
return fetched?.call(isRefresh);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(bool isRefresh)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(isRefresh);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements PaymentMethodLoaderEvent {
const factory _Fetched({final bool isRefresh}) = _$FetchedImpl;
@override
bool get isRefresh;
/// Create a copy of PaymentMethodLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$FetchedImplCopyWith<_$FetchedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$PaymentMethodLoaderState {
List<PaymentMethod> get paymentMethods => throw _privateConstructorUsedError;
Option<PaymentMethodFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get hasReachedMax => throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
int get page => throw _privateConstructorUsedError;
/// Create a copy of PaymentMethodLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PaymentMethodLoaderStateCopyWith<PaymentMethodLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PaymentMethodLoaderStateCopyWith<$Res> {
factory $PaymentMethodLoaderStateCopyWith(
PaymentMethodLoaderState value,
$Res Function(PaymentMethodLoaderState) then,
) = _$PaymentMethodLoaderStateCopyWithImpl<$Res, PaymentMethodLoaderState>;
@useResult
$Res call({
List<PaymentMethod> paymentMethods,
Option<PaymentMethodFailure> failureOption,
bool hasReachedMax,
bool isFetching,
int page,
});
}
/// @nodoc
class _$PaymentMethodLoaderStateCopyWithImpl<
$Res,
$Val extends PaymentMethodLoaderState
>
implements $PaymentMethodLoaderStateCopyWith<$Res> {
_$PaymentMethodLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PaymentMethodLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? paymentMethods = null,
Object? failureOption = null,
Object? hasReachedMax = null,
Object? isFetching = null,
Object? page = null,
}) {
return _then(
_value.copyWith(
paymentMethods: null == paymentMethods
? _value.paymentMethods
: paymentMethods // ignore: cast_nullable_to_non_nullable
as List<PaymentMethod>,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<PaymentMethodFailure>,
hasReachedMax: null == hasReachedMax
? _value.hasReachedMax
: hasReachedMax // ignore: cast_nullable_to_non_nullable
as bool,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
page: null == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$PaymentMethodLoaderStateImplCopyWith<$Res>
implements $PaymentMethodLoaderStateCopyWith<$Res> {
factory _$$PaymentMethodLoaderStateImplCopyWith(
_$PaymentMethodLoaderStateImpl value,
$Res Function(_$PaymentMethodLoaderStateImpl) then,
) = __$$PaymentMethodLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
List<PaymentMethod> paymentMethods,
Option<PaymentMethodFailure> failureOption,
bool hasReachedMax,
bool isFetching,
int page,
});
}
/// @nodoc
class __$$PaymentMethodLoaderStateImplCopyWithImpl<$Res>
extends
_$PaymentMethodLoaderStateCopyWithImpl<
$Res,
_$PaymentMethodLoaderStateImpl
>
implements _$$PaymentMethodLoaderStateImplCopyWith<$Res> {
__$$PaymentMethodLoaderStateImplCopyWithImpl(
_$PaymentMethodLoaderStateImpl _value,
$Res Function(_$PaymentMethodLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of PaymentMethodLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? paymentMethods = null,
Object? failureOption = null,
Object? hasReachedMax = null,
Object? isFetching = null,
Object? page = null,
}) {
return _then(
_$PaymentMethodLoaderStateImpl(
paymentMethods: null == paymentMethods
? _value._paymentMethods
: paymentMethods // ignore: cast_nullable_to_non_nullable
as List<PaymentMethod>,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<PaymentMethodFailure>,
hasReachedMax: null == hasReachedMax
? _value.hasReachedMax
: hasReachedMax // ignore: cast_nullable_to_non_nullable
as bool,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
page: null == page
? _value.page
: page // ignore: cast_nullable_to_non_nullable
as int,
),
);
}
}
/// @nodoc
class _$PaymentMethodLoaderStateImpl implements _PaymentMethodLoaderState {
_$PaymentMethodLoaderStateImpl({
required final List<PaymentMethod> paymentMethods,
required this.failureOption,
this.hasReachedMax = false,
this.isFetching = false,
this.page = 1,
}) : _paymentMethods = paymentMethods;
final List<PaymentMethod> _paymentMethods;
@override
List<PaymentMethod> get paymentMethods {
if (_paymentMethods is EqualUnmodifiableListView) return _paymentMethods;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_paymentMethods);
}
@override
final Option<PaymentMethodFailure> failureOption;
@override
@JsonKey()
final bool hasReachedMax;
@override
@JsonKey()
final bool isFetching;
@override
@JsonKey()
final int page;
@override
String toString() {
return 'PaymentMethodLoaderState(paymentMethods: $paymentMethods, failureOption: $failureOption, hasReachedMax: $hasReachedMax, isFetching: $isFetching, page: $page)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PaymentMethodLoaderStateImpl &&
const DeepCollectionEquality().equals(
other._paymentMethods,
_paymentMethods,
) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.hasReachedMax, hasReachedMax) ||
other.hasReachedMax == hasReachedMax) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching) &&
(identical(other.page, page) || other.page == page));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_paymentMethods),
failureOption,
hasReachedMax,
isFetching,
page,
);
/// Create a copy of PaymentMethodLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$PaymentMethodLoaderStateImplCopyWith<_$PaymentMethodLoaderStateImpl>
get copyWith =>
__$$PaymentMethodLoaderStateImplCopyWithImpl<
_$PaymentMethodLoaderStateImpl
>(this, _$identity);
}
abstract class _PaymentMethodLoaderState implements PaymentMethodLoaderState {
factory _PaymentMethodLoaderState({
required final List<PaymentMethod> paymentMethods,
required final Option<PaymentMethodFailure> failureOption,
final bool hasReachedMax,
final bool isFetching,
final int page,
}) = _$PaymentMethodLoaderStateImpl;
@override
List<PaymentMethod> get paymentMethods;
@override
Option<PaymentMethodFailure> get failureOption;
@override
bool get hasReachedMax;
@override
bool get isFetching;
@override
int get page;
/// Create a copy of PaymentMethodLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$PaymentMethodLoaderStateImplCopyWith<_$PaymentMethodLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,8 @@
part of 'payment_method_loader_bloc.dart';
@freezed
class PaymentMethodLoaderEvent with _$PaymentMethodLoaderEvent {
const factory PaymentMethodLoaderEvent.fetched({
@Default(false) bool isRefresh,
}) = _Fetched;
}
@@ -0,0 +1,14 @@
part of 'payment_method_loader_bloc.dart';
@freezed
class PaymentMethodLoaderState with _$PaymentMethodLoaderState {
factory PaymentMethodLoaderState({
required List<PaymentMethod> paymentMethods,
required Option<PaymentMethodFailure> failureOption,
@Default(false) bool hasReachedMax,
@Default(false) bool isFetching,
@Default(1) int page,
}) = _PaymentMethodLoaderState;
factory PaymentMethodLoaderState.initial() =>
PaymentMethodLoaderState(paymentMethods: [], failureOption: none());
}
@@ -0,0 +1,38 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../../../domain/printer/printer.dart';
part 'bluetooth_connect_event.dart';
part 'bluetooth_connect_state.dart';
part 'bluetooth_connect_bloc.freezed.dart';
@injectable
class BluetoothConnectBloc
extends Bloc<BluetoothConnectEvent, BluetoothConnectState> {
final IPrinterRepository _printerRepository;
BluetoothConnectBloc(this._printerRepository)
: super(BluetoothConnectState.initial()) {
on<BluetoothConnectEvent>(_onBluetoothConnectEvent);
}
Future<void> _onBluetoothConnectEvent(
BluetoothConnectEvent event,
Emitter<BluetoothConnectState> emit,
) {
return event.map(
connect: (e) async {
emit(state.copyWith(isConnecting: true, failureOrSuccee: none()));
final result = await _printerRepository.connectBluetooth(e.macAddress);
result.fold(
(failure) => emit(state.copyWith(isConnecting: false)),
(success) => emit(state.copyWith(isConnecting: false)),
);
},
);
}
}
@@ -0,0 +1,404 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'bluetooth_connect_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$BluetoothConnectEvent {
String get macAddress => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String macAddress) connect,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String macAddress)? connect,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String macAddress)? connect,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Connect value) connect,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Connect value)? connect,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Connect value)? connect,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of BluetoothConnectEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$BluetoothConnectEventCopyWith<BluetoothConnectEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $BluetoothConnectEventCopyWith<$Res> {
factory $BluetoothConnectEventCopyWith(
BluetoothConnectEvent value,
$Res Function(BluetoothConnectEvent) then,
) = _$BluetoothConnectEventCopyWithImpl<$Res, BluetoothConnectEvent>;
@useResult
$Res call({String macAddress});
}
/// @nodoc
class _$BluetoothConnectEventCopyWithImpl<
$Res,
$Val extends BluetoothConnectEvent
>
implements $BluetoothConnectEventCopyWith<$Res> {
_$BluetoothConnectEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of BluetoothConnectEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? macAddress = null}) {
return _then(
_value.copyWith(
macAddress: null == macAddress
? _value.macAddress
: macAddress // ignore: cast_nullable_to_non_nullable
as String,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$ConnectImplCopyWith<$Res>
implements $BluetoothConnectEventCopyWith<$Res> {
factory _$$ConnectImplCopyWith(
_$ConnectImpl value,
$Res Function(_$ConnectImpl) then,
) = __$$ConnectImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String macAddress});
}
/// @nodoc
class __$$ConnectImplCopyWithImpl<$Res>
extends _$BluetoothConnectEventCopyWithImpl<$Res, _$ConnectImpl>
implements _$$ConnectImplCopyWith<$Res> {
__$$ConnectImplCopyWithImpl(
_$ConnectImpl _value,
$Res Function(_$ConnectImpl) _then,
) : super(_value, _then);
/// Create a copy of BluetoothConnectEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? macAddress = null}) {
return _then(
_$ConnectImpl(
null == macAddress
? _value.macAddress
: macAddress // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$ConnectImpl implements _Connect {
const _$ConnectImpl(this.macAddress);
@override
final String macAddress;
@override
String toString() {
return 'BluetoothConnectEvent.connect(macAddress: $macAddress)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ConnectImpl &&
(identical(other.macAddress, macAddress) ||
other.macAddress == macAddress));
}
@override
int get hashCode => Object.hash(runtimeType, macAddress);
/// Create a copy of BluetoothConnectEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ConnectImplCopyWith<_$ConnectImpl> get copyWith =>
__$$ConnectImplCopyWithImpl<_$ConnectImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String macAddress) connect,
}) {
return connect(macAddress);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String macAddress)? connect,
}) {
return connect?.call(macAddress);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String macAddress)? connect,
required TResult orElse(),
}) {
if (connect != null) {
return connect(macAddress);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Connect value) connect,
}) {
return connect(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Connect value)? connect,
}) {
return connect?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Connect value)? connect,
required TResult orElse(),
}) {
if (connect != null) {
return connect(this);
}
return orElse();
}
}
abstract class _Connect implements BluetoothConnectEvent {
const factory _Connect(final String macAddress) = _$ConnectImpl;
@override
String get macAddress;
/// Create a copy of BluetoothConnectEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ConnectImplCopyWith<_$ConnectImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$BluetoothConnectState {
Option<Either<PrinterFailure, bool>> get failureOrSuccee =>
throw _privateConstructorUsedError;
bool get isConnecting => throw _privateConstructorUsedError;
/// Create a copy of BluetoothConnectState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$BluetoothConnectStateCopyWith<BluetoothConnectState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $BluetoothConnectStateCopyWith<$Res> {
factory $BluetoothConnectStateCopyWith(
BluetoothConnectState value,
$Res Function(BluetoothConnectState) then,
) = _$BluetoothConnectStateCopyWithImpl<$Res, BluetoothConnectState>;
@useResult
$Res call({
Option<Either<PrinterFailure, bool>> failureOrSuccee,
bool isConnecting,
});
}
/// @nodoc
class _$BluetoothConnectStateCopyWithImpl<
$Res,
$Val extends BluetoothConnectState
>
implements $BluetoothConnectStateCopyWith<$Res> {
_$BluetoothConnectStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of BluetoothConnectState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? failureOrSuccee = null, Object? isConnecting = null}) {
return _then(
_value.copyWith(
failureOrSuccee: null == failureOrSuccee
? _value.failureOrSuccee
: failureOrSuccee // ignore: cast_nullable_to_non_nullable
as Option<Either<PrinterFailure, bool>>,
isConnecting: null == isConnecting
? _value.isConnecting
: isConnecting // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$BluetoothConnectStateImplCopyWith<$Res>
implements $BluetoothConnectStateCopyWith<$Res> {
factory _$$BluetoothConnectStateImplCopyWith(
_$BluetoothConnectStateImpl value,
$Res Function(_$BluetoothConnectStateImpl) then,
) = __$$BluetoothConnectStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
Option<Either<PrinterFailure, bool>> failureOrSuccee,
bool isConnecting,
});
}
/// @nodoc
class __$$BluetoothConnectStateImplCopyWithImpl<$Res>
extends
_$BluetoothConnectStateCopyWithImpl<$Res, _$BluetoothConnectStateImpl>
implements _$$BluetoothConnectStateImplCopyWith<$Res> {
__$$BluetoothConnectStateImplCopyWithImpl(
_$BluetoothConnectStateImpl _value,
$Res Function(_$BluetoothConnectStateImpl) _then,
) : super(_value, _then);
/// Create a copy of BluetoothConnectState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? failureOrSuccee = null, Object? isConnecting = null}) {
return _then(
_$BluetoothConnectStateImpl(
failureOrSuccee: null == failureOrSuccee
? _value.failureOrSuccee
: failureOrSuccee // ignore: cast_nullable_to_non_nullable
as Option<Either<PrinterFailure, bool>>,
isConnecting: null == isConnecting
? _value.isConnecting
: isConnecting // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$BluetoothConnectStateImpl implements _BluetoothConnectState {
_$BluetoothConnectStateImpl({
required this.failureOrSuccee,
this.isConnecting = false,
});
@override
final Option<Either<PrinterFailure, bool>> failureOrSuccee;
@override
@JsonKey()
final bool isConnecting;
@override
String toString() {
return 'BluetoothConnectState(failureOrSuccee: $failureOrSuccee, isConnecting: $isConnecting)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BluetoothConnectStateImpl &&
(identical(other.failureOrSuccee, failureOrSuccee) ||
other.failureOrSuccee == failureOrSuccee) &&
(identical(other.isConnecting, isConnecting) ||
other.isConnecting == isConnecting));
}
@override
int get hashCode => Object.hash(runtimeType, failureOrSuccee, isConnecting);
/// Create a copy of BluetoothConnectState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$BluetoothConnectStateImplCopyWith<_$BluetoothConnectStateImpl>
get copyWith =>
__$$BluetoothConnectStateImplCopyWithImpl<_$BluetoothConnectStateImpl>(
this,
_$identity,
);
}
abstract class _BluetoothConnectState implements BluetoothConnectState {
factory _BluetoothConnectState({
required final Option<Either<PrinterFailure, bool>> failureOrSuccee,
final bool isConnecting,
}) = _$BluetoothConnectStateImpl;
@override
Option<Either<PrinterFailure, bool>> get failureOrSuccee;
@override
bool get isConnecting;
/// Create a copy of BluetoothConnectState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$BluetoothConnectStateImplCopyWith<_$BluetoothConnectStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'bluetooth_connect_bloc.dart';
@freezed
class BluetoothConnectEvent with _$BluetoothConnectEvent {
const factory BluetoothConnectEvent.connect(String macAddress) = _Connect;
}
@@ -0,0 +1,12 @@
part of 'bluetooth_connect_bloc.dart';
@freezed
class BluetoothConnectState with _$BluetoothConnectState {
factory BluetoothConnectState({
required Option<Either<PrinterFailure, bool>> failureOrSuccee,
@Default(false) bool isConnecting,
}) = _BluetoothConnectState;
factory BluetoothConnectState.initial() =>
BluetoothConnectState(failureOrSuccee: none());
}
@@ -0,0 +1,47 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart';
import '../../../../domain/printer/printer.dart';
part 'bluetooth_loader_event.dart';
part 'bluetooth_loader_state.dart';
part 'bluetooth_loader_bloc.freezed.dart';
@injectable
class BluetoothLoaderBloc
extends Bloc<BluetoothLoaderEvent, BluetoothLoaderState> {
final IPrinterRepository _printerRepository;
BluetoothLoaderBloc(this._printerRepository)
: super(BluetoothLoaderState.initial()) {
on<BluetoothLoaderEvent>(_onBluetoothLoaderEvent);
}
Future<void> _onBluetoothLoaderEvent(
BluetoothLoaderEvent event,
Emitter<BluetoothLoaderState> emit,
) {
return event.map(
fetched: (e) async {
emit(state.copyWith(isFetching: true, failureOption: none()));
final result = await _printerRepository.getPairedBluetoothDevices();
result.fold(
(failure) => emit(
state.copyWith(failureOption: optionOf(failure), isFetching: false),
),
(devices) => emit(
state.copyWith(
bluetoothDevices: devices,
failureOption: none(),
isFetching: false,
),
),
);
},
);
}
}
@@ -0,0 +1,379 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'bluetooth_loader_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$BluetoothLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $BluetoothLoaderEventCopyWith<$Res> {
factory $BluetoothLoaderEventCopyWith(
BluetoothLoaderEvent value,
$Res Function(BluetoothLoaderEvent) then,
) = _$BluetoothLoaderEventCopyWithImpl<$Res, BluetoothLoaderEvent>;
}
/// @nodoc
class _$BluetoothLoaderEventCopyWithImpl<
$Res,
$Val extends BluetoothLoaderEvent
>
implements $BluetoothLoaderEventCopyWith<$Res> {
_$BluetoothLoaderEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of BluetoothLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$FetchedImplCopyWith<$Res> {
factory _$$FetchedImplCopyWith(
_$FetchedImpl value,
$Res Function(_$FetchedImpl) then,
) = __$$FetchedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$FetchedImplCopyWithImpl<$Res>
extends _$BluetoothLoaderEventCopyWithImpl<$Res, _$FetchedImpl>
implements _$$FetchedImplCopyWith<$Res> {
__$$FetchedImplCopyWithImpl(
_$FetchedImpl _value,
$Res Function(_$FetchedImpl) _then,
) : super(_value, _then);
/// Create a copy of BluetoothLoaderEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$FetchedImpl implements _Fetched {
const _$FetchedImpl();
@override
String toString() {
return 'BluetoothLoaderEvent.fetched()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$FetchedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({required TResult Function() fetched}) {
return fetched();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({TResult? Function()? fetched}) {
return fetched?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Fetched value) fetched,
}) {
return fetched(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Fetched value)? fetched,
}) {
return fetched?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Fetched value)? fetched,
required TResult orElse(),
}) {
if (fetched != null) {
return fetched(this);
}
return orElse();
}
}
abstract class _Fetched implements BluetoothLoaderEvent {
const factory _Fetched() = _$FetchedImpl;
}
/// @nodoc
mixin _$BluetoothLoaderState {
List<BluetoothInfo> get bluetoothDevices =>
throw _privateConstructorUsedError;
Option<PrinterFailure> get failureOption =>
throw _privateConstructorUsedError;
bool get isFetching => throw _privateConstructorUsedError;
/// Create a copy of BluetoothLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$BluetoothLoaderStateCopyWith<BluetoothLoaderState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $BluetoothLoaderStateCopyWith<$Res> {
factory $BluetoothLoaderStateCopyWith(
BluetoothLoaderState value,
$Res Function(BluetoothLoaderState) then,
) = _$BluetoothLoaderStateCopyWithImpl<$Res, BluetoothLoaderState>;
@useResult
$Res call({
List<BluetoothInfo> bluetoothDevices,
Option<PrinterFailure> failureOption,
bool isFetching,
});
}
/// @nodoc
class _$BluetoothLoaderStateCopyWithImpl<
$Res,
$Val extends BluetoothLoaderState
>
implements $BluetoothLoaderStateCopyWith<$Res> {
_$BluetoothLoaderStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of BluetoothLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? bluetoothDevices = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_value.copyWith(
bluetoothDevices: null == bluetoothDevices
? _value.bluetoothDevices
: bluetoothDevices // ignore: cast_nullable_to_non_nullable
as List<BluetoothInfo>,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<PrinterFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$BluetoothLoaderStateImplCopyWith<$Res>
implements $BluetoothLoaderStateCopyWith<$Res> {
factory _$$BluetoothLoaderStateImplCopyWith(
_$BluetoothLoaderStateImpl value,
$Res Function(_$BluetoothLoaderStateImpl) then,
) = __$$BluetoothLoaderStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
List<BluetoothInfo> bluetoothDevices,
Option<PrinterFailure> failureOption,
bool isFetching,
});
}
/// @nodoc
class __$$BluetoothLoaderStateImplCopyWithImpl<$Res>
extends _$BluetoothLoaderStateCopyWithImpl<$Res, _$BluetoothLoaderStateImpl>
implements _$$BluetoothLoaderStateImplCopyWith<$Res> {
__$$BluetoothLoaderStateImplCopyWithImpl(
_$BluetoothLoaderStateImpl _value,
$Res Function(_$BluetoothLoaderStateImpl) _then,
) : super(_value, _then);
/// Create a copy of BluetoothLoaderState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? bluetoothDevices = null,
Object? failureOption = null,
Object? isFetching = null,
}) {
return _then(
_$BluetoothLoaderStateImpl(
bluetoothDevices: null == bluetoothDevices
? _value._bluetoothDevices
: bluetoothDevices // ignore: cast_nullable_to_non_nullable
as List<BluetoothInfo>,
failureOption: null == failureOption
? _value.failureOption
: failureOption // ignore: cast_nullable_to_non_nullable
as Option<PrinterFailure>,
isFetching: null == isFetching
? _value.isFetching
: isFetching // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$BluetoothLoaderStateImpl implements _BluetoothLoaderState {
_$BluetoothLoaderStateImpl({
required final List<BluetoothInfo> bluetoothDevices,
required this.failureOption,
this.isFetching = false,
}) : _bluetoothDevices = bluetoothDevices;
final List<BluetoothInfo> _bluetoothDevices;
@override
List<BluetoothInfo> get bluetoothDevices {
if (_bluetoothDevices is EqualUnmodifiableListView)
return _bluetoothDevices;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_bluetoothDevices);
}
@override
final Option<PrinterFailure> failureOption;
@override
@JsonKey()
final bool isFetching;
@override
String toString() {
return 'BluetoothLoaderState(bluetoothDevices: $bluetoothDevices, failureOption: $failureOption, isFetching: $isFetching)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BluetoothLoaderStateImpl &&
const DeepCollectionEquality().equals(
other._bluetoothDevices,
_bluetoothDevices,
) &&
(identical(other.failureOption, failureOption) ||
other.failureOption == failureOption) &&
(identical(other.isFetching, isFetching) ||
other.isFetching == isFetching));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_bluetoothDevices),
failureOption,
isFetching,
);
/// Create a copy of BluetoothLoaderState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$BluetoothLoaderStateImplCopyWith<_$BluetoothLoaderStateImpl>
get copyWith =>
__$$BluetoothLoaderStateImplCopyWithImpl<_$BluetoothLoaderStateImpl>(
this,
_$identity,
);
}
abstract class _BluetoothLoaderState implements BluetoothLoaderState {
factory _BluetoothLoaderState({
required final List<BluetoothInfo> bluetoothDevices,
required final Option<PrinterFailure> failureOption,
final bool isFetching,
}) = _$BluetoothLoaderStateImpl;
@override
List<BluetoothInfo> get bluetoothDevices;
@override
Option<PrinterFailure> get failureOption;
@override
bool get isFetching;
/// Create a copy of BluetoothLoaderState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$BluetoothLoaderStateImplCopyWith<_$BluetoothLoaderStateImpl>
get copyWith => throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'bluetooth_loader_bloc.dart';
@freezed
class BluetoothLoaderEvent with _$BluetoothLoaderEvent {
const factory BluetoothLoaderEvent.fetched() = _Fetched;
}
@@ -0,0 +1,13 @@
part of 'bluetooth_loader_bloc.dart';
@freezed
class BluetoothLoaderState with _$BluetoothLoaderState {
factory BluetoothLoaderState({
required List<BluetoothInfo> bluetoothDevices,
required Option<PrinterFailure> failureOption,
@Default(false) bool isFetching,
}) = _BluetoothLoaderState;
factory BluetoothLoaderState.initial() =>
BluetoothLoaderState(bluetoothDevices: [], failureOption: none());
}
@@ -0,0 +1,156 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart' hide Order;
import '../../../domain/order/order.dart';
import '../../../domain/printer/printer.dart';
part 'print_struck_event.dart';
part 'print_struck_state.dart';
part 'print_struck_bloc.freezed.dart';
@injectable
class PrintStruckBloc extends Bloc<PrintStruckEvent, PrintStruckState> {
final IPrinterRepository _printerRepository;
PrintStruckBloc(this._printerRepository) : super(PrintStruckState.initial()) {
on<PrintStruckEvent>(_onPrintStruckEvent);
}
Future<void> _onPrintStruckEvent(
PrintStruckEvent event,
Emitter<PrintStruckState> emit,
) {
return event.map(
order: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckOrder(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
cashier: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckCashier(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
payment: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckPayment(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
voided: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckVoid(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
splitBill: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckSplitBill(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
kitchen: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckKitchen(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
bar: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckBar(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
checker: (e) async {
Either<PrinterFailure, Unit> failureOrSuccess;
emit(state.copyWith(isPrinting: true, failureOrPrintStruck: none()));
failureOrSuccess = await _printerRepository.printStruckChecker(
order: e.order,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintStruck: optionOf(failureOrSuccess),
),
);
},
);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,13 @@
part of 'print_struck_bloc.dart';
@freezed
class PrintStruckEvent with _$PrintStruckEvent {
const factory PrintStruckEvent.order(Order order) = _Order;
const factory PrintStruckEvent.cashier(Order order) = _Cashier;
const factory PrintStruckEvent.payment(Order order) = _Payment;
const factory PrintStruckEvent.voided(Order order) = _Voided;
const factory PrintStruckEvent.checker(Order order) = _Checker;
const factory PrintStruckEvent.kitchen(Order order) = _Kitchen;
const factory PrintStruckEvent.bar(Order order) = _Bar;
const factory PrintStruckEvent.splitBill(Order order) = _SplitBill;
}
@@ -0,0 +1,12 @@
part of 'print_struck_bloc.dart';
@freezed
class PrintStruckState with _$PrintStruckState {
factory PrintStruckState({
required Option<Either<PrinterFailure, Unit>> failureOrPrintStruck,
@Default(false) bool isPrinting,
}) = _PrintStruckState;
factory PrintStruckState.initial() =>
PrintStruckState(failureOrPrintStruck: none());
}
+22
View File
@@ -0,0 +1,22 @@
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
part 'printer_event.dart';
part 'printer_state.dart';
part 'printer_bloc.freezed.dart';
@injectable
class PrinterBloc extends Bloc<PrinterEvent, PrinterState> {
PrinterBloc() : super(PrinterState.initial()) {
on<PrinterEvent>(_onPrinterEvent);
}
Future<void> _onPrinterEvent(PrinterEvent event, Emitter<PrinterState> emit) {
return event.map(
indexChanged: (e) async {
emit(state.copyWith(index: e.index));
},
);
}
}
@@ -0,0 +1,363 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'printer_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models',
);
/// @nodoc
mixin _$PrinterEvent {
int get index => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(int index) indexChanged,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(int index)? indexChanged,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(int index)? indexChanged,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_IndexChanged value) indexChanged,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_IndexChanged value)? indexChanged,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_IndexChanged value)? indexChanged,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
/// Create a copy of PrinterEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PrinterEventCopyWith<PrinterEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PrinterEventCopyWith<$Res> {
factory $PrinterEventCopyWith(
PrinterEvent value,
$Res Function(PrinterEvent) then,
) = _$PrinterEventCopyWithImpl<$Res, PrinterEvent>;
@useResult
$Res call({int index});
}
/// @nodoc
class _$PrinterEventCopyWithImpl<$Res, $Val extends PrinterEvent>
implements $PrinterEventCopyWith<$Res> {
_$PrinterEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PrinterEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? index = null}) {
return _then(
_value.copyWith(
index: null == index
? _value.index
: index // ignore: cast_nullable_to_non_nullable
as int,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$IndexChangedImplCopyWith<$Res>
implements $PrinterEventCopyWith<$Res> {
factory _$$IndexChangedImplCopyWith(
_$IndexChangedImpl value,
$Res Function(_$IndexChangedImpl) then,
) = __$$IndexChangedImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({int index});
}
/// @nodoc
class __$$IndexChangedImplCopyWithImpl<$Res>
extends _$PrinterEventCopyWithImpl<$Res, _$IndexChangedImpl>
implements _$$IndexChangedImplCopyWith<$Res> {
__$$IndexChangedImplCopyWithImpl(
_$IndexChangedImpl _value,
$Res Function(_$IndexChangedImpl) _then,
) : super(_value, _then);
/// Create a copy of PrinterEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? index = null}) {
return _then(
_$IndexChangedImpl(
null == index
? _value.index
: index // ignore: cast_nullable_to_non_nullable
as int,
),
);
}
}
/// @nodoc
class _$IndexChangedImpl implements _IndexChanged {
const _$IndexChangedImpl(this.index);
@override
final int index;
@override
String toString() {
return 'PrinterEvent.indexChanged(index: $index)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$IndexChangedImpl &&
(identical(other.index, index) || other.index == index));
}
@override
int get hashCode => Object.hash(runtimeType, index);
/// Create a copy of PrinterEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$IndexChangedImplCopyWith<_$IndexChangedImpl> get copyWith =>
__$$IndexChangedImplCopyWithImpl<_$IndexChangedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(int index) indexChanged,
}) {
return indexChanged(index);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(int index)? indexChanged,
}) {
return indexChanged?.call(index);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(int index)? indexChanged,
required TResult orElse(),
}) {
if (indexChanged != null) {
return indexChanged(index);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_IndexChanged value) indexChanged,
}) {
return indexChanged(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_IndexChanged value)? indexChanged,
}) {
return indexChanged?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_IndexChanged value)? indexChanged,
required TResult orElse(),
}) {
if (indexChanged != null) {
return indexChanged(this);
}
return orElse();
}
}
abstract class _IndexChanged implements PrinterEvent {
const factory _IndexChanged(final int index) = _$IndexChangedImpl;
@override
int get index;
/// Create a copy of PrinterEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$IndexChangedImplCopyWith<_$IndexChangedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$PrinterState {
int get index => throw _privateConstructorUsedError;
/// Create a copy of PrinterState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PrinterStateCopyWith<PrinterState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $PrinterStateCopyWith<$Res> {
factory $PrinterStateCopyWith(
PrinterState value,
$Res Function(PrinterState) then,
) = _$PrinterStateCopyWithImpl<$Res, PrinterState>;
@useResult
$Res call({int index});
}
/// @nodoc
class _$PrinterStateCopyWithImpl<$Res, $Val extends PrinterState>
implements $PrinterStateCopyWith<$Res> {
_$PrinterStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of PrinterState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? index = null}) {
return _then(
_value.copyWith(
index: null == index
? _value.index
: index // ignore: cast_nullable_to_non_nullable
as int,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$PrinterStateImplCopyWith<$Res>
implements $PrinterStateCopyWith<$Res> {
factory _$$PrinterStateImplCopyWith(
_$PrinterStateImpl value,
$Res Function(_$PrinterStateImpl) then,
) = __$$PrinterStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({int index});
}
/// @nodoc
class __$$PrinterStateImplCopyWithImpl<$Res>
extends _$PrinterStateCopyWithImpl<$Res, _$PrinterStateImpl>
implements _$$PrinterStateImplCopyWith<$Res> {
__$$PrinterStateImplCopyWithImpl(
_$PrinterStateImpl _value,
$Res Function(_$PrinterStateImpl) _then,
) : super(_value, _then);
/// Create a copy of PrinterState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? index = null}) {
return _then(
_$PrinterStateImpl(
index: null == index
? _value.index
: index // ignore: cast_nullable_to_non_nullable
as int,
),
);
}
}
/// @nodoc
class _$PrinterStateImpl implements _PrinterState {
_$PrinterStateImpl({this.index = 0});
@override
@JsonKey()
final int index;
@override
String toString() {
return 'PrinterState(index: $index)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PrinterStateImpl &&
(identical(other.index, index) || other.index == index));
}
@override
int get hashCode => Object.hash(runtimeType, index);
/// Create a copy of PrinterState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$PrinterStateImplCopyWith<_$PrinterStateImpl> get copyWith =>
__$$PrinterStateImplCopyWithImpl<_$PrinterStateImpl>(this, _$identity);
}
abstract class _PrinterState implements PrinterState {
factory _PrinterState({final int index}) = _$PrinterStateImpl;
@override
int get index;
/// Create a copy of PrinterState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$PrinterStateImplCopyWith<_$PrinterStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'printer_bloc.dart';
@freezed
class PrinterEvent with _$PrinterEvent {
const factory PrinterEvent.indexChanged(int index) = _IndexChanged;
}
@@ -0,0 +1,187 @@
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart' hide Order;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart' hide Order;
import '../../../common/function/app_function.dart';
import '../../../domain/order/order.dart';
import '../../../domain/outlet/outlet.dart';
import '../../../domain/printer/printer.dart';
import '../../../presentation/components/print/print_ui.dart';
part 'printer_form_event.dart';
part 'printer_form_state.dart';
part 'printer_form_bloc.freezed.dart';
@injectable
class PrinterFormBloc extends Bloc<PrinterFormEvent, PrinterFormState> {
final IPrinterRepository _printerRepository;
final IOutletRepository _outletRepository;
PrinterFormBloc(this._printerRepository, this._outletRepository)
: super(PrinterFormState.initial()) {
on<PrinterFormEvent>(_onPrinterFormEvent);
}
Future<void> _onPrinterFormEvent(
PrinterFormEvent event,
Emitter<PrinterFormState> emit,
) {
return event.map(
codeChanged: (e) async {
emit(state.copyWith(code: e.code));
},
nameChanged: (e) async {
emit(state.copyWith(name: e.name));
},
addressChanged: (e) async {
emit(state.copyWith(address: e.address));
},
typeChanged: (e) async {
emit(state.copyWith(type: e.type));
},
paperChanged: (e) async {
emit(state.copyWith(paper: e.paper));
},
created: (e) async {
Either<PrinterFailure, Unit> failureOrPrinter;
emit(state.copyWith(isCreating: true, failureOrCreateSuccess: none()));
final request = Printer(
id: generateRandomNumber(),
code: state.code,
name: state.name,
address: state.address,
paper: state.paper,
type: state.type,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
failureOrPrinter = await _printerRepository.createPrinter(request);
emit(
state.copyWith(
isCreating: false,
failureOrCreateSuccess: optionOf(failureOrPrinter),
),
);
},
updated: (e) async {
Either<PrinterFailure, Unit> failureOrPrinter;
emit(state.copyWith(isUpdate: true, failureOrUpdateSuccess: none()));
final request = Printer(
id: generateRandomNumber(),
code: state.code,
name: state.name,
address: state.address,
paper: state.paper,
type: state.type,
createdAt: DateTime.now(),
updatedAt: DateTime.now(),
);
failureOrPrinter = await _printerRepository.updatePrinter(
request,
e.id,
);
emit(
state.copyWith(
isUpdate: false,
failureOrUpdateSuccess: optionOf(failureOrPrinter),
),
);
},
deleted: (e) async {
Either<PrinterFailure, Unit> failureOrPrinter;
emit(state.copyWith(isDeleting: true, failureOrDeleteSuccess: none()));
failureOrPrinter = await _printerRepository.deletePrinter(e.id);
emit(
state.copyWith(
isDeleting: false,
failureOrDeleteSuccess: optionOf(failureOrPrinter),
),
);
},
printTest: (e) async {
Either<PrinterFailure, bool> failureOrPrinter;
emit(state.copyWith(isPrinting: true, failureOrPrintTest: none()));
final currentOutlet = await _outletRepository.currentOutlet();
// Ambil paper size dari DB, fallback ke state.paper jika belum tersimpan
final savedPrinter = await _printerRepository.getPrinterByCode(e.code);
final paper = savedPrinter.fold(
(_) => int.tryParse(state.paper) ?? 58,
(p) => int.tryParse(p.paper) ?? 58,
);
List<int> printValue = [];
if (e.code == "receipt") {
printValue = await PrintUi().printOrder(
order: Order.mockOrder(),
outlet: currentOutlet,
cashierName: 'Kasir Test',
paper: paper,
);
} else if (e.code == "checker") {
printValue = await PrintUi().printChecker(
order: Order.mockOrder(),
outlet: currentOutlet,
cashierName: 'Kasir Test',
paper: paper,
);
} else if (e.code == 'kitchen') {
printValue = await PrintUi().printKitchen(
order: Order.mockOrder(),
outlet: currentOutlet,
cashierName: 'Kasir Test',
paper: paper,
);
} else if (e.code == 'bar') {
printValue = await PrintUi().printBar(
order: Order.mockOrder(),
outlet: currentOutlet,
cashierName: 'Kasir Test',
paper: paper,
);
} else if (e.code == 'ticket') {
printValue = await PrintUi().printTicket(
order: Order.mockOrder(),
outlet: currentOutlet,
paper: paper,
);
}
final printer = Printer.fromTest(
code: e.code,
name: state.name,
address: e.macAccdress,
paper: paper.toString(),
type: state.type,
);
failureOrPrinter = await _printerRepository.printStruct(
printer,
printValue,
);
emit(
state.copyWith(
isPrinting: false,
failureOrPrintTest: optionOf(failureOrPrinter),
),
);
},
);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,18 @@
part of 'printer_form_bloc.dart';
@freezed
class PrinterFormEvent with _$PrinterFormEvent {
const factory PrinterFormEvent.codeChanged(String code) = _CodeChanged;
const factory PrinterFormEvent.nameChanged(String name) = _NameChanged;
const factory PrinterFormEvent.addressChanged(String address) =
_AddressChanged;
const factory PrinterFormEvent.typeChanged(String type) = _TypeChanged;
const factory PrinterFormEvent.paperChanged(String paper) = _PaperChanged;
const factory PrinterFormEvent.created() = _Created;
const factory PrinterFormEvent.updated(int id) = _Updated;
const factory PrinterFormEvent.deleted(int id) = _Deleted;
const factory PrinterFormEvent.printTest({
required String code,
required String macAccdress,
}) = _PrintTest;
}
@@ -0,0 +1,32 @@
part of 'printer_form_bloc.dart';
@freezed
class PrinterFormState with _$PrinterFormState {
factory PrinterFormState({
required String code,
required String name,
required String address,
required String paper,
required String type,
required Option<Either<PrinterFailure, Unit>> failureOrCreateSuccess,
required Option<Either<PrinterFailure, Unit>> failureOrUpdateSuccess,
required Option<Either<PrinterFailure, Unit>> failureOrDeleteSuccess,
required Option<Either<PrinterFailure, bool>> failureOrPrintTest,
@Default(false) isCreating,
@Default(false) isUpdate,
@Default(false) isDeleting,
@Default(false) isPrinting,
}) = _PrinterFormState;
factory PrinterFormState.initial() => PrinterFormState(
code: '',
name: '',
address: '',
paper: '58',
type: 'Bluetooth',
failureOrCreateSuccess: none(),
failureOrUpdateSuccess: none(),
failureOrDeleteSuccess: none(),
failureOrPrintTest: none(),
);
}

Some files were not shown because too many files have changed in this diff Show More