setView to render video onto the same AtomicLiveWidget. You only need to focus on building your UI and interaction logic.
atomic_x_core dependency to your pubspec.yaml, then run flutter pub get.dependencies:atomic_x_core: ^5.3.0
android/app/src/main/AndroidManifest.xml:<uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.RECORD_AUDIO" />
iOS directory and Info.plist in the ios/Runner directory.post_install do |installer|installer.pods_project.targets.each do |target|flutter_additional_ios_build_settings(target)target.build_configurations.each do |config|config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)','PERMISSION_MICROPHONE=1','PERMISSION_CAMERA=1',]endendend
<key>NSCameraUsageDescription</key><string>TUILiveKit needs access to your camera. Video recording will have visuals only after enabling this permission.</string><key>NSMicrophoneUsageDescription</key><string>TUILiveKit needs access to your microphone. Video recording will have audio only after enabling this permission.</string>

LoginStore.shared.login in your project to complete login. This is required before using any AtomicXCore features.LoginStore.shared.login after your app's user account login succeeds, to ensure clear and consistent login logic.import 'package:flutter/material.dart';import 'package:atomic_x_core/atomicxcore.dart';void main() async {WidgetsFlutterBinding.ensureInitialized();final result = await LoginStore.shared.login(sdkAppID: 1400000001, // Replace with your sdkAppIDuserID: "test_001", // Replace with your userIDuserSig: "xxxxxxxxxxx", // Replace with your userSig);if (result.isSuccess) {debugPrint("login success");} else {debugPrint("login failed code: ${result.errorCode}, message: ${result.errorMessage}");}runApp(const MyApp());}
Parameter | Type | Description |
sdkAppId | int | |
userId | string | Unique identifier for the current user. Use only letters, numbers, hyphens, and underscores. Avoid simple IDs like 1, 123, etc., to prevent multi-device login conflicts. |
userSig | string | A ticket for Tencent Cloud authentication. Please note: Development Environment: You can use the local GenerateTestUserSig.genTestSig function to generate a UserSig or generate a temporary UserSig via the UserSig Generation Tool.Production Environment: To prevent key leakage, you must use a server-side method to generate UserSig. For details, see Generating UserSig on the Server. |
startPush to go live. AtomicLiveWidget continuously renders both the local preview and the streaming video—there’s no need to switch between preview and live views.
_isLiveStarted flag to control the visibility of the "Go Live" button.class _YourAnchorPageState extends State<YourAnchorPage> {// Core componentslate final AtomicLiveController _controller;late final AtomicLiveWidget _videoView;final AtomicPusher _pusher = AtomicPusher.shared;// State flag: false = preview; true = livebool _isLiveStarted = false;@overridevoid initState() {super.initState();_controller = AtomicLiveController.create(AtomicLiveViewType.pushView);_videoView = AtomicLiveWidget(controller: _controller);// Bind rendering view; after binding, you see the local preview_pusher.setView(_videoView);// Enable devices on initialization (see next step)_openDevices();}}
DeviceStore.shared.openLocalCamera and DeviceStore.shared.openLocalMicrophone to enable the camera and microphone. AtomicLiveWidget will automatically preview the camera stream, no extra steps needed.void _openDevices() {// 1. Open front camera (true = front)DeviceStore.shared.openLocalCamera(true);// 2. Enable microphoneDeviceStore.shared.openLocalMicrophone();}
AtomicLiveWidget in your page. Preview and live share the same view, no need to switch components.// 3.1 Wrap rendering view componentWidget _buildVideoView() {return Container(color: Colors.black,child: _videoView,);}// 3.2 Compose main view@overrideWidget build(BuildContext context) {return Scaffold(body: Stack(children: [// View layer: preview and live share AtomicLiveWidgetPositioned.fill(child: _buildVideoView(),),// UI layer: Go Live button (only visible during preview)if (!_isLiveStarted)Positioned(bottom: 50, left: 0, right: 0,child: Center(child: ElevatedButton(onPressed: _startLive, // Implement this method in the next stepchild: const Text('Go Live'),),),),],),);}
AtomicPusher.startPush to start streaming.Future<void> _startLive() async {// 1. Configure live room parametersfinal config = PusherInfo(liveID: widget.liveId, // Unique room identifierliveName: "Atomic Live Demo", // Room title);// 2. Start streaming_pusher.startPush(config);debugPrint("Live started successfully");// 3. Update state to hide Go Live buttonsetState(() {_isLiveStarted = true;});}
PusherInfo Parameter DetailsParameter Name | Type| | Attribute | Description |
liveID | String | Required | Unique identifier for the live room. |
liveName | String | Optional | Title of the live room. |
notice | String | Optional | Announcement for the live room. |
metaData | Map | Optional | Custom metadata for the live room. |
isPublicVisible | Boolean | Optional | Whether the room is publicly visible (true: yes, false: no). |
coverURL | String | Optional | Cover image URL for the live room. |
backgroundURL | String | Optional | Cover image URL for the live room. |
categoryList | List | Optional | Background image URL for the live room. |
AtomicPusher.stopPush to stop streaming. The SDK will handle stopping the stream and destroying the room.Future<void> _stopLive() async {// End live_pusher.stopPush();debugPrint("Live ended successfully");// Exit current pageif (mounted) {Navigator.of(context).pop();}}
YourAnchorPage file. You can copy the following code:import 'package:flutter/material.dart';import 'package:atomic_x_core/atomicxcore.dart';class YourAnchorPage extends StatefulWidget {final String liveId;const YourAnchorPage({super.key, required this.liveId});@overrideState<YourAnchorPage> createState() => _YourAnchorPageState();}class _YourAnchorPageState extends State<YourAnchorPage> {late final AtomicLiveController _controller;late final AtomicLiveWidget _videoView;final AtomicPusher _pusher = AtomicPusher.shared;bool _isLiveStarted = false; // Live status flag@overridevoid initState() {super.initState();_controller = AtomicLiveController.create(AtomicLiveViewType.pushView);_videoView = AtomicLiveWidget(controller: _controller);_pusher.setView(_videoView); // Bind rendering view_openDevices(); // Enable devices}void _openDevices() {DeviceStore.shared.openLocalCamera(true);DeviceStore.shared.openLocalMicrophone();}@overrideWidget build(BuildContext context) {return Scaffold(body: Stack(children: [// View layer: preview and live share AtomicLiveWidgetPositioned.fill(child: Container(color: Colors.black,child: _videoView,),),// Go Live buttonif (!_isLiveStarted)Positioned(bottom: 50, left: 0, right: 0,child: Center(child: ElevatedButton(onPressed: _startLive, child: const Text('Go Live')),),),],),);}// Go Live logicvoid _startLive() {final config = PusherInfo(liveID: widget.liveId,liveName: "Test Live",);_pusher.startPush(config);setState(() {_isLiveStarted = true; // Switch UI state});}}

AtomicLiveWidget and use AtomicLiveController and AtomicPlayer to control playback.setView to bind AtomicLiveWidget to AtomicPlayer before calling joinChannel().AtomicPlayer binds to the rendering view via setView, independent of widget mounting. You can call setView before the widget mounts; the binding completes automatically when the view is ready. After joinChannel succeeds, call startPlay to begin playback, or the screen will remain black.import 'package:flutter/material.dart';import 'package:atomic_x_core/atomicxcore.dart';/// YourAudiencePage represents your audience viewing pageclass _YourAudiencePageState extends State<YourAudiencePage> {late final AtomicLiveController _controller;late final AtomicLiveWidget _videoView;final AtomicPlayer _player = AtomicPlayer();bool _isJoining = true;@overridevoid initState() {super.initState();_controller = AtomicLiveController.create(AtomicLiveViewType.playView);_videoView = AtomicLiveWidget(controller: _controller);// Bind rendering view_player.setView(_videoView);// Enter the live room after the first frame is rendered to ensure AtomicLiveWidget is initializedWidgetsBinding.instance.addPostFrameCallback((_) {_joinLive();});}Future<void> _joinLive() async {final result = await _player.joinChannel(widget.liveId);if (result.isSuccess) {debugPrint("joinChannel success");// Playback URL is generated from liveId using livekit://liveid=<liveId>_player.startPlay("livekit://liveid=${widget.liveId}");if (mounted) setState(() => _isJoining = false);} else {debugPrint("joinChannel error: ${result.errorMessage}");}}@overrideWidget build(BuildContext context) {return Scaffold(body: Stack(children: [// Always render; do not remove based on _isJoining, or video will be interrupted_videoView,if (_isJoining)const Center(child: CircularProgressIndicator(color: Colors.white)),],),);}}
AtomicPlayer.setView to bind the rendering view, then call joinChannel to join the live room. After joining, call startPlay to play the current room's stream.import 'package:flutter/material.dart';import 'package:atomic_x_core/atomicxcore.dart';/// YourAudiencePage represents your audience viewing pageclass YourAudiencePage extends StatefulWidget {final String liveId;const YourAudiencePage({super.key, required this.liveId});@overrideState<YourAudiencePage> createState() => _YourAudiencePageState();}class _YourAudiencePageState extends State<YourAudiencePage> {late final AtomicLiveController _controller;late final AtomicLiveWidget _videoView;final AtomicPlayer _player = AtomicPlayer();@overridevoid initState() {super.initState();_controller = AtomicLiveController.create(AtomicLiveViewType.playView);_videoView = AtomicLiveWidget(controller: _controller);// Bind rendering view_player.setView(_videoView);// Join live room_joinLive();}Future<void> _joinLive() async {// Call joinChannel to enter the live room; after success, call startPlay to begin playback// - liveId: same liveId as host broadcastingfinal result = await _player.joinChannel(widget.liveId);if (result.isSuccess) {debugPrint("joinChannel success");_player.startPlay("livekit://liveid=${widget.liveId}");} else {debugPrint("joinChannel error: ${result.errorMessage}");// If join fails, also exit the page// if (mounted) Navigator.of(context).pop();}}@overrideWidget build(BuildContext context) {return Scaffold(body: Stack(children: [_videoView,],),);}}
AtomicPlayer.stopPlay and leaveChannel to exit. The SDK will automatically stop playback and exit the room.import 'package:flutter/material.dart';import 'package:atomic_x_core/atomicxcore.dart';/// YourAudiencePage represents your audience viewing pageclass YourAudiencePage extends StatefulWidget {final String liveId;const YourAudiencePage({super.key, required this.liveId});@overrideState<YourAudiencePage> createState() => _YourAudiencePageState();}class _YourAudiencePageState extends State<YourAudiencePage> {// ... other code ...// Exit liveFuture<void> _leaveLive() async {_player.stopPlay();_player.leaveChannel();debugPrint("leaveLive success");}// ... other code ...}
PlayerListener to listen for events.import 'package:flutter/material.dart';import 'package:atomic_x_core/atomicxcore.dart';/// YourAudiencePage represents your audience viewing pageclass YourAudiencePage extends StatefulWidget {final String liveId;const YourAudiencePage({super.key, required this.liveId});@overrideState<YourAudiencePage> createState() => _YourAudiencePageState();}class _YourAudiencePageState extends State<YourAudiencePage> {late final AtomicLiveController _controller;late final AtomicLiveWidget _videoView;final AtomicPlayer _player = AtomicPlayer();// 1. Define PlayerListener to manage event listeninglate final PlayerListener _playerListener;@overridevoid initState() {super.initState();_controller = AtomicLiveController.create(AtomicLiveViewType.playView);_videoView = AtomicLiveWidget(controller: _controller);_player.setView(_videoView);// 2. Listen for live events_setupLiveEventListener();// 3. Join live room_joinLive();}// 4. Set up event listenervoid _setupLiveEventListener() {_playerListener = PlayerListener(liveEnded: (reason) {// Listen for live end eventdebugPrint("Live ended. reason: ${reason.name}");// Handle exit logic here, e.g., close the current page// if (mounted) Navigator.of(context).pop();},kickedOut: (reason, message) {// Listen for being kicked out of livedebugPrint("Kicked out of live. reason: ${reason.name}, message: $message");// Handle exit logic here// if (mounted) Navigator.of(context).pop();},);_player.addListener(_playerListener);}Future<void> _joinLive() async {final result = await _player.joinChannel(widget.liveId);if (result.isSuccess) {debugPrint("joinChannel success");_player.startPlay("livekit://liveid=${widget.liveId}");} else {debugPrint("joinChannel error: ${result.errorMessage}");}}Future<void> _leaveLive() async {_player.stopPlay();_player.leaveChannel();debugPrint("leaveLive success");}@overridevoid dispose() {// 5. Remove event listener_player.removeListener(_playerListener);super.dispose();}@overrideWidget build(BuildContext context) {return Scaffold(body: Stack(children: [_videoView,],),);}}
Layout Type | Dynamic Grid Layout | Floating Window Layout | Fixed Grid Layout | Fixed Window Layout |
Template ID | 600 | 601 | 800 | 801 |
Description | Default layout, dynamically adjusts grid size based on the number of co-hosts. | Co-host guests are displayed in floating windows. | Fixed number of co-hosts, each guest occupies a fixed grid. | Fixed number of co-hosts, guests are displayed in fixed windows. |
Live Streaming Results | ![]() | ![]() | ![]() | ![]() |
Live Feature | Feature Description | Feature Stores | Implementation Guide |
Audience Audio/Video Co-hosting | Audience can request to take a mic seat and interact with the host via real-time video. | ||
Host Cross-room Co-hosting PK | Hosts from different rooms can connect for interaction or PK. | ||
Add Live Comments Chat | Audience can send and receive real-time text messages in the live room. | ||
Build Gift System | Audience can send virtual gifts to the host, increasing interaction and fun. |
Store/Component | Feature Description | API Documentation |
AtomicPusher | Host streaming: local audio/video capture and preview, start/stop streaming, live room info updates, streaming status/statistics, event callbacks. | |
AtomicPlayer | Audience playback: rendering view binding, join/leave channel, start/stop playback, playback status/statistics, event callbacks. | |
LiveListStore | Live room lifecycle management: create/join/leave/destroy room, query room list, modify live info (name, announcement, etc.), listen for live status (e.g., kicked out, ended). | |
DeviceStore | Audio/video device control: microphone (on/off/volume), camera (on/off/switch/quality), screen sharing, real-time device status monitoring. | |
CoGuestStore | Audience co-host management: co-host requests/invitations/accept/reject, co-host member permissions (microphone/camera), status sync. | |
CoHostStore | Host cross-room co-hosting: supports multiple layout templates (dynamic grid, etc.), initiate/accept/reject co-hosting, co-host interaction management. | |
BattleStore | Host PK battle: initiate PK (set duration/opponent), manage PK status (start/end), sync scores, listen for battle results. | |
GiftStore | Gift interaction: get gift list, send/receive gifts, listen for gift events (including sender, gift details). | |
BarrageStore | Live comments: send text/custom comments, maintain comment list, real-time comment status monitoring. | |
LikeStore | Like interaction: send likes, listen for like events, sync total like count. | |
LiveAudienceStore | Audience management: get real-time audience list (ID/name/avatar), count audience number, listen for audience join/leave events. | |
AudioEffectStore | Audio effects: voice change (child/male), reverb (KTV, etc.), monitor adjustment, switch effects in real time. | |
BaseBeautyStore | Basic beauty: adjust smoothing/whitening/rosiness (0-100 levels), reset beauty state, sync effect parameters. |
setView to bind AtomicLiveWidget to AtomicPusher or AtomicPlayer before calling the go live or watch API.DeviceStore.shared.openLocalCamera(true) to enable the camera?startPlay after joinChannel succeeded? See above for calling startPlay after joining the room.AtomicLiveViewType.playView when creating the controller?AtomicLiveWidget accidentally destroyed or recreated due to setState during room join? Ensure it remains stable in the widget tree.permission_handler plugin to request camera and microphone permissions:import 'package:permission_handler/permission_handler.dart';Future<void> requestPermissions() async {await [Permission.camera,Permission.microphone,].request();}
dispose method, such as removing event listeners:@overridevoid dispose() {_player.removeListener(_playerListener);super.dispose();}
피드백