Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8182542
updating the flutter AI playground's behavior and layout
apeynado Oct 24, 2025
7ddd102
making navigation and style changes to improve look and feel
apeynado Oct 24, 2025
3cf3f49
added the free trial promotion to the blaze warning banner
apeynado Oct 27, 2025
0a64cb8
updating the hero image to reflect the current UX
apeynado Oct 27, 2025
94a3ec9
actually making the UI responsive
apeynado Oct 27, 2025
fb32b52
make the banana bigger
apeynado Oct 27, 2025
e836a0e
updated hero image
apeynado Oct 27, 2025
6136796
removed the headers from each demo app
apeynado Oct 27, 2025
6c45eb4
adding vertical padding to a few demos
apeynado Oct 27, 2025
76f043f
update audio input sample rate
khanhnwin Oct 28, 2025
c9d47a7
putting back message input field in bottom navigation bar
khanhnwin Oct 28, 2025
4f00882
deleting unused imagen demo
khanhnwin Oct 28, 2025
b4f51bf
remove unused imports
khanhnwin Oct 28, 2025
5cd46db
remove padding from top of multimodal & live api demos
khanhnwin Oct 28, 2025
764d8c5
replace bottom nav bar with a hamburger menu + drawer
khanhnwin Oct 28, 2025
c6e9af4
Merge pull request #1 from apeynado/apeynado/main
apeynado Oct 28, 2025
961bc59
refactor the common UI and service code
cynthiajoan Nov 11, 2025
03ab41b
add a dialog to trigger the function call
cynthiajoan Nov 13, 2025
4d65d1a
refactor the repeat logic for different layout
cynthiajoan Nov 13, 2025
91272eb
more layout refactor
cynthiajoan Nov 13, 2025
0d933c3
update the initialize logic for live api demo
cynthiajoan Nov 13, 2025
15b3835
keep firebase_options.dart out of gitignore
cynthiajoan Nov 13, 2025
108e8f7
remove the start dialog for chat's function call
cynthiajoan Nov 13, 2025
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
1 change: 1 addition & 0 deletions firebase_ai_logic_showcase/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ ephemeral/
#firebase
google-services.json
GoogleService-Info.plist
firebase.json
.firebaserc
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 28 additions & 77 deletions firebase_ai_logic_showcase/lib/demos/chat/chat_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import '../../shared/ui/app_frame.dart';
import '../../shared/ui/app_spacing.dart';
import './ui_components/ui_components.dart';
import './firebaseai_chat_service.dart';
import 'ui_components/model_picker.dart';
import './models/models.dart';
import '../../shared/ui/chat_components/ui_components.dart';
import '../../shared/chat_service.dart';
import '../../shared/models/models.dart';

class ChatDemo extends ConsumerStatefulWidget {
const ChatDemo({super.key});
Expand All @@ -45,18 +44,15 @@ class _ChatDemoState extends ConsumerState<ChatDemo> {
Uint8List? _attachment;
final ScrollController _scrollController = ScrollController();
bool _loading = false;
OverlayPortalController opController = OverlayPortalController();

@override
void initState() {
super.initState();
_chatService = ChatService(ref);
final model = geminiModels.selectModel('gemini-2.5-flash');
_chatService = ChatService(ref, model);
_chatService.init();
_userTextInputController.text = geminiModels.selectedModel.defaultPrompt;

WidgetsBinding.instance.addPostFrameCallback((_) {
opController.show();
});
_userTextInputController.text =
'Hey Gemini! Can you set the app color to purple?';
}

@override
Expand Down Expand Up @@ -162,79 +158,34 @@ class _ChatDemoState extends ConsumerState<ChatDemo> {
}
}

void showModelPicker() {
opController.hide();
showDialog(
context: context,
builder: (context) {
return ModelPicker(
selectedModel: geminiModels.selectedModel,
onSelected: (value) {
_chatService.changeModel(value);
setState(() {
_userTextInputController.text =
geminiModels.selectedModel.defaultPrompt;
_messages.clear();
});
},
);
},
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
title: const Text('Chat Demo'),
actions: [
OverlayPortal(
controller: opController,
child: IconButton(
onPressed: showModelPicker,
icon: Icon(Icons.settings_outlined),
),
overlayChildBuilder: (context) {
return Positioned(
right: 0,
top: 40,
child: Dialog(
insetAnimationDuration: Duration(milliseconds: 2000),
constraints: BoxConstraints(maxWidth: 500),
insetPadding: EdgeInsets.all(8),
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [Text('Try another model!')],
),
body: Column(
children: [
Expanded(
child: AppFrame(
child: Padding(
padding: const EdgeInsets.all(AppSpacing.s16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: MessageListView(
messages: _messages,
scrollController: _scrollController,
),
),
if (_loading) const LinearProgressIndicator(),
AttachmentPreview(attachment: _attachment),
],
),
),
);
},
),
],
),
body: AppFrame(
child: Padding(
padding: const EdgeInsets.all(AppSpacing.s16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: MessageListView(
messages: _messages,
scrollController: _scrollController,
),
),
if (_loading) const LinearProgressIndicator(),
AttachmentPreview(attachment: _attachment),
],
),
),
),
),
],
),
bottomNavigationBar: MessageInputBar(
textController: _userTextInputController,
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions firebase_ai_logic_showcase/lib/demos/chat/models/models.dart

This file was deleted.

241 changes: 241 additions & 0 deletions firebase_ai_logic_showcase/lib/demos/chat_nano/chat_nano_demo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
// Copyright 2025 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also duplicated code that doesn't need to be duplicated! We should eb able to use the original chat demo, just swap out the model in that is being used!

Choose a reason for hiding this comment

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

I cleaned up the chat demo so it will focus on the function calling part and always select the gemini 2.5 flash. The majority of the UI component is moved to shared folder and reuse between two demos. I think it's ok to have independent demo page for different purposes.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:typed_data';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:permission_handler/permission_handler.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import '../../shared/ui/app_frame.dart';
import '../../shared/ui/app_spacing.dart';
import '../../shared/ui/chat_components/ui_components.dart';
import '../../shared/chat_service.dart';
import '../../shared/ui/chat_components/model_picker.dart';
import '../../shared/models/models.dart';

class ChatDemoNano extends ConsumerStatefulWidget {
const ChatDemoNano({super.key, this.isSelected = false});
final bool isSelected;

@override
ConsumerState<ChatDemoNano> createState() => ChatDemoNanoState();
}

class ChatDemoNanoState extends ConsumerState<ChatDemoNano> {
// Service for interacting with the Gemini API.
late final ChatService _chatService;

// UI State
final List<MessageData> _messages = <MessageData>[];
final TextEditingController _userTextInputController =
TextEditingController();
Uint8List? _attachment;
final ScrollController _scrollController = ScrollController();
bool _loading = false;
OverlayPortalController opController = OverlayPortalController();
static bool _pickerHasBeenShown = false;

@override
void initState() {
super.initState();
_chatService = ChatService(ref);
geminiModels.selectModel('gemini-2.5-flash-image-preview');
_chatService.init();
_userTextInputController.text =
'Hot air balloons rising over the San Francisco Bay at golden hour with a view of the Golden Gate Bridge. Make it anime style.';
_checkAndShowPicker();
}

@override
void didUpdateWidget(ChatDemoNano oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isSelected != oldWidget.isSelected) {
_checkAndShowPicker();
}
}

void _checkAndShowPicker() {
if (widget.isSelected && !_pickerHasBeenShown) {
_pickerHasBeenShown = true;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
showModelPicker();
}
});
}
}

@override
void didChangeDependencies() {
requestPermissions();
super.didChangeDependencies();
}

@override
void dispose() {
_scrollController.dispose();
_userTextInputController.dispose();
super.dispose();
}

Future<void> requestPermissions() async {
if (!kIsWeb) {
await Permission.manageExternalStorage.request();
}
}

void _scrollToEnd() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_scrollController.hasClients) {
_scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
}
});
}

void _pickImage() async {
final pickedImage = await ImagePicker().pickImage(
source: ImageSource.gallery,
);

if (pickedImage != null) {
final imageBytes = await pickedImage.readAsBytes();
setState(() {
_attachment = imageBytes;
});
log('attachment saved!');
}
}

void sendMessage(String text) async {
if (text.isEmpty) return;

setState(() {
_loading = true;
});

// Add user message to UI
final userMessageText = text.trim();
final userAttachment = _attachment;
_messages.add(
MessageData(
text: userMessageText,
image: userAttachment != null ? Image.memory(userAttachment) : null,
fromUser: true,
),
);
setState(() {
_attachment = null;
_userTextInputController.clear();
});
_scrollToEnd();

// Construct the Content object for the service
final content = (userAttachment != null)
? Content.multi([
TextPart(userMessageText),
InlineDataPart('image/jpeg', userAttachment),
])
: Content.text(userMessageText);

// Call the service and handle the response
try {
final chatResponse = await _chatService.sendMessage(content);
_messages.add(
MessageData(
text: chatResponse.text,
image: chatResponse.image,
fromUser: false,
),
);
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(e.toString()),
backgroundColor: Theme.of(context).colorScheme.error,
),
);
}
} finally {
setState(() {
_loading = false;
});
_scrollToEnd();
}
}

void showModelPicker() {
showDialog(
context: context,
builder: (context) {
return ModelPicker(
selectedModel: geminiModels.selectedModel,
onSelected: (value) {
_chatService.changeModel(value);
setState(() {
_userTextInputController.text =
geminiModels.selectedModel.defaultPrompt;
_messages.clear();
});
},
);
},
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: AppFrame(
child: Padding(
padding: const EdgeInsets.all(AppSpacing.s16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: MessageListView(
messages: _messages,
scrollController: _scrollController,
),
),
if (_loading) const LinearProgressIndicator(),
AttachmentPreview(attachment: _attachment),
],
),
),
),
),
),
],
),
bottomNavigationBar: MessageInputBar(
textController: _userTextInputController,
loading: _loading,
sendMessage: sendMessage,
onPickImagePressed: _pickImage,
),
);
}
}
Loading