fix loyalty
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/// Providers: Points History
|
||||
///
|
||||
/// Riverpod providers for managing points history state.
|
||||
library;
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:worker/features/loyalty/data/datasources/points_history_local_datasource.dart';
|
||||
import 'package:worker/features/loyalty/data/models/loyalty_point_entry_model.dart';
|
||||
|
||||
part 'points_history_provider.g.dart';
|
||||
|
||||
/// Points History Local Data Source Provider
|
||||
@riverpod
|
||||
PointsHistoryLocalDataSource pointsHistoryLocalDataSource(Ref ref) {
|
||||
return PointsHistoryLocalDataSource();
|
||||
}
|
||||
|
||||
/// Points History Provider
|
||||
///
|
||||
/// Provides list of all points history entries from local data source.
|
||||
@riverpod
|
||||
class PointsHistory extends _$PointsHistory {
|
||||
@override
|
||||
Future<List<LoyaltyPointEntryModel>> build() async {
|
||||
final datasource = ref.read(pointsHistoryLocalDataSourceProvider);
|
||||
|
||||
// Seed mock data on first load
|
||||
final entries = await datasource.getAllEntries();
|
||||
if (entries.isEmpty) {
|
||||
await datasource.seedMockEntries();
|
||||
return await datasource.getAllEntries();
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// Refresh points history
|
||||
Future<void> refresh() async {
|
||||
state = const AsyncValue.loading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
return await ref.read(pointsHistoryLocalDataSourceProvider).getAllEntries();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'points_history_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Points History Local Data Source Provider
|
||||
|
||||
@ProviderFor(pointsHistoryLocalDataSource)
|
||||
const pointsHistoryLocalDataSourceProvider =
|
||||
PointsHistoryLocalDataSourceProvider._();
|
||||
|
||||
/// Points History Local Data Source Provider
|
||||
|
||||
final class PointsHistoryLocalDataSourceProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
PointsHistoryLocalDataSource,
|
||||
PointsHistoryLocalDataSource,
|
||||
PointsHistoryLocalDataSource
|
||||
>
|
||||
with $Provider<PointsHistoryLocalDataSource> {
|
||||
/// Points History Local Data Source Provider
|
||||
const PointsHistoryLocalDataSourceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'pointsHistoryLocalDataSourceProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$pointsHistoryLocalDataSourceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<PointsHistoryLocalDataSource> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
PointsHistoryLocalDataSource create(Ref ref) {
|
||||
return pointsHistoryLocalDataSource(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(PointsHistoryLocalDataSource value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<PointsHistoryLocalDataSource>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$pointsHistoryLocalDataSourceHash() =>
|
||||
r'324e4d6d12e0f1ec3f77de8e0fd60f69eaa8c7ce';
|
||||
|
||||
/// Points History Provider
|
||||
///
|
||||
/// Provides list of all points history entries from local data source.
|
||||
|
||||
@ProviderFor(PointsHistory)
|
||||
const pointsHistoryProvider = PointsHistoryProvider._();
|
||||
|
||||
/// Points History Provider
|
||||
///
|
||||
/// Provides list of all points history entries from local data source.
|
||||
final class PointsHistoryProvider
|
||||
extends
|
||||
$AsyncNotifierProvider<PointsHistory, List<LoyaltyPointEntryModel>> {
|
||||
/// Points History Provider
|
||||
///
|
||||
/// Provides list of all points history entries from local data source.
|
||||
const PointsHistoryProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'pointsHistoryProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$pointsHistoryHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
PointsHistory create() => PointsHistory();
|
||||
}
|
||||
|
||||
String _$pointsHistoryHash() => r'e812d6f6707f02c15a1263ae5b5ee912f269358d';
|
||||
|
||||
/// Points History Provider
|
||||
///
|
||||
/// Provides list of all points history entries from local data source.
|
||||
|
||||
abstract class _$PointsHistory
|
||||
extends $AsyncNotifier<List<LoyaltyPointEntryModel>> {
|
||||
FutureOr<List<LoyaltyPointEntryModel>> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref =
|
||||
this.ref
|
||||
as $Ref<
|
||||
AsyncValue<List<LoyaltyPointEntryModel>>,
|
||||
List<LoyaltyPointEntryModel>
|
||||
>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<
|
||||
AsyncValue<List<LoyaltyPointEntryModel>>,
|
||||
List<LoyaltyPointEntryModel>
|
||||
>,
|
||||
AsyncValue<List<LoyaltyPointEntryModel>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user