36c7ad8b43
Deploy Client / build-client-web (push) Successful in 38s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / build-macos (push) Successful in 1m55s
Deploy Client / build-android (push) Successful in 1m0s
Deploy Client / build-ios (push) Successful in 2m47s
Deploy Client / release-deploy-client (push) Successful in 1m21s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
70 lines
1.7 KiB
Dart
70 lines
1.7 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/auth/auth_state.dart';
|
|
import '../core/config/app_constants.dart';
|
|
import '../core/models/page_result.dart';
|
|
import '../models/finance.dart';
|
|
import '../repositories/finance_repository.dart';
|
|
|
|
final financeRepositoryProvider = Provider<FinanceRepository>((ref) {
|
|
return FinanceRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final financeListProvider =
|
|
AsyncNotifierProvider<FinanceListNotifier, PageResult<FinanceRecord>>(
|
|
FinanceListNotifier.new,
|
|
);
|
|
|
|
class FinanceListNotifier extends AsyncNotifier<PageResult<FinanceRecord>> {
|
|
int _page = 1;
|
|
int _pageSize = AppConstants.defaultPageSize;
|
|
String _type = '';
|
|
String _month = '';
|
|
|
|
@override
|
|
Future<PageResult<FinanceRecord>> build() {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
return _fetch();
|
|
}
|
|
|
|
Future<PageResult<FinanceRecord>> _fetch() {
|
|
return ref.read(financeRepositoryProvider).listRecords(
|
|
type: _type.isEmpty ? null : _type,
|
|
month: _month.isEmpty ? null : _month,
|
|
page: _page,
|
|
pageSize: _pageSize,
|
|
);
|
|
}
|
|
|
|
void setType(String type) {
|
|
_type = type;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setMonth(String month) {
|
|
_month = month;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setPage(int page) {
|
|
_page = page;
|
|
reload();
|
|
}
|
|
|
|
void setPageSize(int pageSize) {
|
|
_pageSize = pageSize;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void reload() {
|
|
state = const AsyncValue.loading();
|
|
_fetch().then(
|
|
(result) => state = AsyncValue.data(result),
|
|
onError: (e, st) => state = AsyncValue.error(e, st),
|
|
);
|
|
}
|
|
}
|