2026-04-26 14:42:39 +10:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
import '../llm/model_download_service.dart';
|
|
|
|
|
import 'settings_provider.dart';
|
|
|
|
|
|
|
|
|
|
// ── Is the model file present on disk? ───────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
final modelPresentProvider = FutureProvider<bool>((ref) {
|
|
|
|
|
return ModelDownloadService().isModelPresent();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-26 15:14:17 +10:00
|
|
|
// ── Has the user chosen to skip the model requirement? ───────────────────────
|
2026-04-26 14:42:39 +10:00
|
|
|
|
2026-04-26 15:14:17 +10:00
|
|
|
class _SkipNotifier extends Notifier<bool> {
|
2026-04-26 14:42:39 +10:00
|
|
|
@override
|
2026-04-26 15:14:17 +10:00
|
|
|
bool build() => false;
|
|
|
|
|
void skip() => state = true;
|
2026-04-26 14:42:39 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-26 15:14:17 +10:00
|
|
|
final modelSkippedProvider =
|
|
|
|
|
NotifierProvider<_SkipNotifier, bool>(_SkipNotifier.new);
|
|
|
|
|
|
|
|
|
|
// ── Scan notifier — checks for the model on demand ────────────────��──────────
|
|
|
|
|
|
|
|
|
|
class ModelScanNotifier extends Notifier<AsyncValue<bool>> {
|
|
|
|
|
@override
|
|
|
|
|
AsyncValue<bool> build() => const AsyncData(false);
|
|
|
|
|
|
|
|
|
|
Future<void> scan() async {
|
|
|
|
|
state = const AsyncLoading();
|
|
|
|
|
final next = await AsyncValue.guard(
|
|
|
|
|
() => ModelDownloadService().isModelPresent(),
|
|
|
|
|
);
|
|
|
|
|
if (!ref.mounted) return;
|
|
|
|
|
next.whenData((present) async {
|
|
|
|
|
if (present) {
|
|
|
|
|
await ref.read(settingsNotifierProvider.notifier).markModelDownloaded();
|
|
|
|
|
ref.invalidate(modelPresentProvider);
|
|
|
|
|
} else {
|
|
|
|
|
state = AsyncError(
|
|
|
|
|
Exception('Model file not found at expected path'),
|
|
|
|
|
StackTrace.current,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (next is AsyncError) state = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void skipToApp() => ref.read(modelSkippedProvider.notifier).skip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final modelScanProvider =
|
|
|
|
|
NotifierProvider.autoDispose<ModelScanNotifier, AsyncValue<bool>>(
|
|
|
|
|
ModelScanNotifier.new);
|