Skip to content

Commit 1afa017

Browse files
Merge branch 'main' into fix/travel-app-widget-catalog
2 parents 86427a1 + c42003a commit 1afa017

File tree

368 files changed

+1194
-30374
lines changed

Some content is hidden

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

368 files changed

+1194
-30374
lines changed

.gemini/commands/fix_code.toml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This command will be invoked via: /fix_code
2+
3+
# A brief description of what the command does.
4+
description = "Fixes code issues reported by a script and verifies the fixes."
5+
6+
# The prompt that will be sent to the model when the command is invoked.
7+
# This prompt contains the instructions for the model to follow.
8+
prompt = """
9+
You are an expert in fixing code issues. Your task is to run a script that reports
10+
issues, fix them, and then verify your fixes.
11+
12+
## 0. Setup the repo
13+
Run `flutter pub get` and init the git submodules, to ensure that
14+
all dependencies are downloaded and initialized.
15+
16+
## 1. Run the issue reporting script:
17+
Look at the list of issues reported in "List of issues" below.
18+
19+
## 2. Analyze and Fix Issues:
20+
* Parse the output from the script.
21+
* For each issue reported, analyze the problem and make the necessary
22+
code changes to fix it.
23+
24+
## 3. Verify the Fixes:
25+
* After applying the fixes, you need to verify that the issues are resolved.
26+
* You can verify this by running 'flutter test' etc in the relevant
27+
subdirectory. For example: 'cd examples/travel_app && flutter test',
28+
or by using Dart MCP server to run the tests.
29+
* Execute the verification commands as specified in the issue report.
30+
* If any verification command fails, you should analyze the failure,
31+
attempt to fix it, and re-run the verification command until it passes.
32+
33+
## 4. Final Verification:
34+
* Once all individual issues are fixed and verified, run the original
35+
script `./tool/run_all_tests_and_fixes.sh` again to ensure that no
36+
new issues have been introduced.
37+
* If the script reports no issues, your task is complete.
38+
39+
# List of issues
40+
`!{./tool/run_all_tests_and_fixes.sh}`
41+
"""

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ final catalog = CoreCatalogItems.asCatalog().copyWith([
5050
5151
/// Initializing the library.
5252
final genUiManager = GenUiManager(catalog: catalog);
53-
final aiClient = FirebaseAiClient(
53+
final contentGenerator = FirebaseAiContentGenerator(
54+
catalog: catalog,
5455
systemInstruction: '''
5556
You are a bicycle maintenance assistant who is an expert in diagnosing issues and
5657
giving step-by-step instructions.
5758
''',
58-
tools: genUiManager.getTools(),
5959
);
6060
late final _genUiConversation = GenUiConversation(
6161
genUiManager: genUiManager,
62-
aiClient: aiClient,
62+
contentGenerator: contentGenerator,
6363
onSurfaceAdded: _onSurfaceAdded,
6464
onSurfaceDeleted: (_) {},
6565
onTextResponse: (_) {},
@@ -81,7 +81,7 @@ void _onSurfaceAdded(SurfaceAdded surface) {
8181
Widget build(BuildContext context) {
8282
if (type == MessageType.genUi) {
8383
return GenUiSurface(
84-
host: _genUiConversation.host,
84+
host: _genUiConversation.genUiManager.host,
8585
surfaceId: _surfaceId,
8686
onEvent: _handleEvent,
8787
);

examples/travel_app/integration_test/app_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ void main() {
1414

1515
group('Initial UI test', () {
1616
testWidgets('send a request and verify the UI', (tester) async {
17-
final mockAiClient = FakeContentGenerator();
18-
mockAiClient.addA2uiMessage(A2uiMessage.fromJson(_baliResponse));
17+
final mockContentGenerator = FakeContentGenerator();
18+
mockContentGenerator.addA2uiMessage(A2uiMessage.fromJson(_baliResponse));
1919

20-
runApp(app.TravelApp(contentGenerator: mockAiClient));
20+
runApp(app.TravelApp(contentGenerator: mockContentGenerator));
2121
await tester.pumpAndSettle();
2222
await tester.enterText(find.byType(EditableText), 'Plan a trip to Bali');
2323
await tester.tap(find.byIcon(Icons.send));

examples/travel_app/lib/src/catalog/checkbox_filter_chips_input.dart

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -101,62 +101,55 @@ final checkboxFilterChipsInput = CatalogItem(
101101
]
102102
''',
103103
],
104-
widgetBuilder:
105-
({
106-
required data,
107-
required id,
108-
required buildChild,
109-
required dispatchEvent,
110-
required context,
111-
required dataContext,
112-
required getComponent,
113-
}) {
114-
final checkboxFilterChipsData = _CheckboxFilterChipsInputData.fromMap(
115-
data as Map<String, Object?>,
104+
widgetBuilder: (context) {
105+
final checkboxFilterChipsData = _CheckboxFilterChipsInputData.fromMap(
106+
context.data as Map<String, Object?>,
107+
);
108+
IconData? icon;
109+
if (checkboxFilterChipsData.iconName != null) {
110+
try {
111+
icon = iconFor(
112+
TravelIcon.values.byName(checkboxFilterChipsData.iconName!),
116113
);
117-
IconData? icon;
118-
if (checkboxFilterChipsData.iconName != null) {
119-
try {
120-
icon = iconFor(
121-
TravelIcon.values.byName(checkboxFilterChipsData.iconName!),
122-
);
123-
} catch (e) {
124-
developer.log(
125-
'Invalid icon name: ${checkboxFilterChipsData.iconName}',
126-
name: 'CheckboxFilterChipsInput',
127-
error: e,
128-
);
129-
icon = null;
130-
}
131-
}
114+
} catch (e) {
115+
developer.log(
116+
'Invalid icon name: ${checkboxFilterChipsData.iconName}',
117+
name: 'CheckboxFilterChipsInput',
118+
error: e,
119+
);
120+
icon = null;
121+
}
122+
}
132123

133-
final selectedOptionsRef = checkboxFilterChipsData.selectedOptions;
134-
final notifier = dataContext.subscribeToObjectArray(selectedOptionsRef);
124+
final selectedOptionsRef = checkboxFilterChipsData.selectedOptions;
125+
final notifier = context.dataContext.subscribeToObjectArray(
126+
selectedOptionsRef,
127+
);
135128

136-
return ValueListenableBuilder<List<Object?>?>(
137-
valueListenable: notifier,
138-
builder: (context, currentSelectedValues, child) {
139-
final selectedOptionsSet = (currentSelectedValues ?? [])
140-
.cast<String>()
141-
.toSet();
142-
return _CheckboxFilterChip(
143-
chipLabel: checkboxFilterChipsData.chipLabel,
144-
options: checkboxFilterChipsData.options,
145-
icon: icon,
146-
selectedOptions: selectedOptionsSet,
147-
onChanged: (newSelectedOptions) {
148-
final path = selectedOptionsRef['path'] as String?;
149-
if (path != null) {
150-
dataContext.update(
151-
DataPath(path),
152-
newSelectedOptions.toList(),
153-
);
154-
}
155-
},
156-
);
129+
return ValueListenableBuilder<List<Object?>?>(
130+
valueListenable: notifier,
131+
builder: (buildContext, currentSelectedValues, child) {
132+
final selectedOptionsSet = (currentSelectedValues ?? [])
133+
.cast<String>()
134+
.toSet();
135+
return _CheckboxFilterChip(
136+
chipLabel: checkboxFilterChipsData.chipLabel,
137+
options: checkboxFilterChipsData.options,
138+
icon: icon,
139+
selectedOptions: selectedOptionsSet,
140+
onChanged: (newSelectedOptions) {
141+
final path = selectedOptionsRef['path'] as String?;
142+
if (path != null) {
143+
context.dataContext.update(
144+
DataPath(path),
145+
newSelectedOptions.toList(),
146+
);
147+
}
157148
},
158149
);
159150
},
151+
);
152+
},
160153
);
161154

162155
class _CheckboxFilterChip extends StatelessWidget {

examples/travel_app/lib/src/catalog/date_input_chip.dart

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,33 +128,26 @@ final dateInputChip = CatalogItem(
128128
]
129129
''',
130130
],
131-
widgetBuilder:
132-
({
133-
required data,
134-
required id,
135-
required buildChild,
136-
required dispatchEvent,
137-
required context,
138-
required dataContext,
139-
required getComponent,
140-
}) {
141-
final datePickerData = _DatePickerData.fromMap(data as JsonMap);
142-
final notifier = dataContext.subscribeToString(datePickerData.value);
143-
final path = datePickerData.value?['path'] as String?;
131+
widgetBuilder: (context) {
132+
final datePickerData = _DatePickerData.fromMap(context.data as JsonMap);
133+
final notifier = context.dataContext.subscribeToString(
134+
datePickerData.value,
135+
);
136+
final path = datePickerData.value?['path'] as String?;
144137

145-
return ValueListenableBuilder<String?>(
146-
valueListenable: notifier,
147-
builder: (context, currentValue, child) {
148-
return _DateInputChip(
149-
initialValue: currentValue,
150-
label: datePickerData.label,
151-
onChanged: (newValue) {
152-
if (path != null) {
153-
dataContext.update(DataPath(path), newValue);
154-
}
155-
},
156-
);
138+
return ValueListenableBuilder<String?>(
139+
valueListenable: notifier,
140+
builder: (buildContext, currentValue, child) {
141+
return _DateInputChip(
142+
initialValue: currentValue,
143+
label: datePickerData.label,
144+
onChanged: (newValue) {
145+
if (path != null) {
146+
context.dataContext.update(DataPath(path), newValue);
147+
}
157148
},
158149
);
159150
},
151+
);
152+
},
160153
);

examples/travel_app/lib/src/catalog/information_card.dart

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,36 +82,27 @@ final informationCard = CatalogItem(
8282
]
8383
''',
8484
],
85-
widgetBuilder:
86-
({
87-
required data,
88-
required id,
89-
required buildChild,
90-
required dispatchEvent,
91-
required context,
92-
required dataContext,
93-
required getComponent,
94-
}) {
95-
final cardData = _InformationCardData.fromMap(
96-
data as Map<String, Object?>,
97-
);
98-
final imageChild = cardData.imageChildId != null
99-
? buildChild(cardData.imageChildId!)
100-
: null;
85+
widgetBuilder: (context) {
86+
final cardData = _InformationCardData.fromMap(
87+
context.data as Map<String, Object?>,
88+
);
89+
final imageChild = cardData.imageChildId != null
90+
? context.buildChild(cardData.imageChildId!)
91+
: null;
10192

102-
final titleNotifier = dataContext.subscribeToString(cardData.title);
103-
final subtitleNotifier = dataContext.subscribeToString(
104-
cardData.subtitle,
105-
);
106-
final bodyNotifier = dataContext.subscribeToString(cardData.body);
93+
final titleNotifier = context.dataContext.subscribeToString(cardData.title);
94+
final subtitleNotifier = context.dataContext.subscribeToString(
95+
cardData.subtitle,
96+
);
97+
final bodyNotifier = context.dataContext.subscribeToString(cardData.body);
10798

108-
return _InformationCard(
109-
imageChild: imageChild,
110-
titleNotifier: titleNotifier,
111-
subtitleNotifier: subtitleNotifier,
112-
bodyNotifier: bodyNotifier,
113-
);
114-
},
99+
return _InformationCard(
100+
imageChild: imageChild,
101+
titleNotifier: titleNotifier,
102+
subtitleNotifier: subtitleNotifier,
103+
bodyNotifier: bodyNotifier,
104+
);
105+
},
115106
);
116107

117108
class _InformationCard extends StatelessWidget {

0 commit comments

Comments
 (0)