@@ -23,8 +23,7 @@ import 'utilities/utilities.dart';
2323import 'firebaseai_live_api_service.dart' ;
2424
2525class LiveAPIDemo extends ConsumerStatefulWidget {
26- const LiveAPIDemo ({super .key, this .isSelected = false });
27- final bool isSelected;
26+ const LiveAPIDemo ({super .key});
2827
2928 @override
3029 ConsumerState <LiveAPIDemo > createState () => _LiveAPIDemoState ();
@@ -45,9 +44,7 @@ class _LiveAPIDemoState extends ConsumerState<LiveAPIDemo> {
4544 late final VideoInput _videoInput = VideoInput ();
4645
4746 // Initialization flags.
48- bool _audioIsInitialized = false ;
4947 bool _videoIsInitialized = false ;
50- static bool _hasBeenSelected = false ;
5148
5249 // UI State flags.
5350 bool _isConnecting = false ; // True when setting up the Gemini session.
@@ -66,24 +63,19 @@ class _LiveAPIDemoState extends ConsumerState<LiveAPIDemo> {
6663 @override
6764 void didUpdateWidget (LiveAPIDemo oldWidget) {
6865 super .didUpdateWidget (oldWidget);
69- if (widget.isSelected != oldWidget.isSelected) {
70- _checkAndInitializeIO ();
71- }
66+ _checkAndInitializeIO ();
7267 }
7368
7469 Future <void > _checkAndInitializeIO () async {
75- if (widget.isSelected && ! _hasBeenSelected) {
76- _hasBeenSelected = true ;
77- await _initializeAudio ();
78- await _initializeVideo ();
79- _liveApiService = LiveApiService (
80- audioOutput: _audioOutput,
81- ref: ref, // Pass the ref to the service
82- onImageLoadingChange: _onImageLoadingChange,
83- onImageGenerated: _onImageGenerated,
84- onError: _showErrorSnackBar,
85- );
86- }
70+ await _initializeAudio ();
71+ await _initializeVideo ();
72+ _liveApiService = LiveApiService (
73+ audioOutput: _audioOutput,
74+ ref: ref, // Pass the ref to the service
75+ onImageLoadingChange: _onImageLoadingChange,
76+ onImageGenerated: _onImageGenerated,
77+ onError: _showErrorSnackBar,
78+ );
8779 }
8880
8981 @override
0 commit comments