### Basic LivekitRoom Setup with MaterialApp Source: https://context7.com/livekit/components-flutter/llms.txt A basic example of setting up LivekitRoom within a MaterialApp, demonstrating how to provide theme data and conditionally render content based on connection status. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { // LiveKitTheme provides an out-of-the-box dark theme. return LivekitRoom( roomContext: RoomContext( url: 'wss://my-project.livekit.cloud', token: '', connect: true, ), builder: (context, roomCtx) => MaterialApp( theme: LiveKitTheme().buildThemeData(context), home: Scaffold( body: roomCtx.connected ? const Text('In room') : const CircularProgressIndicator(), ), ), ); } } ``` -------------------------------- ### Installation Bundle Configuration Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. It sets the installation prefix to a 'bundle' directory within the build directory and ensures a clean bundle on each install. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Application Executable Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Installs the main application executable to the specified runtime destination. This is a core step for deploying the application. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Define Installation Directories Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Sets variables for the installation directories within the bundle. This organizes data and libraries for the application. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Installs the Flutter assets directory to the application bundle. It first removes any existing directory to ensure a clean installation. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install( CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Configure Installation Prefix for Bundled App Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Sets the installation prefix to be next to the executable, facilitating in-place running and Visual Studio integration. This ensures support files are correctly located. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install Flutter Library Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Installs the main Flutter library file to the bundle's root directory. This is essential for the Flutter engine to run. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Installs any bundled native libraries provided by plugins. This ensures that plugins have their required dependencies available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Initialize and Start Agent Session in Flutter Source: https://github.com/livekit/components-flutter/blob/main/README.md Demonstrates how to initialize a LiveKit agent session using `Session.withAgent` and start the connection. Ensure the token endpoint is correctly configured. The session is disposed of in the `dispose` method. ```dart import 'package:livekit_client/livekit_client.dart'; import 'package:livekit_components/livekit_components.dart'; class AgentChatView extends StatefulWidget { const AgentChatView({super.key}); @override State createState() => _AgentChatViewState(); } class _AgentChatViewState extends State { late final Session _session; @override void initState() { super.initState(); _session = Session.withAgent( 'my-agent', tokenSource: EndpointTokenSource( url: Uri.parse('https://your-token-endpoint'), ), options: const SessionOptions(preConnectAudio: true), ); unawaited(_session.start()); // start connecting the agent session } @override void dispose() { _session.dispose(); // ends the session and cleans up listeners super.dispose(); } @override Widget build(BuildContext context) { return SessionContext( session: _session, child: ChatScrollView( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20), messageBuilder: (context, message) => ListTile( title: Text(message.content.text), subtitle: Text(message.timestamp.toLocal().toIso8601String()), ), ), ); } } ``` -------------------------------- ### Add livekit_components to pubspec.yaml Source: https://github.com/livekit/components-flutter/blob/main/README.md Add this dependency to your pubspec.yaml file and run `flutter pub get` to install the package. ```yaml dependencies: livekit_components: ^1.3.0 ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Installs the Flutter assets directory, which contains UI resources like images and fonts. It ensures that the assets are copied correctly and removes stale files from previous builds. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library Conditionally Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Installs the AOT (Ahead-Of-Time) compiled library. This is only performed for builds that are not of type 'Debug'. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Installs any bundled native libraries from plugins into the 'lib' subdirectory of the bundle. This ensures that all necessary plugin dependencies are included in the application package. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Install AOT Library for Release Builds Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on non-Debug builds (Profile and Release). This is used for performance optimization. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Copies native assets provided by packages into the 'lib' subdirectory of the bundle. This ensures that any platform-specific assets required by plugins or the application are included. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Copies native assets provided by the build.dart script from all packages into the application bundle. These assets are typically required for platform-specific functionality. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter ICU Data File Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Installs the ICU data file, which is necessary for internationalization and localization, to the data directory of the bundle. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Specifies the minimum required CMake version and defines the project name. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) ``` -------------------------------- ### Programmatically Toggle Chat Visibility Source: https://context7.com/livekit/components-flutter/llms.txt Control the chat visibility from any widget using RoomContext. This example shows how to create a button that toggles the chat interface on and off. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class ChatToggleBtn extends StatelessWidget { const ChatToggleBtn({super.key}); @override Widget build(BuildContext context) { final roomCtx = RoomContext.of(context)!; return IconButton( icon: Icon(roomCtx.isChatEnabled ? Icons.chat : Icons.chat_bubble_outline), onPressed: () => roomCtx.toggleChat(!roomCtx.isChatEnabled), ); } } ``` -------------------------------- ### Define Flutter Library and Headers Source: https://github.com/livekit/components-flutter/blob/main/example/linux/flutter/CMakeLists.txt Sets the path to the Flutter Linux GTK shared library and its associated header files. These are published to the parent scope for use in the installation step. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Export Flutter library and ICU data Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Exports the Flutter library path and the ICU data file path to the parent scope for use in the install step. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) ``` -------------------------------- ### Application ID Definition Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Defines the APPLICATION_ID preprocessor macro using the value set earlier. This macro is often used within the application code to identify the application, for example, for D-Bus activation. ```cmake add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Initialize RoomContext and LivekitRoom Widget Source: https://context7.com/livekit/components-flutter/llms.txt Initialize RoomContext with connection details and use LivekitRoom to provide room state to the widget tree. Auto-connects on creation and handles connection events. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class VideoCallPage extends StatelessWidget { const VideoCallPage({super.key}); @override Widget build(BuildContext context) { return LivekitRoom( roomContext: RoomContext( url: 'wss://my-project.livekit.cloud', token: '', connect: true, // auto-connect on creation enableAudioVisulizer: true, // enable audio visualizer support roomOptions: const RoomOptions(), onConnected: () => debugPrint('Connected!'), onDisconnected: () => debugPrint('Disconnected.'), onError: (err) => debugPrint('Error: $err'), ), builder: (context, roomCtx) { return Scaffold( appBar: AppBar( title: Text(roomCtx.roomName ?? 'Connecting…'), actions: [ if (roomCtx.activeRecording) const Icon(Icons.fiber_manual_record, color: Colors.red), ], ), body: Text( 'Participants: ${roomCtx.participantCount} | ' 'State: ${roomCtx.connectionState}', ), ); }, ); } } ``` -------------------------------- ### System Dependencies Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Finds and checks for the PkgConfig tool and the 'gtk+-3.0' library. This ensures that GTK+ 3 development files are available for linking and header inclusion. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/livekit/components-flutter/blob/main/example/windows/runner/CMakeLists.txt Applies a predefined set of build settings to the application target. This can be customized or removed if different build configurations are required. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Agent Chat Page with SessionContext Source: https://context7.com/livekit/components-flutter/llms.txt Demonstrates setting up an AI agent chat interface using SessionContext to manage the session and ChatScrollView to display messages. Requires a token source for authentication. ```dart import 'dart:async'; import 'package:flutter/material.dart'; import 'package:livekit_client/livekit_client.dart'; import 'package:livekit_components/livekit_components.dart'; class AgentChatPage extends StatefulWidget { const AgentChatPage({super.key}); @override State createState() => _AgentChatPageState(); } class _AgentChatPageState extends State { late final Session _session; @override void initState() { super.initState(); _session = Session.withAgent( 'my-voice-agent', tokenSource: EndpointTokenSource( url: Uri.parse('https://api.example.com/token'), ), options: const SessionOptions(preConnectAudio: true), ); unawaited(_session.start()); } @override void dispose() { _session.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Agent Chat')), body: SessionContext( session: _session, child: ChatScrollView( autoScroll: true, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), messageBuilder: (context, message) => ListTile( title: Text(message.content.text), subtitle: Text( message.timestamp.toLocal().toIso8601String(), style: const TextStyle(fontSize: 10), ), ), ), ), ); } } // Alternative: pass Session directly without SessionContext. class AgentChatDirect extends StatelessWidget { final Session session; const AgentChatDirect({super.key, required this.session}); @override Widget build(BuildContext context) { return ChatScrollView( session: session, messageBuilder: (context, message) => Text(message.content.text), ); } } ``` -------------------------------- ### Cross-building Sysroot Configuration Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Sets up the sysroot and find root path for cross-compilation. This is used when building for a different architecture or platform, ensuring the compiler and linker can find necessary headers and libraries. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/livekit/components-flutter/blob/main/example/windows/runner/CMakeLists.txt Adds necessary dependency libraries and include directories for the application. Custom application-specific dependencies should be added here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Basic LiveKit Room Integration in Flutter Source: https://github.com/livekit/components-flutter/blob/main/README.md Integrate LiveKit video, audio, and data features into your Flutter app by wrapping your app with `LivekitRoom`. Ensure your `RoomContext` has the correct room URL and token. The `builder` callback provides access to the `roomCtx` for further customization. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return LivekitRoom( roomContext: RoomContext( url: 'your room url', token: 'your room token', connect: true, ), builder: (context, roomCtx) { return MaterialApp( theme: LiveKitTheme().buildThemeData(context), home: Scaffold( appBar: AppBar( title: const Text('LiveKit Components Sample'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( /// show participant loop child: ParticipantLoop( showAudioTracks: false, showVideoTracks: true, /// layout builder layoutBuilder: const GridLayoutBuilder(), /// participant builder participantBuilder: (context) { /// build participant widget for each Track /// return ParticipantTileWidget for each participant /// you can customize the widget as you want, please refer to the example /// https://github.com/livekit/components-flutter/blob/main/example/lib/main.dart#L130-L168 return const ParticipantTileWidget(); }, ), ), /// show control bar at the bottom const ControlBar(), ], ), ), ), ); }, ); } } ``` -------------------------------- ### Create static library for Flutter wrapper plugin Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Creates a static library for the Flutter wrapper plugin, including core and plugin-specific sources, and applies standard build settings. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Define C++ wrapper application sources Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Lists the C++ source files specific to the application runner and prepends the wrapper root directory path. ```cmake list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Define C++ wrapper plugin sources Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Lists the C++ source files specific to the plugin wrapper and prepends the wrapper root directory path. ```cmake list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Configure Flutter tool backend custom command Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Sets up a custom command to run the Flutter tool backend, ensuring it executes every time by using a phony output file. This command generates necessary build artifacts like the Flutter library and headers. ```cmake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Create static library for Flutter wrapper application Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Creates a static library for the Flutter wrapper application, including core and application-specific sources, and applies standard build settings. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Adds preprocessor definitions to enable Unicode support for all projects. This is crucial for handling international characters correctly. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Define C++ wrapper core sources Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Lists the core C++ source files for the wrapper and prepends the wrapper root directory path. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Include generated configuration Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Includes the generated configuration file, which provides settings from the Flutter tool. ```cmake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Configure Flutter GTK Dependencies Source: https://github.com/livekit/components-flutter/blob/main/example/linux/flutter/CMakeLists.txt This section finds and checks for required system-level dependencies using PkgConfig, specifically GTK, GLib, and GIO. These are essential for the Flutter GTK integration. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Build Room UI with ParticipantLoop Source: https://context7.com/livekit/components-flutter/llms.txt Use ParticipantLoop to iterate over participants and render their audio/video tracks. Configure track visibility, placeholders, layout, and a custom participant track builder. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class RoomBody extends StatelessWidget { const RoomBody({super.key}); @override Widget build(BuildContext context) { return ParticipantLoop( showVideoTracks: true, showAudioTracks: true, showParticipantPlaceholder: true, // show tile even when no track layoutBuilder: const CarouselLayoutBuilder(), // or GridLayoutBuilder() participantTrackBuilder: (context, identifier) { return Padding( padding: const EdgeInsets.all(2), child: Stack( children: [ // Video or audio visualizer background identifier.isAudio ? const AudioVisualizerWidget( backgroundColor: LKColors.lkDarkBlue, ) : IsSpeakingIndicator( builder: (context, isSpeaking) => isSpeaking == true ? IsSpeakingIndicatorWidget( isSpeaking: isSpeaking!, child: const VideoTrackWidget(), ) : const VideoTrackWidget(), ), // Pin / focus button const Positioned(top: 0, right: 0, child: FocusToggle()), // Stats overlay const Positioned(top: 8, left: 0, child: TrackStatsWidget()), // Name / mute bar const Positioned( bottom: 0, left: 0, right: 0, child: ParticipantStatusBar(), ), ], ), ); }, ); } } ``` -------------------------------- ### Configure ControlBar for Media Controls Source: https://context7.com/livekit/components-flutter/llms.txt Use ControlBar to display and configure media control buttons like microphone, camera, screen share, chat, and disconnect. Customize visibility, colors, and device selectors. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class RoomScreen extends StatelessWidget { const RoomScreen({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ const AdaptiveLayout(), const Positioned( bottom: 24, left: 0, right: 0, child: ControlBar( microphone: true, camera: true, screenShare: true, chat: true, leave: true, audioOutput: true, // shown only on desktop/web showTitleWidget: false, backgroundColor: Colors.grey, selectedColor: LKColors.lkBlue, foregroundColor: Colors.white, ), ), ], ), ); } } ``` -------------------------------- ### Access and Control Media Devices with MediaDeviceContext Source: https://context7.com/livekit/components-flutter/llms.txt Access MediaDeviceContext directly from the widget tree to enumerate devices, track selections, and control camera/microphone. Ensure MediaDeviceContext is provided within the LivekitRoom widget. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; // Access MediaDeviceContext directly from the widget tree. class DevicePanel extends StatelessWidget { const DevicePanel({super.key}); @override Widget build(BuildContext context) { final deviceCtx = MediaDeviceContext.of(context)!; return Column( children: [ Text('Video inputs: ${deviceCtx.videoInputs?.length ?? 0}'), Text('Audio inputs: ${deviceCtx.audioInputs?.length ?? 0}'), Text('Camera on: ${deviceCtx.cameraOpened}'), Text('Mic on: ${deviceCtx.microphoneOpened}'), ElevatedButton( onPressed: deviceCtx.cameraOpened ? deviceCtx.disableCamera : deviceCtx.enableCamera, child: Text(deviceCtx.cameraOpened ? 'Turn Off Camera' : 'Turn On Camera'), ), ElevatedButton( onPressed: deviceCtx.microphoneOpened ? deviceCtx.disableMicrophone : deviceCtx.enableMicrophone, child: Text(deviceCtx.microphoneOpened ? 'Mute' : 'Unmute'), ), // Switch speaker (mobile only) if (deviceCtx.canSwitchSpeakerphone) ElevatedButton( onPressed: () => deviceCtx.setSpeakerphoneOn(!(deviceCtx.isSpeakerOn ?? false)), child: Text(deviceCtx.isSpeakerOn == true ? 'Earpiece' : 'Speaker'), ), ], ); } } ``` -------------------------------- ### LiveKit Theming: LiveKitTheme Source: https://context7.com/livekit/components-flutter/llms.txt Apply LiveKit's brand palette, Montserrat font, and pre-styled UI elements by using LiveKitTheme().buildThemeData(context) to generate a ThemeData. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class ThemedApp extends StatelessWidget { const ThemedApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'My LiveKit App', theme: LiveKitTheme().buildThemeData(context), home: const MyRoomPage(), ); } } // Access brand colors anywhere: // LKColors.lkBlue → Color(0xFF5A8BFF) // LKColors.lkLightBlue → Color(0xFF8AB4FF) // LKColors.lkDarkBlue → Color(0xFF00153C) ``` -------------------------------- ### Set wrapper root directory Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Defines the root directory for the C++ client wrapper sources. ```cmake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Executable Output Directory Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to a subdirectory within the build directory. This is done to prevent users from running the unbundled executable, which may not function correctly due to missing resources. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Audio Visualizer Widget for LiveKit Tracks Source: https://context7.com/livekit/components-flutter/llms.txt The AudioVisualizerWidget provides an animated bar-style audio spectrum visualization. It can be placed within a ParticipantTrack subtree that provides an AudioTrack via TrackReferenceContext. It also includes special animations for AI agent states. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; // Must be placed inside a ParticipantTrack subtree that provides // a TrackReferenceContext for an audio track. class AgentVisualizerTile extends StatelessWidget { const AgentVisualizerTile({super.key}); @override Widget build(BuildContext context) { return SizedBox( height: 80, child: AudioVisualizerWidget( backgroundColor: LKColors.lkDarkBlue, options: const AudioVisualizerWidgetOptions( barCount: 9, centeredBands: true, minHeight: 8, maxHeight: 60, durationInMilliseconds: 400, spacing: 4, cornerRadius: 9999, barMinOpacity: 0.15, // color: Colors.cyan, // defaults to theme primary color ), ), ); } } ``` -------------------------------- ### Create Flutter interface library Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Creates an interface library target for Flutter, specifying include directories and linking against the Flutter library. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Link Application Dependencies Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Links the application executable against the 'flutter' library and the 'PkgConfig::GTK' imported target. This makes the Flutter engine and GTK+ functionalities available to the application. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Define Build Configuration Types Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Configures the available build types (Debug, Profile, Release) for the project. It handles both multi-configuration and single-configuration generators. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Application Executable Target Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Defines the main executable target for the application. It lists the source files, including the main entry point, application-specific code, and generated plugin registration code. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Integrate Flutter Build Tool Source: https://github.com/livekit/components-flutter/blob/main/example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's build process is executed as part of the main target's dependencies. This step is mandatory and should not be removed. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Runtime Library Path Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Configures the runtime search path for libraries to include the 'lib' directory relative to the executable. This is crucial for ensuring the application can find its bundled libraries at runtime. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Define Flutter library headers Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Lists the header files for the Flutter library and prepends the ephemeral directory path to each. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") ``` -------------------------------- ### Displaying Live Captions with TranscriptionBuilder Source: https://context7.com/livekit/components-flutter/llms.txt Renders live transcriptions as overlaid captions using TranscriptionBuilder and TranscriptionWidget. Ensure TranscriptionContextMixin is integrated into your RoomContext. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class CaptionsOverlay extends StatelessWidget { const CaptionsOverlay({super.key}); @override Widget build(BuildContext context) { return TranscriptionBuilder( builder: (context, roomCtx, transcriptions) { if (transcriptions.isEmpty) return const SizedBox.shrink(); return Positioned( bottom: 80, left: 16, right: 16, child: TranscriptionWidget(transcriptions: transcriptions), ); }, ); } } // Manually insert a local transcription segment (e.g. for testing): void injectLocalCaption(RoomContext roomCtx) { roomCtx.insertTranscription( TranscriptionForParticipant( TranscriptionSegment( id: 'local-1', text: 'Hello from local!', isFinal: true, firstReceivedTime: DateTime.now(), lastReceivedTime: DateTime.now(), startTime: 0, endTime: 0, ), null, // no remote participant ), ); } ``` -------------------------------- ### In-Room Chat UI with ChatWidget and ChatBuilder Source: https://context7.com/livekit/components-flutter/llms.txt Implement a reactive chat UI using ChatBuilder and ChatWidget. ChatBuilder manages chat messages and enables/disables chat, while ChatWidget provides the visual interface for displaying messages and sending new ones. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class InRoomChat extends StatelessWidget { const InRoomChat({super.key}); @override Widget build(BuildContext context) { return ChatBuilder( builder: (context, isChatEnabled, chatCtx, messages) { if (!isChatEnabled) return const SizedBox.shrink(); return ChatWidget( messages: messages, // List onSend: (text) => chatCtx.sendMessage(text), onClose: () => chatCtx.toggleChat(false), ); }, ); } } ``` -------------------------------- ### Include Runner Application Build Rules Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Includes the CMake build rules for the application runner. This allows the main application logic to be built. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Custom Video Tile with VideoTrackWidget Source: https://context7.com/livekit/components-flutter/llms.txt Displays a video stream using VideoTrackWidget, with a fallback UI defined by noTrackBuilder. Includes a ParticipantStatusBar for additional information. ```dart import 'package:flutter/material.dart'; import 'package:livekit_client/livekit_client.dart'; import 'package:livekit_components/livekit_components.dart'; class CustomVideoTile extends StatelessWidget { const CustomVideoTile({super.key}); @override Widget build(BuildContext context) { return Stack( children: [ VideoTrackWidget( fit: VideoViewFit.cover, // or VideoViewFit.contain (default) noTrackBuilder: (context) => Container( color: Colors.black, alignment: Alignment.center, child: const Icon(Icons.person, size: 64, color: Colors.white54), ), ), const Positioned(bottom: 4, left: 4, child: ParticipantStatusBar()), ], ); } } ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/livekit/components-flutter/blob/main/example/linux/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command is designed to run every time by using a non-existent output file '_phony_' to ensure the Flutter library and headers are generated. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) ``` -------------------------------- ### Adaptive Layout with GridLayoutBuilder and CarouselLayoutBuilder Source: https://context7.com/livekit/components-flutter/llms.txt Implement an adaptive layout that switches between a grid and a carousel based on whether tracks are pinned. This uses ParticipantLoop with different layout builders. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; // Dynamic layout: carousel when a track is pinned, grid otherwise. class AdaptiveLayout extends StatelessWidget { const AdaptiveLayout({super.key}); @override Widget build(BuildContext context) { final roomCtx = RoomContext.of(context)!; return ParticipantLoop( showVideoTracks: true, showAudioTracks: false, layoutBuilder: roomCtx.pinnedTracks.isNotEmpty ? const CarouselLayoutBuilder() : const GridLayoutBuilder(), participantTrackBuilder: (ctx, _) => const ParticipantTileWidget(), ); } } ``` -------------------------------- ### Define Flutter library path Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Sets the path to the Flutter Windows DLL, which is essential for linking. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") ``` -------------------------------- ### Opt-in to Modern CMake Behaviors Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Explicitly enables modern CMake behaviors to avoid warnings in recent CMake versions. It sets the policy for a range of versions. ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Add Flutter Library Interface Target Source: https://github.com/livekit/components-flutter/blob/main/example/linux/flutter/CMakeLists.txt Creates an INTERFACE library target named 'flutter' and configures its include directories and link libraries. This includes Flutter headers, the main Flutter library, and the GTK/GLib/GIO dependencies. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Standard Compilation Settings Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Defines a function to apply common compilation settings to targets. This includes enabling C++14, setting Wall and Werror flags, and applying optimization and NDEBUG definitions based on the build configuration. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Project and Executable Naming Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, executable name, and application identifier. The executable name should match the BINARY_NAME variable for `flutter run` to function correctly. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) set(BINARY_NAME "example") set(APPLICATION_ID "io.livekit.fluttercomponents.example.example") ``` -------------------------------- ### Set Profile Build Mode Linker and Compiler Flags Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Configures linker and compiler flags for the Profile build mode, often by copying settings from the Release mode. This ensures consistent performance characteristics. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Define list_prepend function for CMake < 3.10 Source: https://github.com/livekit/components-flutter/blob/main/example/linux/flutter/CMakeLists.txt This custom function mimics the behavior of list(TRANSFORM ... PREPEND ...) which is not available in CMake version 3.10. It prepends a prefix to each element in a given list. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Export project build directory and AOT library Source: https://github.com/livekit/components-flutter/blob/main/example/windows/flutter/CMakeLists.txt Exports the project's build directory and the AOT library path to the parent scope. ```cmake set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) ``` -------------------------------- ### Add Version Preprocessor Definitions Source: https://github.com/livekit/components-flutter/blob/main/example/windows/runner/CMakeLists.txt Adds preprocessor definitions to the build for various components of the Flutter version. This allows the application to access version information at compile time. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") ``` ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Modern CMake Policy Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Explicitly opts into modern CMake behaviors to avoid warnings with recent CMake versions. This ensures compatibility and adherence to current CMake standards. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Set Executable Binary Name Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Defines the name of the executable file for the application. This can be changed to customize the on-disk name. ```cmake set(BINARY_NAME "example") ``` -------------------------------- ### Define Executable Target Source: https://github.com/livekit/components-flutter/blob/main/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows runner. The binary name should not be changed here to maintain compatibility with `flutter run`. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Apply Standard Compilation Settings Function Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Defines a reusable function to apply common compilation settings to targets. This includes C++ standard, warning levels, and specific definitions. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Build Type Configuration Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already specified. This ensures a consistent build mode for development and testing. Supported modes are Debug, Profile, and Release. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Track Pinning: FocusToggle and RoomContext Source: https://context7.com/livekit/components-flutter/llms.txt Use the FocusToggle widget for a ready-made pinning button, or control pinning manually using RoomContext.pinningTrack and RoomContext.unpinningTrack. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; // Use the ready-made FocusToggle button (requires TrackReferenceContext). class TileWithPin extends StatelessWidget { const TileWithPin({super.key}); @override Widget build(BuildContext context) { return Stack( children: const [ VideoTrackWidget(), Positioned(top: 0, right: 0, child: FocusToggle()), ], ); } } // Or control pinning manually: class PinButton extends StatelessWidget { final String trackSid; const PinButton({super.key, required this.trackSid}); @override Widget build(BuildContext context) { final roomCtx = RoomContext.of(context)!; final isPinned = roomCtx.pinnedTracks.contains(trackSid); return IconButton( icon: Icon(isPinned ? Icons.push_pin : Icons.push_pin_outlined), onPressed: () => isPinned ? roomCtx.unpinningTrack(trackSid) : roomCtx.pinningTrack(trackSid), ); } } ``` -------------------------------- ### Include Generated Plugin Build Rules Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Includes CMake scripts that manage the building of Flutter plugins and their integration into the application. This is essential for plugin functionality. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Include Flutter Managed Directory Source: https://github.com/livekit/components-flutter/blob/main/example/windows/CMakeLists.txt Adds the Flutter managed directory as a subdirectory. This is typically where Flutter's build rules and libraries are located. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Display Track Information with TrackReferenceContext Source: https://context7.com/livekit/components-flutter/llms.txt Use TrackReferenceContext to access and display details about video or audio tracks, such as SID, type, mute status, and screen share status. It also allows toggling a live statistics overlay. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class TrackInfoBadge extends StatelessWidget { const TrackInfoBadge({super.key}); @override Widget build(BuildContext context) { final trackCtx = TrackReferenceContext.of(context)!; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Track SID: ${trackCtx.sid}'), Text('Type: ${trackCtx.isVideo ? "video" : "audio"}'), Text('Muted: ${trackCtx.isMuted}'), Text('Screen share: ${trackCtx.isScreenShare}'), ElevatedButton( onPressed: () { // Toggle live RTP stats overlay trackCtx.showStatistics = !trackCtx.showStatistics; }, child: Text(trackCtx.showStatistics ? 'Hide Stats' : 'Show Stats'), ), if (trackCtx.showStatistics) ...trackCtx.stats.entries.map( (e) => Text('${e.key}: ${e.value}', style: const TextStyle(fontSize: 10)), ), ], ); } } ``` -------------------------------- ### Display Prejoin Lobby Screen in Flutter Source: https://context7.com/livekit/components-flutter/llms.txt Use the Prejoin widget to display a pre-join lobby screen. It renders only when the room is not yet connected and provides options for camera preview, device selection, and joining the room. ```dart import 'package:flutter/material.dart'; import 'package:livekit_components/livekit_components.dart'; class EntryPage extends StatelessWidget { const EntryPage({super.key}); @override Widget build(BuildContext context) { return LivekitRoom( roomContext: RoomContext(), // no auto-connect builder: (context, roomCtx) { return Scaffold( body: roomCtx.connected ? const RoomScreen() : Prejoin( url: 'wss://my-project.livekit.cloud', token: '', onJoinPressed: (roomCtx, url, token) async { await roomCtx.connect(url: url, token: token); }, ), ); }, ); } } ``` -------------------------------- ### Flutter Managed Directory Source: https://github.com/livekit/components-flutter/blob/main/example/linux/CMakeLists.txt Sets the path to the Flutter managed directory, which contains Flutter-specific build artifacts and generated files. This path is relative to the current source directory. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") ```