Skip to content

Commit e7bb0bd

Browse files
committed
Add custom_lint
1 parent 5ad39b6 commit e7bb0bd

File tree

15 files changed

+86
-47
lines changed

15 files changed

+86
-47
lines changed

colorist/codelab_rebuild.yaml

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ steps:
88
flutter: create -e colorist --platforms=android,ios,macos,web,windows
99
- name: Add dependencies
1010
path: colorist
11-
flutter: pub add colorist_ui flutter_riverpod logging riverpod_annotation dev:build_runner dev:riverpod_generator dev:riverpod_lint dev:json_serializable
11+
flutter: pub add colorist_ui flutter_riverpod logging riverpod_annotation dev:build_runner dev:riverpod_generator dev:riverpod_lint dev:json_serializable dev:custom_lint
1212
- name: Strip DEVELOPMENT_TEAM
1313
strip-lines-containing: DEVELOPMENT_TEAM =
1414
path: colorist/ios/Runner.xcodeproj/project.pbxproj
1515
- name: Configure analysis_options.yaml
1616
path: colorist/analysis_options.yaml
1717
replace-contents: |
1818
include: ../../analysis_options.yaml
19+
20+
analyzer:
21+
plugins:
22+
- custom_lint
1923
- name: dart fix
2024
path: colorist
2125
dart: fix --apply
@@ -248,7 +252,7 @@ steps:
248252
@@ -2,15 +2,17 @@
249253
// Use of this source code is governed by a BSD-style license that can be
250254
// found in the LICENSE file.
251-
255+
252256
-import 'package:colorist_ui/models/message.dart';
253257
-import 'package:colorist_ui/providers/chat_state_notifier.dart';
254258
-import 'package:colorist_ui/providers/log_state_notifier.dart';
@@ -259,15 +263,15 @@ steps:
259263
import 'package:flutter/material.dart';
260264
import 'package:flutter_riverpod/flutter_riverpod.dart';
261265
import 'package:logging/logging.dart';
262-
266+
263267
+import 'providers/gemini.dart';
264268
+import 'services/gemini_chat_service.dart';
265269
+
266270
void main() async {
267271
Logger.root.level = Level.ALL;
268272
Logger.root.onRecord.listen((record) {
269273
@@ -30,26 +32,22 @@ class MainApp extends ConsumerWidget {
270-
274+
271275
@override
272276
Widget build(BuildContext context, WidgetRef ref) {
273277
+ final model = ref.watch(geminiModelProvider);
@@ -341,7 +345,7 @@ steps:
341345
compileSdk = flutter.compileSdkVersion
342346
- ndkVersion = flutter.ndkVersion
343347
+ ndkVersion = "27.0.12077973"
344-
348+
345349
compileOptions {
346350
sourceCompatibility = JavaVersion.VERSION_11
347351
@@ -24,7 +24,7 @@ android {
@@ -463,10 +467,10 @@ steps:
463467
- name: Patch pubspec.yaml
464468
path: colorist/pubspec.yaml
465469
patch-u: |
466-
--- a/colorist/step_03/pubspec.yaml
467-
+++ b/colorist/step_03/pubspec.yaml
468-
@@ -27,3 +27,7 @@ dev_dependencies:
469-
470+
--- b/colorist/step_03/pubspec.yaml
471+
+++ a/colorist/step_03/pubspec.yaml
472+
@@ -28,3 +28,7 @@ dev_dependencies:
473+
470474
flutter:
471475
uses-material-design: true
472476
+
@@ -496,18 +500,18 @@ steps:
496500
+++ b/colorist/step_03/lib/providers/gemini.dart
497501
@@ -10,6 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
498502
import 'package:riverpod_annotation/riverpod_annotation.dart';
499-
503+
500504
import '../firebase_options.dart';
501505
+import 'system_prompt.dart';
502-
506+
503507
part 'gemini.g.dart';
504-
508+
505509
@@ -20,9 +21,11 @@ Future<FirebaseApp> firebaseApp(Ref ref) =>
506510
@riverpod
507511
Future<GenerativeModel> geminiModel(Ref ref) async {
508512
await ref.watch(firebaseAppProvider.future);
509513
+ final systemPrompt = await ref.watch(systemPromptProvider.future);
510-
514+
511515
final model = FirebaseVertexAI.instance.generativeModel(
512516
model: 'gemini-2.0-flash',
513517
+ systemInstruction: Content.system(systemPrompt),
@@ -570,18 +574,18 @@ steps:
570574
+++ b/colorist/step_04/lib/providers/gemini.dart
571575
@@ -10,6 +10,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
572576
import 'package:riverpod_annotation/riverpod_annotation.dart';
573-
577+
574578
import '../firebase_options.dart';
575579
+import '../services/gemini_tools.dart';
576580
import 'system_prompt.dart';
577-
581+
578582
part 'gemini.g.dart';
579583
@@ -22,10 +23,12 @@ Future<FirebaseApp> firebaseApp(Ref ref) =>
580584
Future<GenerativeModel> geminiModel(Ref ref) async {
581585
await ref.watch(firebaseAppProvider.future);
582586
final systemPrompt = await ref.watch(systemPromptProvider.future);
583587
+ final geminiTools = ref.watch(geminiToolsProvider);
584-
588+
585589
final model = FirebaseVertexAI.instance.generativeModel(
586590
model: 'gemini-2.0-flash',
587591
systemInstruction: Content.system(systemPrompt),
@@ -596,46 +600,46 @@ steps:
596600
+++ b/colorist/step_04/assets/prompts/system_prompt.md
597601
@@ -1,14 +1,12 @@
598602
# Colorist System Prompt
599-
603+
600604
-You are a color expert assistant integrated into a desktop app called Colorist. Your job is to interpret natural language color descriptions and provide the appropriate RGB values that best represent that description.
601605
+You are a color expert assistant integrated into a desktop app called Colorist. Your job is to interpret natural language color descriptions and set the appropriate color values using a specialized tool.
602-
606+
603607
## Your Capabilities
604-
608+
605609
-You are knowledgeable about colors, color theory, and how to translate natural language descriptions into specific RGB values. When users describe a color, you should:
606610
+You are knowledgeable about colors, color theory, and how to translate natural language descriptions into specific RGB values. You have access to the following tool:
607-
611+
608612
-1. Analyze their description to understand the color they're trying to convey
609613
-2. Determine the appropriate RGB values (values should be between 0.0 and 1.0)
610614
-3. Respond with a conversational explanation and explicitly state the RGB values
611615
+**set_color** - Sets the RGB values for the color display based on a description
612-
616+
613617
## How to Respond to User Inputs
614-
618+
615619
@@ -16,16 +14,16 @@ When users describe a color:
616-
620+
617621
1. First, acknowledge their color description with a brief, friendly response
618622
2. Interpret what RGB values would best represent that color description
619623
-3. Always include the RGB values clearly in your response, formatted as: `RGB: (red=X.X, green=X.X, blue=X.X)`
620624
-4. Provide a brief explanation of your interpretation
621625
+3. Use the `set_color` tool to set those values (all values should be between 0.0 and 1.0)
622626
+4. After setting the color, provide a brief explanation of your interpretation
623-
627+
624628
Example:
625629
User: "I want a sunset orange"
626630
You: "Sunset orange is a warm, vibrant color that captures the golden-red hues of the setting sun. It combines a strong red component with moderate orange tones.
627-
631+
628632
-RGB: (red=1.0, green=0.5, blue=0.25)
629633
+[Then you would call the set_color tool with approximately: red=1.0, green=0.5, blue=0.25]
630-
634+
631635
-I've selected values with high red, moderate green, and low blue to capture that beautiful sunset glow. This creates a warm orange with a slightly reddish tint, reminiscent of the sun low on the horizon."
632636
+After the tool call: "I've set a warm orange with strong red, moderate green, and minimal blue components that is reminiscent of the sun low on the horizon."
633-
637+
634638
## When Descriptions are Unclear
635-
639+
636640
@@ -34,7 +32,6 @@ If a color description is ambiguous or unclear, please ask the user clarifying q
637641
## Important Guidelines
638-
642+
639643
- Always keep RGB values between 0.0 and 1.0
640644
-- Always format RGB values as: `RGB: (red=X.X, green=X.X, blue=X.X)` for easy parsing
641645
- Provide thoughtful, knowledgeable responses about colors
@@ -662,12 +666,12 @@ steps:
662666
+++ a/colorist/step_05/lib/services/gemini_chat_service.dart
663667
@@ -11,6 +11,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
664668
import 'package:riverpod_annotation/riverpod_annotation.dart';
665-
669+
666670
import '../providers/gemini.dart';
667671
+import 'gemini_tools.dart';
668-
672+
669673
part 'gemini_chat_service.g.dart';
670-
674+
671675
@@ -31,6 +32,13 @@ class GeminiChatService {
672676
final responseText = response.text?.trim() ?? 'No text response received';
673677
logStateNotifier.logLlmText(responseText);
@@ -690,7 +694,7 @@ steps:
690694
@@ -2,6 +2,8 @@
691695
// Use of this source code is governed by a BSD-style license that can be
692696
// found in the LICENSE file.
693-
697+
694698
+import 'package:colorist_ui/providers/color_state_notifier.dart';
695699
+import 'package:colorist_ui/providers/log_state_notifier.dart';
696700
import 'package:firebase_vertexai/firebase_vertexai.dart';
@@ -740,7 +744,7 @@ steps:
740744
+ };
741745
+ }
742746
}
743-
747+
744748
@riverpod
745749
- name: Run build_runner
746750
path: colorist
@@ -762,31 +766,31 @@ steps:
762766
--- b/colorist/step_06/lib/services/gemini_chat_service.dart
763767
+++ a/colorist/step_06/lib/services/gemini_chat_service.dart
764768
@@ -4,6 +4,7 @@
765-
769+
766770
import 'dart:async';
767-
771+
768772
+import 'package:colorist_ui/models/conversation_state.dart';
769773
import 'package:colorist_ui/providers/chat_state_notifier.dart';
770774
import 'package:colorist_ui/providers/log_state_notifier.dart';
771775
import 'package:firebase_vertexai/firebase_vertexai.dart';
772776
@@ -15,29 +16,41 @@ import 'gemini_tools.dart';
773-
777+
774778
part 'gemini_chat_service.g.dart';
775-
779+
776780
+final conversationStateProvider = StateProvider(
777781
+ (ref) => ConversationState.idle,
778782
+);
779783
+
780784
class GeminiChatService {
781785
GeminiChatService(this.ref);
782786
final Ref ref;
783-
787+
784788
Future<void> sendMessage(String message) async {
785789
final chatSession = await ref.read(chatSessionProvider.future);
786790
+ final conversationState = ref.read(conversationStateProvider);
787791
final chatStateNotifier = ref.read(chatStateNotifierProvider.notifier);
788792
final logStateNotifier = ref.read(logStateNotifierProvider.notifier);
789-
793+
790794
+ if (conversationState == ConversationState.busy) {
791795
+ logStateNotifier.logWarning(
792796
+ "Can't send a message while a conversation is in progress",
@@ -856,7 +860,7 @@ steps:
856860
Widget build(BuildContext context, WidgetRef ref) {
857861
final model = ref.watch(geminiModelProvider);
858862
+ final conversationState = ref.watch(conversationStateProvider);
859-
863+
860864
return MaterialApp(
861865
theme: ThemeData(
862866
@@ -41,6 +42,7 @@ class MainApp extends ConsumerWidget {
@@ -888,18 +892,18 @@ steps:
888892
+++ a/colorist/step_07/lib/services/gemini_chat_service.dart
889893
@@ -3,7 +3,9 @@
890894
// found in the LICENSE file.
891-
895+
892896
import 'dart:async';
893897
+import 'dart:convert';
894-
898+
895899
+import 'package:colorist_ui/models/color_data.dart';
896900
import 'package:colorist_ui/models/conversation_state.dart';
897901
import 'package:colorist_ui/providers/chat_state_notifier.dart';
898902
import 'package:colorist_ui/providers/log_state_notifier.dart';
899903
@@ -24,6 +26,10 @@ class GeminiChatService {
900904
GeminiChatService(this.ref);
901905
final Ref ref;
902-
906+
903907
+ Future<void> notifyColorSelection(ColorData color) => sendMessage(
904908
+ 'User selected color from history: ${json.encode(color.toLLMContextMap())}',
905909
+ );
@@ -928,9 +932,9 @@ steps:
928932
--- b/colorist/step_07/assets/prompts/system_prompt.md
929933
+++ a/colorist/step_07/assets/prompts/system_prompt.md
930934
@@ -29,6 +29,14 @@ After the tool call: "I've set a warm orange with strong red, moderate green, an
931-
935+
932936
If a color description is ambiguous or unclear, please ask the user clarifying questions, one at a time.
933-
937+
934938
+## When Users Select Historical Colors
935939
+
936940
+Sometimes, the user will manually select a color from the history panel. When this happens, you'll receive a notification about this selection that includes details about the color. Acknowledge this selection with a brief response that recognizes what they've done and comments on the selected color.
@@ -940,7 +944,7 @@ steps:
940944
+You: "I see you've selected an ocean blue from your history. This tranquil blue with a moderate intensity has a calming, professional quality to it. Would you like to explore similar shades or create a contrasting color?"
941945
+
942946
## Important Guidelines
943-
947+
944948
- Always keep RGB values between 0.0 and 1.0
945949
- name: Run build_runner
946950
path: colorist
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
plugins:
5+
- custom_lint

colorist/step_01/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dev_dependencies:
2222
riverpod_generator: ^2.6.5
2323
riverpod_lint: ^2.6.5
2424
json_serializable: ^6.9.4
25+
custom_lint: ^0.7.5
2526

2627
flutter:
2728
uses-material-design: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
plugins:
5+
- custom_lint

colorist/step_02/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dev_dependencies:
2424
riverpod_generator: ^2.6.5
2525
riverpod_lint: ^2.6.5
2626
json_serializable: ^6.9.4
27+
custom_lint: ^0.7.5
2728

2829
flutter:
2930
uses-material-design: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
plugins:
5+
- custom_lint

colorist/step_03/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dev_dependencies:
2424
riverpod_generator: ^2.6.5
2525
riverpod_lint: ^2.6.5
2626
json_serializable: ^6.9.4
27+
custom_lint: ^0.7.5
2728

2829
flutter:
2930
uses-material-design: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
plugins:
5+
- custom_lint

colorist/step_04/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dev_dependencies:
2424
riverpod_generator: ^2.6.5
2525
riverpod_lint: ^2.6.5
2626
json_serializable: ^6.9.4
27+
custom_lint: ^0.7.5
2728

2829
flutter:
2930
uses-material-design: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
include: ../../analysis_options.yaml
2+
3+
analyzer:
4+
plugins:
5+
- custom_lint

0 commit comments

Comments
 (0)