Add flutter_localizations + intl, 12 ARB files (en/ru/es/de/fr/it/pt/zh/ja/ko/ar/hi), replace all hardcoded Russian UI strings with AppLocalizations, detect system locale on first launch, localise bottom nav bar labels, document rule in CLAUDE.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
79 lines
2.6 KiB
Dart
79 lines
2.6 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../features/scan/recognition_service.dart';
|
|
import '../../shared/models/home_summary.dart';
|
|
import 'home_service.dart';
|
|
|
|
// ── Selected date (persists while app is open) ────────────────
|
|
|
|
/// The date currently viewed on the home screen.
|
|
/// Defaults to today; can be changed via the date selector.
|
|
final selectedDateProvider = StateProvider<DateTime>((ref) => DateTime.now());
|
|
|
|
/// Formats a [DateTime] to the 'YYYY-MM-DD' string expected by the diary API.
|
|
String formatDateForDiary(DateTime date) =>
|
|
'${date.year}-${date.month.toString().padLeft(2, '0')}-'
|
|
'${date.day.toString().padLeft(2, '0')}';
|
|
|
|
// ── Home summary ──────────────────────────────────────────────
|
|
|
|
class HomeNotifier extends StateNotifier<AsyncValue<HomeSummary>> {
|
|
final HomeService _service;
|
|
|
|
HomeNotifier(this._service) : super(const AsyncValue.loading()) {
|
|
load();
|
|
}
|
|
|
|
Future<void> load() async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() => _service.getSummary());
|
|
}
|
|
}
|
|
|
|
final homeProvider =
|
|
StateNotifierProvider<HomeNotifier, AsyncValue<HomeSummary>>(
|
|
(ref) => HomeNotifier(ref.read(homeServiceProvider)),
|
|
);
|
|
|
|
// ── Today's unlinked recognition jobs ─────────────────────────
|
|
|
|
class TodayJobsNotifier
|
|
extends StateNotifier<AsyncValue<List<DishJobSummary>>> {
|
|
final RecognitionService _service;
|
|
|
|
TodayJobsNotifier(this._service) : super(const AsyncValue.loading()) {
|
|
load();
|
|
}
|
|
|
|
Future<void> load() async {
|
|
state = const AsyncValue.loading();
|
|
state =
|
|
await AsyncValue.guard(() => _service.listTodayUnlinkedJobs());
|
|
}
|
|
}
|
|
|
|
final todayJobsProvider =
|
|
StateNotifierProvider<TodayJobsNotifier, AsyncValue<List<DishJobSummary>>>(
|
|
(ref) => TodayJobsNotifier(ref.read(recognitionServiceProvider)),
|
|
);
|
|
|
|
// ── All recognition jobs (history screen) ─────────────────────
|
|
|
|
class AllJobsNotifier extends StateNotifier<AsyncValue<List<DishJobSummary>>> {
|
|
final RecognitionService _service;
|
|
|
|
AllJobsNotifier(this._service) : super(const AsyncValue.loading()) {
|
|
load();
|
|
}
|
|
|
|
Future<void> load() async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() => _service.listAllJobs());
|
|
}
|
|
}
|
|
|
|
final allJobsProvider =
|
|
StateNotifierProvider<AllJobsNotifier, AsyncValue<List<DishJobSummary>>>(
|
|
(ref) => AllJobsNotifier(ref.read(recognitionServiceProvider)),
|
|
);
|