update
This commit is contained in:
@@ -3,7 +3,11 @@
|
||||
/// Riverpod providers for managing orders state.
|
||||
library;
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/features/orders/data/datasources/order_status_local_datasource.dart';
|
||||
import 'package:worker/features/orders/data/models/order_status_model.dart';
|
||||
import 'package:worker/features/orders/domain/entities/order.dart';
|
||||
import 'package:worker/features/orders/domain/entities/order_detail.dart';
|
||||
import 'package:worker/features/orders/domain/entities/order_status.dart';
|
||||
@@ -171,6 +175,37 @@ Future<int> totalOrdersCount(Ref ref) async {
|
||||
);
|
||||
}
|
||||
|
||||
/// Order Status Hive Box Provider
|
||||
///
|
||||
/// Provides direct access to the Hive box for order statuses.
|
||||
/// Use this to read data directly from Hive in the UI.
|
||||
@riverpod
|
||||
Box<dynamic> orderStatusHiveBox(Ref ref) {
|
||||
return Hive.box(HiveBoxNames.orderStatusBox);
|
||||
}
|
||||
|
||||
/// Helper: Get Order Status by Label
|
||||
///
|
||||
/// Returns the OrderStatusModel for a given label (e.g., "Chờ phê duyệt").
|
||||
/// Returns null if not found.
|
||||
OrderStatusModel? getOrderStatusByLabel(Box<dynamic> box, String label) {
|
||||
final statuses = box.values.whereType<OrderStatusModel>();
|
||||
try {
|
||||
return statuses.firstWhere((status) => status.label == label);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper: Get Order Status by Index
|
||||
///
|
||||
/// Returns the OrderStatusModel for a given index.
|
||||
/// Returns null if not found.
|
||||
OrderStatusModel? getOrderStatusByIndex(Box<dynamic> box, int index) {
|
||||
final status = box.get(index);
|
||||
return status is OrderStatusModel ? status : null;
|
||||
}
|
||||
|
||||
/// Order Status List Provider
|
||||
///
|
||||
/// Provides cached order status list with automatic refresh.
|
||||
|
||||
@@ -344,6 +344,62 @@ final class TotalOrdersCountProvider
|
||||
|
||||
String _$totalOrdersCountHash() => r'ec1ab3a8d432033aa1f02d28e841e78eba06d63e';
|
||||
|
||||
/// Order Status Hive Box Provider
|
||||
///
|
||||
/// Provides direct access to the Hive box for order statuses.
|
||||
/// Use this to read data directly from Hive in the UI.
|
||||
|
||||
@ProviderFor(orderStatusHiveBox)
|
||||
const orderStatusHiveBoxProvider = OrderStatusHiveBoxProvider._();
|
||||
|
||||
/// Order Status Hive Box Provider
|
||||
///
|
||||
/// Provides direct access to the Hive box for order statuses.
|
||||
/// Use this to read data directly from Hive in the UI.
|
||||
|
||||
final class OrderStatusHiveBoxProvider
|
||||
extends $FunctionalProvider<Box<dynamic>, Box<dynamic>, Box<dynamic>>
|
||||
with $Provider<Box<dynamic>> {
|
||||
/// Order Status Hive Box Provider
|
||||
///
|
||||
/// Provides direct access to the Hive box for order statuses.
|
||||
/// Use this to read data directly from Hive in the UI.
|
||||
const OrderStatusHiveBoxProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'orderStatusHiveBoxProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$orderStatusHiveBoxHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<Box<dynamic>> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Box<dynamic> create(Ref ref) {
|
||||
return orderStatusHiveBox(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(Box<dynamic> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<Box<dynamic>>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$orderStatusHiveBoxHash() =>
|
||||
r'49b681c9cabb60f58e049dd4d89872c827d7db9a';
|
||||
|
||||
/// Order Status List Provider
|
||||
///
|
||||
/// Provides cached order status list with automatic refresh.
|
||||
|
||||
Reference in New Issue
Block a user