| 1 | import 'package:flutter_riverpod/flutter_riverpod.dart'; |
| 2 | import 'model_selection_providers.dart'; |
| 3 | |
| 4 | class ModelLoadingState { |
| 5 | final bool isLoading; |
| 6 | final String? modelId; |
| 7 | final double? progress; |
| 8 | |
| 9 | const ModelLoadingState({ |
| 10 | this.isLoading = false, |
| 11 | this.modelId, |
| 12 | this.progress, |
| 13 | }); |
| 14 | |
| 15 | ModelLoadingState copyWith({ |
| 16 | bool? isLoading, |
| 17 | String? modelId, |
| 18 | double? progress, |
| 19 | }) { |
| 20 | return ModelLoadingState( |
| 21 | isLoading: isLoading ?? this.isLoading, |
| 22 | modelId: modelId ?? this.modelId, |
| 23 | progress: progress ?? this.progress, |
| 24 | ); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | final modelLoadingProvider = |
| 29 | NotifierProvider<ModelLoadingNotifier, ModelLoadingState>(() { |
| 30 | return ModelLoadingNotifier(); |
| 31 | }); |
| 32 | |
| 33 | class ModelLoadingNotifier extends Notifier<ModelLoadingState> { |
| 34 | @override |
| 35 | ModelLoadingState build() => const ModelLoadingState(); |
| 36 | |
| 37 | void setLoading(String modelId, {double? progress}) { |
| 38 | state = ModelLoadingState( |
| 39 | isLoading: true, |
| 40 | modelId: modelId, |
| 41 | progress: progress, |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | void updateProgress(double progress) { |
| 46 | state = state.copyWith(progress: progress); |
| 47 | } |
| 48 | |
| 49 | void setLoaded() { |
| 50 | state = const ModelLoadingState(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | final modelThinkingProvider = Provider<bool>((ref) { |
| 55 | return ref.watch(isStreamingProvider); |
| 56 | }); |