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
55 changes: 28 additions & 27 deletions packages/firebase_ai/firebase_ai/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GenerativeAISample extends StatefulWidget {
}

class _GenerativeAISampleState extends State<GenerativeAISample> {
bool _useVertexBackend = false;
bool _useAgentPlatform = false;
late GenerativeModel _currentModel;

static final ThemeData _darkTheme = ThemeData(
Expand All @@ -64,14 +64,15 @@ class _GenerativeAISampleState extends State<GenerativeAISample> {
void initState() {
super.initState();

_initializeModel(_useVertexBackend);
_initializeModel(_useAgentPlatform);
}

void _initializeModel(bool useVertexBackend) {
if (useVertexBackend) {
final vertexInstance = FirebaseAI.vertexAI(location: 'global');
final agentPlatformInstance =
FirebaseAI.agentPlatform(location: 'global');
_currentModel =
vertexInstance.generativeModel(model: 'gemini-3.1-flash-lite');
agentPlatformInstance.generativeModel(model: 'gemini-3.1-flash-lite');
} else {
final googleAI = FirebaseAI.googleAI();
_currentModel = googleAI.generativeModel(model: 'gemini-3.1-flash-lite');
Expand All @@ -80,24 +81,24 @@ class _GenerativeAISampleState extends State<GenerativeAISample> {

void _toggleBackend(bool value) {
setState(() {
_useVertexBackend = value;
_useAgentPlatform = value;
});
_initializeModel(_useVertexBackend);
_initializeModel(_useAgentPlatform);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter + ${_useVertexBackend ? 'Vertex AI' : 'Google AI'}',
title: 'Flutter + ${_useAgentPlatform ? 'Agent Platform' : 'Google AI'}',
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark,
theme: _darkTheme,
home: HomeScreen(
key: ValueKey(
'${_useVertexBackend}_${_currentModel.hashCode}',
'${_useAgentPlatform}_${_currentModel.hashCode}',
),
model: _currentModel,
useVertexBackend: _useVertexBackend,
useAgentPlatform: _useAgentPlatform,
onBackendChanged: _toggleBackend,
),
);
Expand All @@ -106,13 +107,13 @@ class _GenerativeAISampleState extends State<GenerativeAISample> {

class HomeScreen extends StatefulWidget {
final GenerativeModel model;
final bool useVertexBackend;
final bool useAgentPlatform;
final ValueChanged<bool> onBackendChanged;

const HomeScreen({
super.key,
required this.model,
required this.useVertexBackend,
required this.useAgentPlatform,
required this.onBackendChanged,
});

Expand All @@ -133,13 +134,13 @@ class _HomeScreenState extends State<HomeScreen> {
Widget _buildSelectedPage(
int index,
GenerativeModel currentModel,
bool useVertexBackend,
bool useAgentPlatform,
) {
switch (index) {
case 0:
return ChatPage(
title: 'Chat',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
case 1:
return CapabilitiesPage(
Expand All @@ -150,40 +151,40 @@ class _HomeScreenState extends State<HomeScreen> {
// FunctionCallingPage initializes its own model as per original design
return FunctionCallingPage(
title: 'Function Calling',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
case 3:
return ImageGenerationPage(
title: 'Image Gen',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
case 4:
return BidiPage(
title: 'Live Stream',
model: currentModel,
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
case 5:
return ServerTemplatePage(
title: 'Server Template',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
case 6:
return GroundingPage(
title: 'Grounding',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
case 7:
return TTSPage(
title: 'TTS Test',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);

default:
// Fallback to the first page in case of an unexpected index
return ChatPage(
title: 'Chat',
useVertexBackend: useVertexBackend,
useAgentPlatform: useAgentPlatform,
);
}
}
Expand All @@ -193,7 +194,7 @@ class _HomeScreenState extends State<HomeScreen> {
return Scaffold(
appBar: AppBar(
title: Text(
'Flutter + ${widget.useVertexBackend ? 'Vertex AI' : 'Google AI'}',
'Flutter + ${widget.useAgentPlatform ? 'Agent Platform' : 'Google AI'}',
),
actions: <Widget>[
IconButton(
Expand All @@ -217,24 +218,24 @@ class _HomeScreenState extends State<HomeScreen> {
'Google AI',
style: TextStyle(
fontSize: 12,
color: widget.useVertexBackend
color: widget.useAgentPlatform
? Theme.of(context).colorScheme.onSurface.withAlpha(180)
: Theme.of(context).colorScheme.primary,
),
),
Switch(
value: widget.useVertexBackend,
value: widget.useAgentPlatform,
onChanged: widget.onBackendChanged,
activeTrackColor: Colors.green.withAlpha(128),
inactiveTrackColor: Colors.blueGrey.withAlpha(128),
activeThumbColor: Colors.green,
inactiveThumbColor: Colors.blueGrey,
),
Text(
'Vertex AI',
'Agent Platform',
style: TextStyle(
fontSize: 12,
color: widget.useVertexBackend
color: widget.useAgentPlatform
? Theme.of(context).colorScheme.primary
: Theme.of(context)
.colorScheme
Expand All @@ -251,15 +252,15 @@ class _HomeScreenState extends State<HomeScreen> {
child: _buildSelectedPage(
_selectedIndex,
widget.model,
widget.useVertexBackend,
widget.useAgentPlatform,
),
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
selectedFontSize: 10,
unselectedFontSize: 9,
selectedItemColor: Theme.of(context).colorScheme.primary,
unselectedItemColor: widget.useVertexBackend
unselectedItemColor: widget.useAgentPlatform
? Theme.of(context).colorScheme.onSurface.withAlpha(180)
: Colors.grey,
items: const <BottomNavigationBarItem>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class BidiSessionController extends ChangeNotifier {
];

_liveModel = useVertexBackend
? FirebaseAI.vertexAI().liveGenerativeModel(
? FirebaseAI.agentPlatform().liveGenerativeModel(
model: 'gemini-live-2.5-flash-preview-native-audio-09-2025',
liveGenerationConfig: config,
tools: tools,
Expand Down Expand Up @@ -561,12 +561,12 @@ class BidiPage extends StatefulWidget {
super.key,
required this.title,
required this.model,
required this.useVertexBackend,
required this.useAgentPlatform,
});

final String title;
final GenerativeModel model;
final bool useVertexBackend;
final bool useAgentPlatform;

@override
State<BidiPage> createState() => _BidiPageState();
Expand All @@ -583,7 +583,7 @@ class _BidiPageState extends State<BidiPage> {
super.initState();
_controller = BidiSessionController(
model: widget.model,
useVertexBackend: widget.useVertexBackend,
useVertexBackend: widget.useAgentPlatform,
onShowError: _showError,
onScrollDown: _scrollDown,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class ChatPage extends StatefulWidget {
const ChatPage({
super.key,
required this.title,
required this.useVertexBackend,
required this.useAgentPlatform,
});

final String title;
final bool useVertexBackend;
final bool useAgentPlatform;

@override
State<ChatPage> createState() => _ChatPageState();
Expand Down Expand Up @@ -52,8 +52,8 @@ class _ChatPageState extends State<ChatPage> {
? ThinkingConfig.withThinkingLevel(ThinkingLevel.medium)
: null,
);
if (widget.useVertexBackend) {
_model = FirebaseAI.vertexAI(location: 'global').generativeModel(
if (widget.useAgentPlatform) {
_model = FirebaseAI.agentPlatform().generativeModel(
model: 'gemini-3.1-flash-lite',
generationConfig: generationConfig,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class FunctionCallingPage extends StatefulWidget {
const FunctionCallingPage({
super.key,
required this.title,
required this.useVertexBackend,
required this.useAgentPlatform,
});

final String title;
final bool useVertexBackend;
final bool useAgentPlatform;

@override
State<FunctionCallingPage> createState() => _FunctionCallingPageState();
Expand Down Expand Up @@ -235,8 +235,8 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
: null,
);

final aiClient = widget.useVertexBackend
? FirebaseAI.vertexAI(location: 'global')
final aiClient = widget.useAgentPlatform
? FirebaseAI.agentPlatform()
: FirebaseAI.googleAI();

_functionCallModel = aiClient.generativeModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class GroundingPage extends StatefulWidget {
const GroundingPage({
super.key,
required this.title,
required this.useVertexBackend,
required this.useAgentPlatform,
});

final String title;
final bool useVertexBackend;
final bool useAgentPlatform;

@override
State<GroundingPage> createState() => _GroundingPageState();
Expand Down Expand Up @@ -73,8 +73,8 @@ class _GroundingPageState extends State<GroundingPage> {
}
}

final aiProvider = widget.useVertexBackend
? FirebaseAI.vertexAI(location: 'global')
final aiProvider = widget.useAgentPlatform
? FirebaseAI.agentPlatform()
: FirebaseAI.googleAI();

_model = aiProvider.generativeModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class ImageGenerationPage extends StatefulWidget {
const ImageGenerationPage({
super.key,
required this.title,
required this.useVertexBackend,
required this.useAgentPlatform,
});

final String title;
final bool useVertexBackend;
final bool useAgentPlatform;

@override
State<ImageGenerationPage> createState() => _ImageGenerationPageState();
Expand All @@ -49,8 +49,9 @@ class _ImageGenerationPageState extends State<ImageGenerationPage> {
}

void _initializeModel() {
final aiClient =
widget.useVertexBackend ? FirebaseAI.vertexAI() : FirebaseAI.googleAI();
final aiClient = widget.useAgentPlatform
? FirebaseAI.agentPlatform()
: FirebaseAI.googleAI();

_model = aiClient.generativeModel(
model: 'gemini-2.5-flash-image',
Expand Down
Loading
Loading