Skip to content

Commit 68279b5

Browse files
committed
Update colorist for Riverpod 3
1 parent dcda86a commit 68279b5

File tree

63 files changed

+2088
-1355
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2088
-1355
lines changed

colorist/codelab_rebuild.yaml

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ steps:
9696
9797
// A fake LLM that just echoes back what it receives.
9898
void sendMessage(String message, WidgetRef ref) {
99-
final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
100-
final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
99+
final chatStateNotifier = ref.read(chatStateProvider.notifier);
100+
final logStateNotifier = ref.read(logStateProvider.notifier);
101101
102102
chatStateNotifier.addUserMessage(message);
103103
logStateNotifier.logUserText(message);
@@ -167,7 +167,6 @@ steps:
167167
168168
import 'package:firebase_ai/firebase_ai.dart';
169169
import 'package:firebase_core/firebase_core.dart';
170-
import 'package:flutter_riverpod/flutter_riverpod.dart';
171170
import 'package:riverpod_annotation/riverpod_annotation.dart';
172171
173172
import '../firebase_options.dart';
@@ -207,7 +206,6 @@ steps:
207206
208207
import 'package:colorist_ui/colorist_ui.dart';
209208
import 'package:firebase_ai/firebase_ai.dart';
210-
import 'package:flutter_riverpod/flutter_riverpod.dart';
211209
import 'package:riverpod_annotation/riverpod_annotation.dart';
212210
213211
import '../providers/gemini.dart';
@@ -220,8 +218,8 @@ steps:
220218
221219
Future<void> sendMessage(String message) async {
222220
final chatSession = await ref.read(chatSessionProvider.future);
223-
final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
224-
final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
221+
final chatStateNotifier = ref.read(chatStateProvider.notifier);
222+
final logStateNotifier = ref.read(logStateProvider.notifier);
225223
226224
chatStateNotifier.addUserMessage(message);
227225
logStateNotifier.logUserText(message);
@@ -298,8 +296,8 @@ steps:
298296
-
299297
- // A fake LLM that just echoes back what it receives.
300298
- void sendMessage(String message, WidgetRef ref) {
301-
- final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
302-
- final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
299+
- final chatStateNotifier = ref.read(chatStateProvider.notifier);
300+
- final logStateNotifier = ref.read(logStateProvider.notifier);
303301
-
304302
- chatStateNotifier.addUserMessage(message);
305303
- logStateNotifier.logUserText(message);
@@ -446,7 +444,6 @@ steps:
446444
// found in the LICENSE file.
447445
448446
import 'package:flutter/services.dart';
449-
import 'package:flutter_riverpod/flutter_riverpod.dart';
450447
import 'package:riverpod_annotation/riverpod_annotation.dart';
451448
452449
part 'system_prompt.g.dart';
@@ -457,17 +454,17 @@ steps:
457454
- name: Patch lib/providers/gemini.dart
458455
path: colorist/lib/providers/gemini.dart
459456
patch-u: |
460-
--- a/colorist/step_03/lib/providers/gemini.dart
461-
+++ b/colorist/step_03/lib/providers/gemini.dart
462-
@@ -10,6 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
457+
--- b/colorist/step_03/lib/providers/gemini.dart
458+
+++ a/colorist/step_03/lib/providers/gemini.dart
459+
@@ -9,6 +9,7 @@ import 'package:firebase_core/firebase_core.dart';
463460
import 'package:riverpod_annotation/riverpod_annotation.dart';
464461
465462
import '../firebase_options.dart';
466463
+import 'system_prompt.dart';
467464
468465
part 'gemini.g.dart';
469466
470-
@@ -20,9 +21,11 @@ Future<FirebaseApp> firebaseApp(Ref ref) =>
467+
@@ -19,9 +20,11 @@ Future<FirebaseApp> firebaseApp(Ref ref) =>
471468
@riverpod
472469
Future<GenerativeModel> geminiModel(Ref ref) async {
473470
await ref.watch(firebaseAppProvider.future);
@@ -505,7 +502,6 @@ steps:
505502
// found in the LICENSE file.
506503
507504
import 'package:firebase_ai/firebase_ai.dart';
508-
import 'package:flutter_riverpod/flutter_riverpod.dart';
509505
import 'package:riverpod_annotation/riverpod_annotation.dart';
510506
511507
part 'gemini_tools.g.dart';
@@ -535,17 +531,17 @@ steps:
535531
- name: Patch lib/providers/gemini.dart
536532
path: colorist/lib/providers/gemini.dart
537533
patch-u: |
538-
--- a/colorist/step_04/lib/providers/gemini.dart
539-
+++ b/colorist/step_04/lib/providers/gemini.dart
540-
@@ -10,6 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
534+
--- b/colorist/step_04/lib/providers/gemini.dart
535+
+++ a/colorist/step_04/lib/providers/gemini.dart
536+
@@ -9,6 +9,7 @@ import 'package:firebase_core/firebase_core.dart';
541537
import 'package:riverpod_annotation/riverpod_annotation.dart';
542538
543539
import '../firebase_options.dart';
544540
+import '../services/gemini_tools.dart';
545541
import 'system_prompt.dart';
546542
547543
part 'gemini.g.dart';
548-
@@ -22,10 +23,12 @@ Future<FirebaseApp> firebaseApp(Ref ref) =>
544+
@@ -21,10 +22,12 @@ Future<FirebaseApp> firebaseApp(Ref ref) =>
549545
Future<GenerativeModel> geminiModel(Ref ref) async {
550546
await ref.watch(firebaseAppProvider.future);
551547
final systemPrompt = await ref.watch(systemPromptProvider.future);
@@ -634,15 +630,15 @@ steps:
634630
patch-u: |
635631
--- b/colorist/step_05/lib/services/gemini_chat_service.dart
636632
+++ a/colorist/step_05/lib/services/gemini_chat_service.dart
637-
@@ -10,6 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
633+
@@ -9,6 +9,7 @@ import 'package:firebase_ai/firebase_ai.dart';
638634
import 'package:riverpod_annotation/riverpod_annotation.dart';
639635
640636
import '../providers/gemini.dart';
641637
+import 'gemini_tools.dart';
642638
643639
part 'gemini_chat_service.g.dart';
644640
645-
@@ -33,6 +34,27 @@ class GeminiChatService {
641+
@@ -32,6 +33,27 @@ class GeminiChatService {
646642
logStateNotifier.logLlmText(responseText);
647643
chatStateNotifier.appendToMessage(llmMessage.id, responseText);
648644
}
@@ -681,9 +677,9 @@ steps:
681677
682678
+import 'package:colorist_ui/colorist_ui.dart';
683679
import 'package:firebase_ai/firebase_ai.dart';
684-
import 'package:flutter_riverpod/flutter_riverpod.dart';
685680
import 'package:riverpod_annotation/riverpod_annotation.dart';
686-
@@ -26,6 +27,44 @@ class GeminiTools {
681+
682+
@@ -25,6 +26,44 @@ class GeminiTools {
687683
List<Tool> get tools => [
688684
Tool.functionDeclarations([setColorFuncDecl]),
689685
];
@@ -692,7 +688,7 @@ steps:
692688
+ String functionName,
693689
+ Map<String, Object?> arguments,
694690
+ ) {
695-
+ final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
691+
+ final logStateNotifier = ref.read(logStateProvider.notifier);
696692
+ logStateNotifier.logFunctionCall(functionName, arguments);
697693
+ return switch (functionName) {
698694
+ 'set_color' => handleSetColor(arguments),
@@ -701,7 +697,7 @@ steps:
701697
+ }
702698
+
703699
+ Map<String, Object?> handleSetColor(Map<String, Object?> arguments) {
704-
+ final colorStateNotifier = ref.read(colorStateNotifierProvider.notifier);
700+
+ final colorStateNotifier = ref.read(colorStateProvider.notifier);
705701
+ final red = (arguments['red'] as num).toDouble();
706702
+ final green = (arguments['green'] as num).toDouble();
707703
+ final blue = (arguments['blue'] as num).toDouble();
@@ -712,13 +708,13 @@ steps:
712708
+ .toLLMContextMap(),
713709
+ };
714710
+
715-
+ final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
711+
+ final logStateNotifier = ref.read(logStateProvider.notifier);
716712
+ logStateNotifier.logFunctionResults(functionResults);
717713
+ return functionResults;
718714
+ }
719715
+
720716
+ Map<String, Object?> handleUnknownFunction(String functionName) {
721-
+ final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
717+
+ final logStateNotifier = ref.read(logStateProvider.notifier);
722718
+ logStateNotifier.logWarning('Unsupported function call $functionName');
723719
+ return {
724720
+ 'success': false,
@@ -751,7 +747,15 @@ steps:
751747
patch-u: |
752748
--- b/colorist/step_06/lib/services/gemini_chat_service.dart
753749
+++ a/colorist/step_06/lib/services/gemini_chat_service.dart
754-
@@ -14,46 +14,41 @@ import 'gemini_tools.dart';
750+
@@ -6,6 +6,7 @@ import 'dart:async';
751+
752+
import 'package:colorist_ui/colorist_ui.dart';
753+
import 'package:firebase_ai/firebase_ai.dart';
754+
+import 'package:flutter_riverpod/legacy.dart';
755+
import 'package:riverpod_annotation/riverpod_annotation.dart';
756+
757+
import '../providers/gemini.dart';
758+
@@ -13,46 +14,41 @@ import 'gemini_tools.dart';
755759
756760
part 'gemini_chat_service.g.dart';
757761
@@ -766,8 +770,8 @@ steps:
766770
Future<void> sendMessage(String message) async {
767771
final chatSession = await ref.read(chatSessionProvider.future);
768772
+ final conversationState = ref.read(conversationStateProvider);
769-
final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
770-
final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
773+
final chatStateNotifier = ref.read(chatStateProvider.notifier);
774+
final logStateNotifier = ref.read(logStateProvider.notifier);
771775
772776
+ if (conversationState == ConversationState.busy) {
773777
+ logStateNotifier.logWarning(
@@ -820,7 +824,7 @@ steps:
820824
}
821825
} catch (e, st) {
822826
logStateNotifier.logError(e, st: st);
823-
@@ -64,6 +59,45 @@ class GeminiChatService {
827+
@@ -63,6 +59,45 @@ class GeminiChatService {
824828
);
825829
} finally {
826830
chatStateNotifier.finalizeMessage(llmMessage.id);
@@ -833,8 +837,8 @@ steps:
833837
+ String llmMessageId,
834838
+ ) async {
835839
+ final chatSession = await ref.read(chatSessionProvider.future);
836-
+ final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
837-
+ final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
840+
+ final chatStateNotifier = ref.read(chatStateProvider.notifier);
841+
+ final logStateNotifier = ref.read(logStateProvider.notifier);
838842
+ final blockText = block.text;
839843
+
840844
+ if (blockText != null) {
@@ -900,6 +904,7 @@ steps:
900904
- name: Flutter clean
901905
path: step_06
902906
flutter: clean
907+
903908
- name: step_07
904909
steps:
905910
- name: Remove generated code
@@ -994,5 +999,6 @@ steps:
994999
- name: Flutter clean
9951000
path: step_07
9961001
flutter: clean
1002+
9971003
- name: Cleanup
9981004
rmdir: colorist

colorist/step_01/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class MainApp extends ConsumerWidget {
2929

3030
// A fake LLM that just echoes back what it receives.
3131
void sendMessage(String message, WidgetRef ref) {
32-
final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
33-
final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
32+
final chatStateNotifier = ref.read(chatStateProvider.notifier);
33+
final logStateNotifier = ref.read(logStateProvider.notifier);
3434

3535
chatStateNotifier.addUserMessage(message);
3636
logStateNotifier.logUserText(message);

colorist/step_01/pubspec.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ publish_to: 'none'
44
version: 0.1.0
55

66
environment:
7-
sdk: ^3.9.0
7+
sdk: ^3.9.2
88

99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
colorist_ui: ^0.2.5
13-
flutter_riverpod: ^2.6.1
14-
riverpod_annotation: ^2.6.1
12+
colorist_ui: ^0.3.0
13+
flutter_riverpod: ^3.0.0
14+
riverpod_annotation: ^3.0.0
1515

1616
dev_dependencies:
1717
flutter_test:
1818
sdk: flutter
1919
flutter_lints: ^6.0.0
20-
build_runner: ^2.5.4
21-
riverpod_generator: ^2.6.5
22-
riverpod_lint: ^2.6.5
23-
json_serializable: ^6.9.5
24-
custom_lint: ^0.7.6
20+
build_runner: ^2.7.1
21+
riverpod_generator: ^3.0.0
22+
riverpod_lint: ^3.0.0
23+
json_serializable: ^6.11.1
24+
custom_lint: ^0.8.0
2525

2626
flutter:
2727
uses-material-design: true

0 commit comments

Comments
 (0)