Skip to content

Commit f91df75

Browse files
authored
feat(firebaseai): update Live API sample to add video support. (#18018)
* add audio visualizer and prepare for video * add the video preview component * add video support in macOS * video and audio somehow works * somehow working with audio/video input on mac and web * make web audio and video working * some fix for macos video * some more attempt for macOS camera stream * code review clean up * fix formatter * fix analyzer
1 parent e8e8539 commit f91df75

File tree

14 files changed

+1035
-206
lines changed

14 files changed

+1035
-206
lines changed

packages/firebase_ai/firebase_ai/example/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
<true/>
4646
<key>UIApplicationSupportsIndirectInputEvents</key>
4747
<true/>
48+
<key>NSCameraUsageDescription</key>
49+
<string>We need camera access to take pictures and record video.</string>
4850
<key>NSMicrophoneUsageDescription</key>
4951
<string>We need access to the microphone to record audio.</string>
5052
</dict>

packages/firebase_ai/firebase_ai/example/lib/main.dart

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'package:firebase_core/firebase_core.dart';
1818
import 'package:flutter/material.dart';
1919

2020
// Import after file is generated through flutterfire_cli.
21-
// import 'package:firebase_ai_example/firebase_options.dart';
21+
//import 'package:firebase_ai_example/firebase_options.dart';
2222

2323
import 'pages/audio_page.dart';
2424
import 'pages/bidi_page.dart';
@@ -54,7 +54,14 @@ class _GenerativeAISampleState extends State<GenerativeAISample> {
5454
bool _useVertexBackend = false;
5555
late GenerativeModel _currentModel;
5656
late ImagenModel _currentImagenModel;
57-
int _currentBottomNavIndex = 0;
57+
58+
static final ThemeData _darkTheme = ThemeData(
59+
colorScheme: ColorScheme.fromSeed(
60+
brightness: Brightness.dark,
61+
seedColor: const Color.fromARGB(255, 171, 222, 244),
62+
),
63+
useMaterial3: true,
64+
);
5865

5966
@override
6067
void initState() {
@@ -98,25 +105,13 @@ class _GenerativeAISampleState extends State<GenerativeAISample> {
98105
_initializeModel(_useVertexBackend);
99106
}
100107

101-
void _onBottomNavTapped(int index) {
102-
setState(() {
103-
_currentBottomNavIndex = index;
104-
});
105-
}
106-
107108
@override
108109
Widget build(BuildContext context) {
109110
return MaterialApp(
110111
title: 'Flutter + ${_useVertexBackend ? 'Vertex AI' : 'Google AI'}',
111112
debugShowCheckedModeBanner: false,
112113
themeMode: ThemeMode.dark,
113-
theme: ThemeData(
114-
colorScheme: ColorScheme.fromSeed(
115-
brightness: Brightness.dark,
116-
seedColor: const Color.fromARGB(255, 171, 222, 244),
117-
),
118-
useMaterial3: true,
119-
),
114+
theme: _darkTheme,
120115
home: HomeScreen(
121116
key: ValueKey(
122117
'${_useVertexBackend}_${_currentModel.hashCode}',
@@ -125,8 +120,6 @@ class _GenerativeAISampleState extends State<GenerativeAISample> {
125120
imagenModel: _currentImagenModel,
126121
useVertexBackend: _useVertexBackend,
127122
onBackendChanged: _toggleBackend,
128-
selectedIndex: _currentBottomNavIndex,
129-
onSelectedIndexChanged: _onBottomNavTapped,
130123
),
131124
);
132125
}
@@ -137,26 +130,26 @@ class HomeScreen extends StatefulWidget {
137130
final ImagenModel imagenModel;
138131
final bool useVertexBackend;
139132
final ValueChanged<bool> onBackendChanged;
140-
final int selectedIndex;
141-
final ValueChanged<int> onSelectedIndexChanged;
142133

143134
const HomeScreen({
144135
super.key,
145136
required this.model,
146137
required this.imagenModel,
147138
required this.useVertexBackend,
148139
required this.onBackendChanged,
149-
required this.selectedIndex,
150-
required this.onSelectedIndexChanged,
151140
});
152141

153142
@override
154143
State<HomeScreen> createState() => _HomeScreenState();
155144
}
156145

157146
class _HomeScreenState extends State<HomeScreen> {
147+
int _selectedIndex = 0;
148+
158149
void _onItemTapped(int index) {
159-
widget.onSelectedIndexChanged(index);
150+
setState(() {
151+
_selectedIndex = index;
152+
});
160153
}
161154

162155
// Method to build the selected page on demand
@@ -264,7 +257,7 @@ class _HomeScreenState extends State<HomeScreen> {
264257
),
265258
body: Center(
266259
child: _buildSelectedPage(
267-
widget.selectedIndex,
260+
_selectedIndex,
268261
widget.model,
269262
widget.imagenModel,
270263
widget.useVertexBackend,
@@ -344,7 +337,7 @@ class _HomeScreenState extends State<HomeScreen> {
344337
tooltip: 'Server Template',
345338
),
346339
],
347-
currentIndex: widget.selectedIndex,
340+
currentIndex: _selectedIndex,
348341
onTap: _onItemTapped,
349342
),
350343
);

0 commit comments

Comments
 (0)