Compare commits

..
140 Commits
Author SHA1 Message Date
efrilm 9777f63426 chore: naikkan build number ke 1.0.12+19 2026-09-05 14:06:35 +07:00
efrilmandClaude Opus 5 7986164a17 fix: beri tiap tab pengaturan printer bloc sendiri
PrinterFormBloc dan PrinterLoaderBloc di-provide sekali secara global, sementara lima tab pengaturan printer hidup bersamaan di dalam TabBarView dan semuanya membaca-menulis state yang sama.

Karena created dan updated membangun entitas Printer sepenuhnya dari state itu (type, address, code, name, paper), tab yang terakhir menulis state akan menang, lalu tombol Simpan di tab mana pun menyimpan milik tab lain. Nilai awal state kebetulan type 'Bluetooth' — itu sebabnya printer kitchen tersimpan dengan alamat IP yang benar tapi tipe Bluetooth, dan cetakannya dikirim ke radio Bluetooth untuk mencari perangkat yang tidak pernah ada.

Provider global dihapus karena tidak ada tempat lain yang memakainya. Catatan: ini mencegah kerusakan baru, tidak memulihkan baris yang sudah terlanjur salah di SQLite — konfigurasi kelima tab perlu disimpan ulang.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:06:34 +07:00
efrilmandClaude Opus 5 32f64a197a fix: pulihkan koneksi Bluetooth dan deteksi kegagalan printer jaringan
Bluetooth: percobaan ulang connect sebelumnya tidak menutup socket lebih dulu, padahal 'read failed, socket might closed or timeout' justru berarti socket RFCOMM masih setengah terbuka — ketiga percobaan gagal identik dan retry-nya sia-sia. Tiap percobaan ulang kini didahului disconnect paksa.

connectBluetooth mengembalikan sukses begitu ADA koneksi tanpa memeriksa apakah itu printer yang diminta, dan tidak pernah mencatat MAC yang aktif. Kini memakai jalur yang sama dengan mencetak.

Izin runtime Bluetooth sebelumnya hanya diminta dari dialog pilih perangkat. Karena reinstall mencabut izin, kasir yang tidak pernah membuka dialog itu gagal cetak tanpa penjelasan. Status adapter, izin, dan pairing kini ikut di log, dan printer yang tidak ter-pairing digagalkan langsung dengan pesan yang menyebut tindakannya.

Jaringan: printTicket hanya menaruh byte di socket lalu menutup koneksi, tidak pernah membaca balik, sehingga kertas habis atau cover terbuka terlihat sama dengan sukses — itu sebabnya kegagalan kitchen tidak pernah muncul di Crashlytics. NetworkPrinterClient baru menanyakan kondisi printer lewat DLE EOT sebelum dan sesudah mencetak, dengan degradasi anggun untuk printer yang tidak mendukungnya.

Panggilan disconnect() ganda dihapus; printTicket sudah flush dan close sendiri, dan panggilan kedua tanpa await membuat error-nya tercatat sebagai crash fatal palsu. Ditambah jejak per station ke Crashlytics.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:06:22 +07:00
efrilmandClaude Opus 5 cb7139fc3e docs: tambahkan langkah PATH untuk fvm di bagian Instalasi
dart pub global activate memasang fvm ke folder bin pub yang belum tentu ada di PATH, dan setiap orang yang setup dari nol akan menabraknya tepat setelah langkah activate. Sebelumnya hanya disebut di Troubleshooting.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 20:46:47 +07:00
efrilm 951e154623 chore: base URL dev, exclude platform dir dari analyzer, dan naikkan versi ke 1.0.12+18
Perubahan ini sudah ada di working tree sebelum pekerjaan print dimulai; dikumpulkan di sini supaya tidak tercampur dengan commit perbaikan printer. Ditambah pembersihan import injectable yang tidak terpakai di main.dart.
2026-09-02 20:45:13 +07:00
efrilmandClaude Opus 5 ebcddca4bb docs: perbarui README untuk FVM, build_runner, dan cara run/build
Bagian setup lama tidak cuma kurang, tapi salah: diklaim environment dipilih otomatis dari debug/release, padahal datang dari --dart-define=ENV. Siapa pun yang mengikutinya akan menghasilkan APK 'production' yang menunjuk database dev. Tabel environment dan contoh kodenya juga sudah tidak sesuai isi lib/env.dart.

Ditambah: prasyarat FVM, langkah instalasi ber-fvm, perintah build per environment, bagian Code Generation (termasuk peringatan --delete-conflicting-outputs yang menghapus seluruh file generated sebelum build), dan Troubleshooting.

URL base sengaja tidak disalin ke README; cukup menunjuk lib/env.dart, karena menyalin nilai itulah yang membuat dokumen ini basi.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 20:44:24 +07:00
efrilmandClaude Opus 5 1b4caf45d5 fix: cetak semua station tanpa saling membatalkan
printStruckOrder berhenti di kegagalan pertama, jadi satu station gagal membuat semua station sesudahnya tidak pernah dicoba. Karena checker (Bluetooth) berada sebelum kitchen dan bar (Network) dalam rantai, satu kegagalan koneksi Bluetooth menghilangkan tiga tiket sekaligus, dua di antaranya di jaringan yang sehat.

Jalur printer Network juga mengembalikan right(false) saat gagal, yang lolos sebagai sukses ke pemanggil, sehingga kasir melihat 'berhasil dicetak' padahal tidak ada kertas keluar.

Perubahan: repository kini mengembalikan Stream<List<PrintStationResult>> dan tetap mencoba semua station; kegagalan Network jadi left; station Network berjalan paralel dengan rantai Bluetooth; station Bluetooth dikelompokkan per alamat agar perpindahan koneksi seminimal mungkin; CapabilityProfile di-cache.

Bluetooth: retry connect dengan backoff dan disconnect di tiap percobaan ulang (socket RFCOMM setengah terbuka membuat connect berulang gagal identik), jeda settle dikembalikan setelah dipangkas ke 300ms, satu lock untuk seluruh radio (bukan per MAC), izin runtime dipastikan di jalur cetak, dan repository jadi LazySingleton agar state koneksi benar-benar dibagi.

UI: dialog progres per-station menggantikan toast tunggal, lengkap dengan durasi tiap station dan tombol cetak ulang khusus yang gagal. Enam listener duplikat di halaman diganti satu listener terpusat di AppWidget. Menu Print di detail transaksi dapat item Print All.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 20:44:14 +07:00
efrilmandClaude Opus 5 038f4d65fe chore: pin Flutter 3.41.9 lewat FVM
Stack codegen project ini (freezed 2.x, build_runner 2.5, analyzer 7.7.1) hanya paham bahasa Dart sampai 3.9. Flutter 3.44+ membawa framework yang ditulis di bahasa 3.10+, dan analyzer 7.7.1 crash saat men-serialize-nya (visitDotShorthandPropertyAccess) sehingga build_runner tidak bisa jalan sama sekali.

3.41.9 adalah rilis terbaru yang framework-nya masih di bahasa 3.9. Versi dipin per-project lewat .fvmrc supaya tidak mengganggu project lain di mesin yang sama.

android/build/ ikut di-ignore; isinya artefak Gradle.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 20:43:49 +07:00
efrilmandClaude Opus 5 865897fc04 config: upgrade gradle 8.14.3, agp 8.11.1, kotlin 2.2.20
Flutter 3.47 menolak build dengan Gradle < 8.14.0, AGP < 8.11.1, dan
Kotlin < 2.2.20.

Hapus juga assets/icons/ dan assets/json/ dari pubspec: foldernya tidak
pernah ada dan tidak dirujuk dari lib/, menyebabkan error "unable to find
directory entry" saat build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-02 19:10:11 +07:00
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
efrilm 13b1b6e6b8 search text field 2025-10-24 14:00:53 +07:00
efrilm 4dbdcadeaf current outlet 2025-10-24 13:55:00 +07:00
efrilm 97c03bcf96 change name login form 2025-10-24 02:04:28 +07:00
efrilm 05609d592d main page 2025-10-24 02:02:21 +07:00
efrilm 59062f9af1 auth state 2025-10-24 02:02:00 +07:00
efrilm ca5d2a58e7 login 2025-10-24 01:16:50 +07:00
efrilm 5d9197c986 color and theme 2025-10-23 23:20:44 +07:00
efrilm 9a61cbecc4 crashlytic interceptro 2025-10-23 23:13:39 +07:00
efrilm cf8f0b373d logo, fonts, firebase analytic 2025-10-23 23:06:02 +07:00
efrilm 4fee7c4bb7 base project 2025-10-23 22:16:53 +07:00
552 changed files with 118967 additions and 382 deletions
+3
View File
@@ -0,0 +1,3 @@
{
"flutter": "3.41.9"
}
+6
View File
@@ -32,6 +32,7 @@ migrate_working_dir/
.pub-cache/
.pub/
/build/
android/build/
# Symbolication related
app.*.symbols
@@ -43,3 +44,8 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
# FVM - versi Flutter dipin di .fvmrc (ikut di-commit), SDK-nya tidak
# FVM Version Cache
.fvm/
+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"]
}
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"dart.flutterSdkPath": ".fvm/versions/3.41.9"
}
+323 -10
View File
@@ -1,16 +1,329 @@
# 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 |
|---|---|
| Version Manager | `fvm` — Flutter dipin di `.fvmrc` |
| 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
- **FVM** — project ini mengunci versi Flutter, jangan pakai Flutter global
- **Flutter 3.41.9** (Dart 3.11.5) — dipin di `.fvmrc`
- Android SDK / Xcode (untuk iOS)
- Firebase project yang sudah dikonfigurasi
> **Kenapa versinya dikunci?** Stack code generation project ini (`freezed` 2.x, `build_runner` 2.5, `analyzer` 7.7.1) hanya paham bahasa Dart sampai 3.9. Flutter 3.44 ke atas membawa framework yang ditulis di bahasa 3.10+, dan `analyzer` 7.7.1 crash saat membacanya. Selama stack codegen belum dinaikkan, **Flutter 3.41.9 adalah versi terbaru yang masih bisa menjalankan `build_runner`.** Lihat [Troubleshooting](#troubleshooting).
### Instalasi
```bash
# Clone repository
git clone <repo-url>
cd apskel-pos-flutter-v2
# Pasang FVM (sekali per mesin)
dart pub global activate fvm
# Ambil & pakai versi Flutter yang dipin di .fvmrc
fvm install
fvm use
```
`dart pub global activate` memasang `fvm` ke folder bin milik pub yang **belum tentu ada di PATH**. Kalau muncul `fvm: command not found` / `The term 'fvm' is not recognized`, tambahkan foldernya sekali saja:
```powershell
# Windows PowerShell — permanen, buka terminal baru setelahnya
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path','User') + ";$env:LOCALAPPDATA\Pub\Cache\bin", 'User')
# Untuk terminal yang sedang terbuka
$env:Path += ";$env:LOCALAPPDATA\Pub\Cache\bin"
```
```bash
# macOS / Linux — tambahkan ke ~/.zshrc atau ~/.bashrc
export PATH="$PATH:$HOME/.pub-cache/bin"
```
Setelah `fvm` bisa dipanggil, lanjutkan:
```bash
# Install dependencies
fvm flutter pub get
# Generate kode
fvm dart run build_runner build
```
> Semua perintah Flutter/Dart di project ini **harus diawali `fvm`**. `flutter run` tanpa `fvm` memakai Flutter global dan hasilnya bisa berbeda.
### Menjalankan App
Environment **tidak** ditentukan otomatis dari debug/release — harus dioper lewat `--dart-define`:
```bash
# Development
fvm flutter run --dart-define=ENV=dev
# Production
fvm flutter run --dart-define=ENV=prod
# Production, release mode
fvm flutter run --release --dart-define=ENV=prod
```
Kalau `ENV` tidak dioper, nilainya jatuh ke `dev` (lihat `defaultValue` di `lib/main.dart`).
Di VSCode sudah tersedia konfigurasi **Dev** dan **Prod** di `.vscode/launch.json`, tinggal pilih di panel Run and Debug.
### Build
`--dart-define=ENV=prod` wajib ikut, kalau tidak APK-nya akan memakai database dan base URL milik dev:
```bash
# APK
fvm flutter build apk --release --dart-define=ENV=prod
# App Bundle (Play Store)
fvm flutter build appbundle --release --dart-define=ENV=prod
# iOS
fvm flutter build ipa --release --dart-define=ENV=prod
```
---
## Code Generation
Project ini banyak memakai kode generated (`freezed`, `injectable`, `auto_route`, `json_serializable`, `flutter_gen`). Kode itu **wajib di-generate ulang** setiap kali kamu:
- menambah/mengubah kelas `@freezed` (entity, event, state, DTO)
- menambah/mengubah anotasi DI (`@injectable`, `@LazySingleton`, `@Injectable(as: ...)`)
- menambah halaman baru dengan `@RoutePage()`
- menambah aset di `pubspec.yaml`
```bash
# Sekali jalan
fvm dart run build_runner build
# Mode watch — regenerate otomatis saat file berubah, enak dipakai saat ngoding
fvm dart run build_runner watch
```
> **Hindari `--delete-conflicting-outputs`.** Flag itu menghapus seluruh file generated **sebelum** mulai build. Kalau build-nya gagal di tengah jalan, kamu berakhir tanpa kode generated sama sekali dan project tidak bisa di-compile. Pakai hanya kalau build_runner benar-benar mengeluh soal konflik output, dan pastikan working tree-mu bersih dulu supaya bisa `git restore`.
---
## Environment
Konfigurasi environment ada di `lib/env.dart` — **itu sumber kebenarannya**, jangan disalin ke sini karena gampang basi.
| Environment | Database |
|---|---|
| `dev` | `apskel_pos_staging.db` |
| `prod` | `apskel_pos_prod.db` |
Environment dipilih dari `--dart-define=ENV=...` di `lib/main.dart`:
```dart
const String env = String.fromEnvironment('ENV', defaultValue: 'dev');
await configureDependencies(env);
```
Nilai `env` diteruskan ke `injectable`, yang lalu memilih antara `DevEnv` (`@dev`) dan `ProdEnv` (`@prod`). Menambah environment baru berarti menambah kelas ber-anotasi di `lib/env.dart`, lalu generate ulang.
Karena `dev` dan `prod` memakai **nama database berbeda**, berpindah environment di perangkat yang sama tidak akan mencampur datanya.
---
## 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
- Selalu pakai `fvm flutter` / `fvm dart`, bukan `flutter` / `dart` global
- Jangan edit `injection.config.dart` dan file `*.freezed.dart` / `*.g.dart` secara manual — file tersebut di-generate otomatis
- Setelah mengubah kelas `@freezed` atau anotasi DI, jalankan build_runner sebelum menjalankan app
- Gunakan `log()` dari `dart:developer` untuk logging, bukan `print()`
- `print()` dinonaktifkan di release mode
---
## Troubleshooting
### `build_runner` gagal: `Missing implementation of visitDotShorthandPropertyAccess`
Kamu sedang memakai Flutter yang terlalu baru. Cek:
```bash
fvm flutter --version # harus 3.41.9
flutter --version # ini Flutter global, boleh versi apa saja
```
Kalau versinya bukan 3.41.9, artinya perintahnya jalan tanpa `fvm`. Log build juga memberi petunjuk yang sama:
```
SDK language version 3.13.0 is newer than `analyzer` language version 3.9.0
```
Perbaikannya: `fvm use`, lalu ulangi dengan awalan `fvm`.
Menaikkan Flutter melewati 3.41.x mengharuskan seluruh stack codegen ikut naik — `freezed` 2 → 3/4, `build_runner` → 2.16, `injectable_generator` 2 → 3, `auto_route` 9 → 10. `freezed` 3 mewajibkan tiap kelas dideklarasikan `abstract`/`sealed` dan menghapus `when`/`map` (diganti pattern matching), jadi ini pekerjaan tersendiri, bukan sambilan.
### Project tidak bisa di-compile, banyak error `_$Something` tidak ditemukan
Kode generated-nya hilang atau belum dibuat. Jalankan:
```bash
fvm dart run build_runner build
```
### `fvm: command not found`
FVM terpasang di `~/AppData/Local/Pub/Cache/bin` (Windows) atau `~/.pub-cache/bin` (macOS/Linux) yang mungkin belum ada di `PATH`. Tambahkan direktori itu ke `PATH`, atau panggil dengan path lengkap.
+25 -23
View File
@@ -1,28 +1,30 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
sort_pub_dependencies: false
prefer_relative_imports: true
prefer_const_constructors: true
prefer_const_literals_to_create_immutables: true
prefer_const_declarations: true
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
errors:
missing_required_param: error
missing_return: error
must_be_immutable: error
sort_unnamed_constructors_first: ignore
invalid_annotation_target: ignore
use_build_context_synchronously: ignore
deprecated_member_use: ignore
exclude:
- test/generated/**
- "**/**.g.dart"
- "**/**.freezed.dart"
- build/**
- android/**
- ios/**
- web/**
- windows/**
- macos/**
- linux/**
+13 -2
View File
@@ -3,16 +3,18 @@ plugins {
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
id("com.google.gms.google-services")
}
android {
namespace = "com.example.apskel_pos_flutter_v2"
namespace = "com.apskel.pos"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
isCoreLibraryDesugaringEnabled = true
}
kotlinOptions {
@@ -21,7 +23,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.apskel_pos_flutter_v2"
applicationId = "com.apskel.pos"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
@@ -42,3 +44,12 @@ android {
flutter {
source = "../.."
}
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"))
implementation("com.google.firebase:firebase-analytics")
}
+29
View File
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "765730035527",
"project_id": "apskel-pos-v2",
"storage_bucket": "apskel-pos-v2.firebasestorage.app"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:765730035527:android:498defd7071336dd241e62",
"android_client_info": {
"package_name": "com.apskel.pos"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyAOZwVSQwUeeM9BjcyTOK9GUh8AmTWucuc"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
+22 -2
View File
@@ -1,8 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<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_flutter_v2"
android:label="Apskel POS"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
android:exported="true"
@@ -30,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
@@ -1,4 +1,4 @@
package com.example.apskel_pos_flutter_v2
package com.apskel.pos
import io.flutter.embedding.android.FlutterActivity
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 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
+1 -1
View File
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip
+3 -2
View File
@@ -18,8 +18,9 @@ pluginManagement {
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.7.3" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
id("com.android.application") version "8.11.1" apply false
id("org.jetbrains.kotlin.android") version "2.2.20" apply false
id("com.google.gms.google-services") version "4.4.4" apply false
}
include(":app")
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 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:
+1
View File
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
+1
View File
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
+43
View File
@@ -0,0 +1,43 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '13.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
+2 -2
View File
@@ -427,7 +427,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -484,7 +484,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -1,122 +1 @@
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@3x.png",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@1x.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@1x.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@1x.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Icon-App-83.5x83.5@2x.png",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "Icon-App-1024x1024@1x.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
{"images":[{"size":"20x20","idiom":"iphone","filename":"Icon-App-20x20@2x.png","scale":"2x"},{"size":"20x20","idiom":"iphone","filename":"Icon-App-20x20@3x.png","scale":"3x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@1x.png","scale":"1x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@2x.png","scale":"2x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@3x.png","scale":"3x"},{"size":"40x40","idiom":"iphone","filename":"Icon-App-40x40@2x.png","scale":"2x"},{"size":"40x40","idiom":"iphone","filename":"Icon-App-40x40@3x.png","scale":"3x"},{"size":"57x57","idiom":"iphone","filename":"Icon-App-57x57@1x.png","scale":"1x"},{"size":"57x57","idiom":"iphone","filename":"Icon-App-57x57@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"Icon-App-60x60@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"Icon-App-60x60@3x.png","scale":"3x"},{"size":"20x20","idiom":"ipad","filename":"Icon-App-20x20@1x.png","scale":"1x"},{"size":"20x20","idiom":"ipad","filename":"Icon-App-20x20@2x.png","scale":"2x"},{"size":"29x29","idiom":"ipad","filename":"Icon-App-29x29@1x.png","scale":"1x"},{"size":"29x29","idiom":"ipad","filename":"Icon-App-29x29@2x.png","scale":"2x"},{"size":"40x40","idiom":"ipad","filename":"Icon-App-40x40@1x.png","scale":"1x"},{"size":"40x40","idiom":"ipad","filename":"Icon-App-40x40@2x.png","scale":"2x"},{"size":"50x50","idiom":"ipad","filename":"Icon-App-50x50@1x.png","scale":"1x"},{"size":"50x50","idiom":"ipad","filename":"Icon-App-50x50@2x.png","scale":"2x"},{"size":"72x72","idiom":"ipad","filename":"Icon-App-72x72@1x.png","scale":"1x"},{"size":"72x72","idiom":"ipad","filename":"Icon-App-72x72@2x.png","scale":"2x"},{"size":"76x76","idiom":"ipad","filename":"Icon-App-76x76@1x.png","scale":"1x"},{"size":"76x76","idiom":"ipad","filename":"Icon-App-76x76@2x.png","scale":"2x"},{"size":"83.5x83.5","idiom":"ipad","filename":"Icon-App-83.5x83.5@2x.png","scale":"2x"},{"size":"1024x1024","idiom":"ios-marketing","filename":"Icon-App-1024x1024@1x.png","scale":"1x"}],"info":{"version":1,"author":"xcode"}}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 B

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 762 B

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+15
View File
@@ -0,0 +1,15 @@
# Generate: dart run flutter_launcher_icons -f launcher_icon.yaml
flutter_launcher_icons:
android: "launcher_icon"
ios: true
image_path: "assets/images/logo.png"
remove_alpha_ios: true
min_sdk_android: 21 # android min sdk min:16, default 21
web:
generate: true
image_path: "assets/images/logo.png"
windows:
generate: true
image_path: "assets/images/logo.png"
icon_size: 48
@@ -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(),
);
}
+66
View File
@@ -0,0 +1,66 @@
import 'package:dartz/dartz.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:injectable/injectable.dart';
import '../../domain/auth/auth.dart';
import '../../domain/outlet/outlet.dart';
part 'auth_event.dart';
part 'auth_state.dart';
part 'auth_bloc.freezed.dart';
@injectable
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final IAuthRepository _repository;
final IOutletRepository _outletRepository;
AuthBloc(this._repository, this._outletRepository)
: super(AuthState.initial()) {
on<AuthEvent>(_onAuthEvent);
}
Future<void> _onAuthEvent(AuthEvent event, Emitter<AuthState> emit) {
return event.map(
fetchCurrentUser: (e) async {
emit(state.copyWith(failureOption: none()));
final token = await _repository.hasToken();
final failureOrAuth = await _repository.currentUser();
failureOrAuth.fold(
(f) => emit(
state.copyWith(
failureOption: optionOf(f),
status: token
? const AuthStatus.authenticated()
: const AuthStatus.unauthenticated(),
),
),
(user) => emit(
state.copyWith(
user: user,
status: token
? const AuthStatus.authenticated()
: const AuthStatus.unauthenticated(),
),
),
);
add(AuthEvent.fetchCurrentOutlet(state.user.outletId));
},
fetchCurrentOutlet: (e) async {
emit(state.copyWith(failureOutletOption: none()));
final failureOrOutlet = await _outletRepository.getOutletById(
e.outletId,
);
failureOrOutlet.fold(
(f) => emit(state.copyWith(failureOutletOption: optionOf(f))),
(outlet) => emit(state.copyWith(outlet: outlet)),
);
},
);
}
}
File diff suppressed because it is too large Load Diff
+8
View File
@@ -0,0 +1,8 @@
part of 'auth_bloc.dart';
@freezed
class AuthEvent with _$AuthEvent {
const factory AuthEvent.fetchCurrentUser() = _FetchCurrentUser;
const factory AuthEvent.fetchCurrentOutlet(String outletId) =
_FetchCurrentOutlet;
}
+33
View File
@@ -0,0 +1,33 @@
part of 'auth_bloc.dart';
@freezed
class AuthState with _$AuthState {
const AuthState._();
const factory AuthState({
required User user,
required Outlet outlet,
@Default(AuthStatus.initial()) AuthStatus status,
required Option<AuthFailure> failureOption,
required Option<OutletFailure> failureOutletOption,
@Default(false) bool isFetching,
@Default(false) bool isFetchingOutlet,
}) = _AuthState;
factory AuthState.initial() => AuthState(
user: User.empty(),
failureOption: none(),
outlet: Outlet.empty(),
failureOutletOption: none(),
);
bool get isAuthenticated => status == const AuthStatus.authenticated();
bool get isInitial => status == const AuthStatus.initial();
}
@freezed
sealed class AuthStatus with _$AuthStatus {
const factory AuthStatus.authenticated() = _Authenticated;
const factory AuthStatus.unauthenticated() = _Unauthenticated;
const factory AuthStatus.initial() = _Initial;
}
@@ -0,0 +1,76 @@
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 '../../../common/service/device_info_service.dart';
import '../../../common/service/fcm_service.dart';
import '../../../domain/auth/auth.dart';
part 'login_form_event.dart';
part 'login_form_state.dart';
part 'login_form_bloc.freezed.dart';
@injectable
class LoginFormBloc extends Bloc<LoginFormEvent, LoginFormState> {
final IAuthRepository _authRepository;
final FcmService _fcmService;
final DeviceInfoService _deviceInfoService;
LoginFormBloc(
this._authRepository,
this._fcmService,
this._deviceInfoService,
) : super(LoginFormState.initial()) {
on<LoginFormEvent>(_onLoginFormEvent);
}
Future<void> _onLoginFormEvent(
LoginFormEvent event,
Emitter<LoginFormState> emit,
) {
return event.map(
emailChanged: (e) async {
emit(state.copyWith(email: e.email, failureOrLoginOption: none()));
},
passwordChanged: (e) async {
emit(
state.copyWith(password: e.password, failureOrLoginOption: none()),
);
},
submitted: (e) async {
Either<AuthFailure, Login>? failureOrLogin;
emit(state.copyWith(isSubmitting: true, failureOrLoginOption: none()));
final emailValid = state.email.isNotEmpty;
final passwordValid = state.password.isNotEmpty;
log(
'emailValid: $emailValid, passwordValid: $passwordValid, email: ${state.email}, password: ${state.password}',
);
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(
state.copyWith(
isSubmitting: false,
failureOrLoginOption: optionOf(failureOrLogin),
),
);
}
emit(state.copyWith(showErrorMessages: true, isSubmitting: false));
},
);
}
}
@@ -0,0 +1,734 @@
// 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 'login_form_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 _$LoginFormEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String email) emailChanged,
required TResult Function(String password) passwordChanged,
required TResult Function() submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String email)? emailChanged,
TResult? Function(String password)? passwordChanged,
TResult? Function()? submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String email)? emailChanged,
TResult Function(String password)? passwordChanged,
TResult Function()? submitted,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_EmailChanged value) emailChanged,
required TResult Function(_PasswordChanged value) passwordChanged,
required TResult Function(_Submitted value) submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_EmailChanged value)? emailChanged,
TResult? Function(_PasswordChanged value)? passwordChanged,
TResult? Function(_Submitted value)? submitted,
}) => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_EmailChanged value)? emailChanged,
TResult Function(_PasswordChanged value)? passwordChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LoginFormEventCopyWith<$Res> {
factory $LoginFormEventCopyWith(
LoginFormEvent value,
$Res Function(LoginFormEvent) then,
) = _$LoginFormEventCopyWithImpl<$Res, LoginFormEvent>;
}
/// @nodoc
class _$LoginFormEventCopyWithImpl<$Res, $Val extends LoginFormEvent>
implements $LoginFormEventCopyWith<$Res> {
_$LoginFormEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$EmailChangedImplCopyWith<$Res> {
factory _$$EmailChangedImplCopyWith(
_$EmailChangedImpl value,
$Res Function(_$EmailChangedImpl) then,
) = __$$EmailChangedImplCopyWithImpl<$Res>;
@useResult
$Res call({String email});
}
/// @nodoc
class __$$EmailChangedImplCopyWithImpl<$Res>
extends _$LoginFormEventCopyWithImpl<$Res, _$EmailChangedImpl>
implements _$$EmailChangedImplCopyWith<$Res> {
__$$EmailChangedImplCopyWithImpl(
_$EmailChangedImpl _value,
$Res Function(_$EmailChangedImpl) _then,
) : super(_value, _then);
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? email = null}) {
return _then(
_$EmailChangedImpl(
null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$EmailChangedImpl implements _EmailChanged {
const _$EmailChangedImpl(this.email);
@override
final String email;
@override
String toString() {
return 'LoginFormEvent.emailChanged(email: $email)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$EmailChangedImpl &&
(identical(other.email, email) || other.email == email));
}
@override
int get hashCode => Object.hash(runtimeType, email);
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$EmailChangedImplCopyWith<_$EmailChangedImpl> get copyWith =>
__$$EmailChangedImplCopyWithImpl<_$EmailChangedImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String email) emailChanged,
required TResult Function(String password) passwordChanged,
required TResult Function() submitted,
}) {
return emailChanged(email);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String email)? emailChanged,
TResult? Function(String password)? passwordChanged,
TResult? Function()? submitted,
}) {
return emailChanged?.call(email);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String email)? emailChanged,
TResult Function(String password)? passwordChanged,
TResult Function()? submitted,
required TResult orElse(),
}) {
if (emailChanged != null) {
return emailChanged(email);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_EmailChanged value) emailChanged,
required TResult Function(_PasswordChanged value) passwordChanged,
required TResult Function(_Submitted value) submitted,
}) {
return emailChanged(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_EmailChanged value)? emailChanged,
TResult? Function(_PasswordChanged value)? passwordChanged,
TResult? Function(_Submitted value)? submitted,
}) {
return emailChanged?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_EmailChanged value)? emailChanged,
TResult Function(_PasswordChanged value)? passwordChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) {
if (emailChanged != null) {
return emailChanged(this);
}
return orElse();
}
}
abstract class _EmailChanged implements LoginFormEvent {
const factory _EmailChanged(final String email) = _$EmailChangedImpl;
String get email;
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$EmailChangedImplCopyWith<_$EmailChangedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$PasswordChangedImplCopyWith<$Res> {
factory _$$PasswordChangedImplCopyWith(
_$PasswordChangedImpl value,
$Res Function(_$PasswordChangedImpl) then,
) = __$$PasswordChangedImplCopyWithImpl<$Res>;
@useResult
$Res call({String password});
}
/// @nodoc
class __$$PasswordChangedImplCopyWithImpl<$Res>
extends _$LoginFormEventCopyWithImpl<$Res, _$PasswordChangedImpl>
implements _$$PasswordChangedImplCopyWith<$Res> {
__$$PasswordChangedImplCopyWithImpl(
_$PasswordChangedImpl _value,
$Res Function(_$PasswordChangedImpl) _then,
) : super(_value, _then);
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({Object? password = null}) {
return _then(
_$PasswordChangedImpl(
null == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
),
);
}
}
/// @nodoc
class _$PasswordChangedImpl implements _PasswordChanged {
const _$PasswordChangedImpl(this.password);
@override
final String password;
@override
String toString() {
return 'LoginFormEvent.passwordChanged(password: $password)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PasswordChangedImpl &&
(identical(other.password, password) ||
other.password == password));
}
@override
int get hashCode => Object.hash(runtimeType, password);
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$PasswordChangedImplCopyWith<_$PasswordChangedImpl> get copyWith =>
__$$PasswordChangedImplCopyWithImpl<_$PasswordChangedImpl>(
this,
_$identity,
);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String email) emailChanged,
required TResult Function(String password) passwordChanged,
required TResult Function() submitted,
}) {
return passwordChanged(password);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String email)? emailChanged,
TResult? Function(String password)? passwordChanged,
TResult? Function()? submitted,
}) {
return passwordChanged?.call(password);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String email)? emailChanged,
TResult Function(String password)? passwordChanged,
TResult Function()? submitted,
required TResult orElse(),
}) {
if (passwordChanged != null) {
return passwordChanged(password);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_EmailChanged value) emailChanged,
required TResult Function(_PasswordChanged value) passwordChanged,
required TResult Function(_Submitted value) submitted,
}) {
return passwordChanged(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_EmailChanged value)? emailChanged,
TResult? Function(_PasswordChanged value)? passwordChanged,
TResult? Function(_Submitted value)? submitted,
}) {
return passwordChanged?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_EmailChanged value)? emailChanged,
TResult Function(_PasswordChanged value)? passwordChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) {
if (passwordChanged != null) {
return passwordChanged(this);
}
return orElse();
}
}
abstract class _PasswordChanged implements LoginFormEvent {
const factory _PasswordChanged(final String password) = _$PasswordChangedImpl;
String get password;
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$PasswordChangedImplCopyWith<_$PasswordChangedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$SubmittedImplCopyWith<$Res> {
factory _$$SubmittedImplCopyWith(
_$SubmittedImpl value,
$Res Function(_$SubmittedImpl) then,
) = __$$SubmittedImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$SubmittedImplCopyWithImpl<$Res>
extends _$LoginFormEventCopyWithImpl<$Res, _$SubmittedImpl>
implements _$$SubmittedImplCopyWith<$Res> {
__$$SubmittedImplCopyWithImpl(
_$SubmittedImpl _value,
$Res Function(_$SubmittedImpl) _then,
) : super(_value, _then);
/// Create a copy of LoginFormEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$SubmittedImpl implements _Submitted {
const _$SubmittedImpl();
@override
String toString() {
return 'LoginFormEvent.submitted()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$SubmittedImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String email) emailChanged,
required TResult Function(String password) passwordChanged,
required TResult Function() submitted,
}) {
return submitted();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String email)? emailChanged,
TResult? Function(String password)? passwordChanged,
TResult? Function()? submitted,
}) {
return submitted?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String email)? emailChanged,
TResult Function(String password)? passwordChanged,
TResult Function()? submitted,
required TResult orElse(),
}) {
if (submitted != null) {
return submitted();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_EmailChanged value) emailChanged,
required TResult Function(_PasswordChanged value) passwordChanged,
required TResult Function(_Submitted value) submitted,
}) {
return submitted(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_EmailChanged value)? emailChanged,
TResult? Function(_PasswordChanged value)? passwordChanged,
TResult? Function(_Submitted value)? submitted,
}) {
return submitted?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_EmailChanged value)? emailChanged,
TResult Function(_PasswordChanged value)? passwordChanged,
TResult Function(_Submitted value)? submitted,
required TResult orElse(),
}) {
if (submitted != null) {
return submitted(this);
}
return orElse();
}
}
abstract class _Submitted implements LoginFormEvent {
const factory _Submitted() = _$SubmittedImpl;
}
/// @nodoc
mixin _$LoginFormState {
String get email => throw _privateConstructorUsedError;
String get password => throw _privateConstructorUsedError;
Option<Either<AuthFailure, Login>> get failureOrLoginOption =>
throw _privateConstructorUsedError;
bool get isSubmitting => throw _privateConstructorUsedError;
bool get showErrorMessages => throw _privateConstructorUsedError;
/// Create a copy of LoginFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$LoginFormStateCopyWith<LoginFormState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $LoginFormStateCopyWith<$Res> {
factory $LoginFormStateCopyWith(
LoginFormState value,
$Res Function(LoginFormState) then,
) = _$LoginFormStateCopyWithImpl<$Res, LoginFormState>;
@useResult
$Res call({
String email,
String password,
Option<Either<AuthFailure, Login>> failureOrLoginOption,
bool isSubmitting,
bool showErrorMessages,
});
}
/// @nodoc
class _$LoginFormStateCopyWithImpl<$Res, $Val extends LoginFormState>
implements $LoginFormStateCopyWith<$Res> {
_$LoginFormStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of LoginFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? email = null,
Object? password = null,
Object? failureOrLoginOption = null,
Object? isSubmitting = null,
Object? showErrorMessages = null,
}) {
return _then(
_value.copyWith(
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String,
password: null == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
failureOrLoginOption: null == failureOrLoginOption
? _value.failureOrLoginOption
: failureOrLoginOption // ignore: cast_nullable_to_non_nullable
as Option<Either<AuthFailure, Login>>,
isSubmitting: null == isSubmitting
? _value.isSubmitting
: isSubmitting // ignore: cast_nullable_to_non_nullable
as bool,
showErrorMessages: null == showErrorMessages
? _value.showErrorMessages
: showErrorMessages // ignore: cast_nullable_to_non_nullable
as bool,
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$LoginFormStateImplCopyWith<$Res>
implements $LoginFormStateCopyWith<$Res> {
factory _$$LoginFormStateImplCopyWith(
_$LoginFormStateImpl value,
$Res Function(_$LoginFormStateImpl) then,
) = __$$LoginFormStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({
String email,
String password,
Option<Either<AuthFailure, Login>> failureOrLoginOption,
bool isSubmitting,
bool showErrorMessages,
});
}
/// @nodoc
class __$$LoginFormStateImplCopyWithImpl<$Res>
extends _$LoginFormStateCopyWithImpl<$Res, _$LoginFormStateImpl>
implements _$$LoginFormStateImplCopyWith<$Res> {
__$$LoginFormStateImplCopyWithImpl(
_$LoginFormStateImpl _value,
$Res Function(_$LoginFormStateImpl) _then,
) : super(_value, _then);
/// Create a copy of LoginFormState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? email = null,
Object? password = null,
Object? failureOrLoginOption = null,
Object? isSubmitting = null,
Object? showErrorMessages = null,
}) {
return _then(
_$LoginFormStateImpl(
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String,
password: null == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
failureOrLoginOption: null == failureOrLoginOption
? _value.failureOrLoginOption
: failureOrLoginOption // ignore: cast_nullable_to_non_nullable
as Option<Either<AuthFailure, Login>>,
isSubmitting: null == isSubmitting
? _value.isSubmitting
: isSubmitting // ignore: cast_nullable_to_non_nullable
as bool,
showErrorMessages: null == showErrorMessages
? _value.showErrorMessages
: showErrorMessages // ignore: cast_nullable_to_non_nullable
as bool,
),
);
}
}
/// @nodoc
class _$LoginFormStateImpl implements _LoginFormState {
const _$LoginFormStateImpl({
required this.email,
required this.password,
required this.failureOrLoginOption,
this.isSubmitting = false,
this.showErrorMessages = false,
});
@override
final String email;
@override
final String password;
@override
final Option<Either<AuthFailure, Login>> failureOrLoginOption;
@override
@JsonKey()
final bool isSubmitting;
@override
@JsonKey()
final bool showErrorMessages;
@override
String toString() {
return 'LoginFormState(email: $email, password: $password, failureOrLoginOption: $failureOrLoginOption, isSubmitting: $isSubmitting, showErrorMessages: $showErrorMessages)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LoginFormStateImpl &&
(identical(other.email, email) || other.email == email) &&
(identical(other.password, password) ||
other.password == password) &&
(identical(other.failureOrLoginOption, failureOrLoginOption) ||
other.failureOrLoginOption == failureOrLoginOption) &&
(identical(other.isSubmitting, isSubmitting) ||
other.isSubmitting == isSubmitting) &&
(identical(other.showErrorMessages, showErrorMessages) ||
other.showErrorMessages == showErrorMessages));
}
@override
int get hashCode => Object.hash(
runtimeType,
email,
password,
failureOrLoginOption,
isSubmitting,
showErrorMessages,
);
/// Create a copy of LoginFormState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$LoginFormStateImplCopyWith<_$LoginFormStateImpl> get copyWith =>
__$$LoginFormStateImplCopyWithImpl<_$LoginFormStateImpl>(
this,
_$identity,
);
}
abstract class _LoginFormState implements LoginFormState {
const factory _LoginFormState({
required final String email,
required final String password,
required final Option<Either<AuthFailure, Login>> failureOrLoginOption,
final bool isSubmitting,
final bool showErrorMessages,
}) = _$LoginFormStateImpl;
@override
String get email;
@override
String get password;
@override
Option<Either<AuthFailure, Login>> get failureOrLoginOption;
@override
bool get isSubmitting;
@override
bool get showErrorMessages;
/// Create a copy of LoginFormState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$LoginFormStateImplCopyWith<_$LoginFormStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,9 @@
part of 'login_form_bloc.dart';
@freezed
class LoginFormEvent with _$LoginFormEvent {
const factory LoginFormEvent.emailChanged(String email) = _EmailChanged;
const factory LoginFormEvent.passwordChanged(String password) =
_PasswordChanged;
const factory LoginFormEvent.submitted() = _Submitted;
}
@@ -0,0 +1,15 @@
part of 'login_form_bloc.dart';
@freezed
class LoginFormState with _$LoginFormState {
const factory LoginFormState({
required String email,
required String password,
required Option<Either<AuthFailure, Login>> failureOrLoginOption,
@Default(false) bool isSubmitting,
@Default(false) bool showErrorMessages,
}) = _LoginFormState;
factory LoginFormState.initial() =>
LoginFormState(email: '', password: '', failureOrLoginOption: 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/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;
}

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