Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/minimal_genui/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _MyHomePageState extends State<MyHomePage> {
Future<void> _triggerInference() async {
_chatController.setAiRequestSent();
try {
final response = await _aiClient.generateText(
final response = await _aiClient.generateText(conversation: _conversation);
List.of(_chatController.conversation.value),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a syntax error?

);
_chatController.addMessage(AssistantMessage.text(response));
Expand Down
2 changes: 1 addition & 1 deletion examples/travel_app/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
final mockAiClient = FakeAiClient();
mockAiClient.response = _baliResponse;

runApp(app.TravelApp(aiClient: mockAiClient));
runApp(app.TravelApp(aiClient: fakeAiClient));
await tester.pumpAndSettle();
await tester.enterText(find.byType(EditableText), 'Plan a trip to Bali');
await tester.tap(find.byIcon(Icons.send));
Expand Down
44 changes: 10 additions & 34 deletions examples/travel_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TravelApp extends StatelessWidget {
///
/// If null, a default [GeminiAiClient] will be created by the
/// [TravelPlannerPage].
final AiClient? aiClient;
final GeminiAiClient? aiClient;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -83,15 +83,15 @@ class TravelPlannerPage extends StatefulWidget {
///
/// If null, a default instance of [GeminiAiClient] will be created within
/// the page's state.
final AiClient? aiClient;
final GeminiAiClient? aiClient;

@override
State<TravelPlannerPage> createState() => _TravelPlannerPageState();
}

class _TravelPlannerPageState extends State<TravelPlannerPage> {
late final GenUiManager _genUiManager;
late final AiClient _aiClient;
late final GeminiAiClient _aiClient;
late final UiEventManager _eventManager;
final List<ChatMessage> _conversation = [];

Expand All @@ -109,7 +109,11 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
_genUiManager.updates.listen((update) {
setState(() {
switch (update) {
case SurfaceAdded(:final surfaceId, :final definition):
case SurfaceAdded(
:final surfaceId,
:final definition,
:final controller,
):
_conversation.add(
UiResponseMessage(
definition: {
Expand Down Expand Up @@ -150,7 +154,6 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {

Future<void> _triggerInference() async {
final result = await _aiClient.generateContent(
_conversation,
S.object(
properties: {
'result': S.boolean(
Expand All @@ -166,6 +169,7 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
},
required: ['result'],
),
conversation: _conversation,
);
if (result == null) {
return;
Expand Down Expand Up @@ -231,35 +235,7 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
Text('Dynamic UI Demo'),
],
),
actions: [
ValueListenableBuilder<AiModel>(
valueListenable: _aiClient.model,
builder: (context, currentModel, child) {
return PopupMenuButton<AiModel>(
icon: const Icon(Icons.psychology_outlined),
onSelected: (AiModel value) {
// Handle model selection
_aiClient.switchModel(value);
},
itemBuilder: (BuildContext context) {
return _aiClient.models.map((model) {
return PopupMenuItem<AiModel>(
value: model,
child: Row(
children: [
Text(model.displayName),
if (currentModel == model) const Icon(Icons.check),
],
),
);
}).toList();
},
);
},
),
const Icon(Icons.person_outline),
const SizedBox(width: 8.0),
],
actions: [const Icon(Icons.person_outline), const SizedBox(width: 8.0)],
),
body: SafeArea(
child: Center(
Expand Down
19 changes: 0 additions & 19 deletions examples/travel_app/test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:travel_app/main.dart' as app;

void main() {
testWidgets('Can switch models', (WidgetTester tester) async {
final mockAiClient = FakeAiClient();
await tester.pumpWidget(app.TravelApp(aiClient: mockAiClient));

expect(find.text('mock1'), findsNothing);
expect(find.text('mock2'), findsNothing);

await tester.tap(find.byIcon(Icons.psychology_outlined));
await tester.pumpAndSettle();

expect(find.text('mock1'), findsOneWidget);
expect(find.text('mock2'), findsOneWidget);

await tester.tap(find.text('mock2'));
await tester.pumpAndSettle();

expect(mockAiClient.model.value.displayName, 'mock2');
});

testWidgets('Can send a prompt', (WidgetTester tester) async {
final mockAiClient = FakeAiClient();
// The main app expects a JSON response from generateContent.
Expand Down
2 changes: 0 additions & 2 deletions pkgs/flutter_genui/lib/flutter_genui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'src/ai_client/ai_client.dart';
export 'src/ai_client/gemini_ai_client.dart';
export 'src/catalog/core_widgets/checkbox_group.dart';
export 'src/catalog/core_widgets/column.dart';
Expand All @@ -13,7 +12,6 @@ export 'src/catalog/core_widgets/text.dart';
export 'src/catalog/core_widgets/text_field.dart';
export 'src/core/core_catalog.dart';
export 'src/core/genui_manager.dart';
export 'src/core/surface_manager.dart';
export 'src/facade/genui_surface.dart';
export 'src/facade/to_refactor/chat_widget.dart';
export 'src/facade/to_refactor/conversation_widget.dart';
Expand Down
66 changes: 0 additions & 66 deletions pkgs/flutter_genui/lib/src/ai_client/ai_client.dart

This file was deleted.

Loading
Loading