From da94e2e0b54e7fa147bdd47f67fa97ec2388f887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asc=C3=AAnio=20Sanderson?= Date: Thu, 1 Jul 2021 22:43:19 -0300 Subject: [PATCH] refactor: removes null checking when possible --- lib/controllers/session_controller.dart | 91 +++++++++---------------- lib/models/agora_channel_data.dart | 36 +++++----- lib/models/agora_connection_data.dart | 4 +- lib/models/agora_event_handlers.dart | 65 +++++++++++------- lib/src/agora_client.dart | 4 +- lib/src/buttons/buttons.dart | 12 ++-- lib/src/layout/floating_layout.dart | 35 ++++------ lib/src/layout/layout.dart | 13 ++-- 8 files changed, 121 insertions(+), 139 deletions(-) diff --git a/lib/controllers/session_controller.dart b/lib/controllers/session_controller.dart index a9ae636..a63da06 100644 --- a/lib/controllers/session_controller.dart +++ b/lib/controllers/session_controller.dart @@ -44,14 +44,13 @@ class SessionController extends ValueNotifier { ); } - void createEvents(AgoraEventHandlers? agoraEventHandlers) async { + void createEvents(AgoraEventHandlers agoraEventHandlers) async { value.engine?.setEventHandler( RtcEngineEventHandler( error: (code) { final info = 'onError: $code'; print(info); - var onErrorFun = agoraEventHandlers?.onError; - if (onErrorFun != null) onErrorFun(code); + agoraEventHandlers.onError(code); }, joinChannelSuccess: (channel, uid, elapsed) { final info = 'onJoinChannel: $channel, uid: $uid'; @@ -66,15 +65,11 @@ class SessionController extends ValueNotifier { clientRole: value.clientRole, ), ); - var joinChannelSuccessFun = agoraEventHandlers?.joinChannelSuccess; - if (joinChannelSuccessFun != null) { - joinChannelSuccessFun(channel, uid, elapsed); - } + agoraEventHandlers.joinChannelSuccess(channel, uid, elapsed); }, leaveChannel: (stats) { _clearUsers(); - var leaveChannelFun = agoraEventHandlers?.leaveChannel; - if (leaveChannelFun != null) leaveChannelFun(stats); + agoraEventHandlers.leaveChannel(stats); }, userJoined: (uid, elapsed) { final info = 'userJoined: $uid'; @@ -84,16 +79,14 @@ class SessionController extends ValueNotifier { uid: uid, ), ); - var userJoinedFun = agoraEventHandlers?.userJoined; - if (userJoinedFun != null) userJoinedFun(uid, elapsed); + agoraEventHandlers.userJoined(uid, elapsed); }, userOffline: (uid, reason) { final info = 'userOffline: $uid , reason: $reason'; print(info); _checkForMaxUser(uid: uid); _removeUser(uid: uid); - var userOfflineFun = agoraEventHandlers?.userOffline; - if (userOfflineFun != null) userOfflineFun(uid, reason); + agoraEventHandlers.userOffline(uid, reason); }, tokenPrivilegeWillExpire: (token) async { await _getToken( @@ -102,11 +95,7 @@ class SessionController extends ValueNotifier { uid: value.connectionData!.uid, ); await value.engine?.renewToken(token); - var tokenPrivilegeWillExpireFun = - agoraEventHandlers?.tokenPrivilegeWillExpire; - if (tokenPrivilegeWillExpireFun != null) { - tokenPrivilegeWillExpireFun(token); - } + agoraEventHandlers.tokenPrivilegeWillExpire(token); }, remoteVideoStateChanged: (uid, state, reason, elapsed) { final String info = @@ -120,11 +109,8 @@ class SessionController extends ValueNotifier { _updateUserVideo(uid: uid, videoDisabled: false); } } - var remoteVideoStateChangedFun = - agoraEventHandlers?.remoteVideoStateChanged; - if (remoteVideoStateChangedFun != null) { - remoteVideoStateChangedFun(uid, state, reason, elapsed); - } + agoraEventHandlers.remoteVideoStateChanged( + uid, state, reason, elapsed); }, remoteAudioStateChanged: (uid, state, reason, elapsed) { final String info = @@ -137,31 +123,20 @@ class SessionController extends ValueNotifier { reason == AudioRemoteStateReason.RemoteUnmuted) { _updateUserAudio(uid: uid, muted: false); } - var remoteAudioStateChangedFun = - agoraEventHandlers?.remoteAudioStateChanged; - if (remoteAudioStateChangedFun != null) { - remoteAudioStateChangedFun(uid, state, reason, elapsed); - } + agoraEventHandlers.remoteAudioStateChanged( + uid, state, reason, elapsed); }, localAudioStateChanged: (state, error) { final String info = "Local audio state changed state: $state and error: $error"; print(info); - var localAudioStateChangedFun = - agoraEventHandlers?.localAudioStateChanged; - if (localAudioStateChangedFun != null) { - localAudioStateChangedFun(state, error); - } + agoraEventHandlers.localAudioStateChanged(state, error); }, localVideoStateChanged: (localVideoState, error) { final String info = "Local audio state changed state: $localVideoState and error: $error"; print(info); - var localVideoStateChangedFun = - agoraEventHandlers?.localVideoStateChanged; - if (localVideoStateChangedFun != null) { - localVideoStateChangedFun(localVideoState, error); - } + agoraEventHandlers.localVideoStateChanged(localVideoState, error); }, activeSpeaker: (uid) { final String info = "Active speaker: $uid"; @@ -173,8 +148,7 @@ class SessionController extends ValueNotifier { } else { print("Active speaker is disabled"); } - var activeSpeakerFun = agoraEventHandlers?.activeSpeaker; - if (activeSpeakerFun != null) activeSpeakerFun(uid); + agoraEventHandlers.activeSpeaker(uid); }, ), ); @@ -182,12 +156,10 @@ class SessionController extends ValueNotifier { /// Function to set all the channel properties. void setChannelProperties(AgoraChannelData agoraChannelData) async { - await value.engine?.setChannelProfile( - agoraChannelData.channelProfile ?? ChannelProfile.Communication); + await value.engine?.setChannelProfile(agoraChannelData.channelProfile); if (agoraChannelData.channelProfile == ChannelProfile.LiveBroadcasting) { - await value.engine?.setClientRole( - agoraChannelData.clientRole ?? ClientRole.Broadcaster); + await value.engine?.setClientRole(agoraChannelData.clientRole); } else { print('You can only set channel profile in case of Live Broadcasting'); } @@ -195,11 +167,11 @@ class SessionController extends ValueNotifier { value = value.copyWith( isActiveSpeakerDisabled: agoraChannelData.isActiveSpeakerDisabled); - await value.engine?.muteAllRemoteVideoStreams( - agoraChannelData.muteAllRemoteVideoStreams ?? false); + await value.engine + ?.muteAllRemoteVideoStreams(agoraChannelData.muteAllRemoteVideoStreams); - await value.engine?.muteAllRemoteAudioStreams( - agoraChannelData.muteAllRemoteAudioStreams ?? false); + await value.engine + ?.muteAllRemoteAudioStreams(agoraChannelData.muteAllRemoteAudioStreams); if (agoraChannelData.setBeautyEffectOptions != null) { value.engine?.setBeautyEffectOptions( @@ -207,7 +179,7 @@ class SessionController extends ValueNotifier { } await value.engine - ?.enableDualStreamMode(agoraChannelData.enableDualStreamMode ?? false); + ?.enableDualStreamMode(agoraChannelData.enableDualStreamMode); if (agoraChannelData.localPublishFallbackOption != null) { await value.engine?.setLocalPublishFallbackOption( @@ -225,13 +197,12 @@ class SessionController extends ValueNotifier { } value.engine?.setCameraAutoFocusFaceModeEnabled( - agoraChannelData.setCameraAutoFocusFaceModeEnabled ?? false); + agoraChannelData.setCameraAutoFocusFaceModeEnabled); - value.engine?.setCameraTorchOn(agoraChannelData.setCameraTorchOn ?? false); + value.engine?.setCameraTorchOn(agoraChannelData.setCameraTorchOn); await value.engine?.setAudioProfile( - agoraChannelData.audioProfile ?? AudioProfile.Default, - agoraChannelData.audioScenario ?? AudioScenario.Default); + agoraChannelData.audioProfile, agoraChannelData.audioScenario); } void joinVideoChannel() async { @@ -248,7 +219,7 @@ class SessionController extends ValueNotifier { value.connectionData!.tempToken ?? value.generatedToken, value.connectionData!.channelName, null, - value.connectionData!.uid ?? 0, + value.connectionData!.uid, ); } @@ -309,10 +280,10 @@ class SessionController extends ValueNotifier { Timer? timer; /// Function to auto hide the button class. - void toggleVisible({int? autoHideButtonTime}) async { + void toggleVisible({int autoHideButtonTime = 5}) async { if (!(value.visible)) { value = value.copyWith(visible: !(value.visible)); - timer = Timer(Duration(seconds: autoHideButtonTime ?? 5), () { + timer = Timer(Duration(seconds: autoHideButtonTime), () { if (!(value.visible)) return; value = value.copyWith(visible: !(value.visible)); }); @@ -375,9 +346,11 @@ class SessionController extends ValueNotifier { _removeUser(uid: newUser.uid); } - Future _getToken( - {String? tokenUrl, String? channelName, int? uid}) async { - uid = uid ?? 0; + Future _getToken({ + String? tokenUrl, + String? channelName, + int uid = 0, + }) async { final response = await http .get(Uri.parse('$tokenUrl/rtc/$channelName/publisher/uid/$uid')); if (response.statusCode == 200) { diff --git a/lib/models/agora_channel_data.dart b/lib/models/agora_channel_data.dart index 4dfc069..f861ccd 100644 --- a/lib/models/agora_channel_data.dart +++ b/lib/models/agora_channel_data.dart @@ -5,7 +5,7 @@ class AgoraChannelData { /// The Agora [RtcEngine] differentiates channel profiles and applies different optimization algorithms accordingly. /// /// You can choose between 3 default channel profiles [ChannelProfile.Communication], [ChannelProfile.LiveBroadcasting] and [ChannelProfile.Game] - final ChannelProfile? channelProfile; + final ChannelProfile channelProfile; /// Sets the role of a user in a live interactive streaming. /// This method applies only when [channelProfile] is set to [ChannelProfile.LiveBroadcasting] @@ -13,7 +13,7 @@ class AgoraChannelData { /// Use this to set the user behaviour inside a channel. A user can choose between a [ClientRole.Audience] or [ClientRole.Broadcaster]. /// - An audience member can only receive the stream. /// - A broadcaster can send and receive the stream. - ClientRole? clientRole; + ClientRole clientRole; /// Each video encoder configuration corresponds to a set of video parameters, including the resolution, frame rate, bitrate, and video orientation. /// @@ -25,7 +25,7 @@ class AgoraChannelData { /// *Parameter* Sets whether to enable/disable the camera auto-face focus function: /// - `true`: Enable the camera auto-face focus function. /// - `false`: (Default) Disable the camera auto-face focus function. - bool? setCameraAutoFocusFaceModeEnabled; + bool setCameraAutoFocusFaceModeEnabled; /// Enables/Disables the dual video stream mode. /// @@ -34,7 +34,7 @@ class AgoraChannelData { /// *Parameter* Sets the stream mode: /// - `true`: Dual-stream mode. /// - `false`: (Default) Single-stream mode. - bool? enableDualStreamMode; + bool enableDualStreamMode; /// Sets the fallback option for the locally published video stream based on the network conditions. /// @@ -60,13 +60,13 @@ class AgoraChannelData { /// Sets the sample rate, bitrate, encoding mode, and the number of channels. /// /// To know more about AudioProfile have a look over here [AudioProfile] - AudioProfile? audioProfile; + AudioProfile audioProfile; /// Sets the audio parameters and application scenarios. /// /// Sets the audio application scenarios. Under different audio scenarios, the device uses different volume tracks, i.e. either the in-call volume or the media volume. S /// To know more about AudioScenario have a look over here [AudioScenario] - AudioScenario? audioScenario; + AudioScenario audioScenario; /// Enhancess the image being streamed on the channel. /// @@ -80,21 +80,21 @@ class AgoraChannelData { /// *Parameter* Enables the camera flash: /// - `true`: Enable the camera flash function. /// - `false`: (Default) Disable the camera flash function. - bool? setCameraTorchOn; + bool setCameraTorchOn; /// Stops/Resumes receiving all remote audio streams. /// /// *Parameter* Determines whether to receive/stop receiving all remote audio streams: /// - `true`: Stop receiving all remote audio streams. /// - `false`: (Default) Receive all remote audio streams. - bool? muteAllRemoteVideoStreams; + bool muteAllRemoteVideoStreams; /// Stops/Resumes receiving all remote video streams. /// /// *Parameter* Determines whether to receive/stop receiving all remote audio streams: /// - `true`: Stop receiving all remote video streams. /// - `false`: (Default) Receive all remote video streams. - bool? muteAllRemoteAudioStreams; + bool muteAllRemoteAudioStreams; /// Active Speaker method automatically pins the active speaker to the main view. By default active speaker is enabled. /// @@ -104,19 +104,19 @@ class AgoraChannelData { final bool isActiveSpeakerDisabled; AgoraChannelData({ - this.channelProfile, - this.clientRole, + this.channelProfile = ChannelProfile.Communication, + this.clientRole = ClientRole.Broadcaster, this.videoEncoderConfiguration, - this.setCameraAutoFocusFaceModeEnabled, - this.enableDualStreamMode, + this.setCameraAutoFocusFaceModeEnabled = false, + this.enableDualStreamMode = false, this.localPublishFallbackOption, this.remoteSubscribeFallbackOption, - this.audioProfile, - this.audioScenario, + this.audioProfile = AudioProfile.Default, + this.audioScenario = AudioScenario.Default, this.setBeautyEffectOptions, - this.setCameraTorchOn, - this.muteAllRemoteAudioStreams, - this.muteAllRemoteVideoStreams, + this.setCameraTorchOn = false, + this.muteAllRemoteAudioStreams = false, + this.muteAllRemoteVideoStreams = false, this.isActiveSpeakerDisabled = false, }); diff --git a/lib/models/agora_connection_data.dart b/lib/models/agora_connection_data.dart index a0d6162..2299925 100644 --- a/lib/models/agora_connection_data.dart +++ b/lib/models/agora_connection_data.dart @@ -8,7 +8,7 @@ class AgoraConnectionData { final String channelName; /// (Optional) The user ID. A 32-bit unsigned integer with a value ranging from 1 to (232-1). This parameter must be unique. If uid is not assigned (or set as 0), the SDK assigns a uid and reports it in the onJoinChannelSuccess callback. - final int? uid; + final int uid; /// (Optional) Link to the deployed token server. The UIKit automatically generates the token after a fixed interval. Have a look at this guide to learn how to set up your [token server](https://github.com/AgoraIO-Community/agora-token-service) final String? tokenUrl; @@ -22,7 +22,7 @@ class AgoraConnectionData { AgoraConnectionData({ required this.appId, required this.channelName, - this.uid, + this.uid = 0, this.tokenUrl, this.tempToken, this.areaCode = AreaCode.GLOB, diff --git a/lib/models/agora_event_handlers.dart b/lib/models/agora_event_handlers.dart index a93c6db..53ab82d 100644 --- a/lib/models/agora_event_handlers.dart +++ b/lib/models/agora_event_handlers.dart @@ -2,56 +2,71 @@ import 'package:agora_rtc_engine/rtc_engine.dart'; class AgoraEventHandlers { /// Occurs when a remote user [ChannelProfile.Communication]/host [ChannelProfile.LiveBroadcasting] joins the channel - Function(int uid, int elapsed)? userJoined; + final Function(int uid, int elapsed) userJoined; /// Occurs when the local user joins a specified channel. - Function(String channel, int uid, int elapsed)? joinChannelSuccess; + final Function(String channel, int uid, int elapsed) joinChannelSuccess; /// Reports an error during SDK runtime - Function(ErrorCode errorCode)? onError; + final Function(ErrorCode errorCode) onError; /// Occurs when a user leaves the channel. - Function(RtcStats stats)? leaveChannel; + final Function(RtcStats stats) leaveChannel; /// Occurs when a remote user [ChannelProfile.Communication]/host [ChannelProfile.LiveBroadcasting] leaves the channel. - Function(int uid, UserOfflineReason reason)? userOffline; + final Function(int uid, UserOfflineReason reason) userOffline; /// Occurs when the token expires in 30 seconds. - Function(String token)? tokenPrivilegeWillExpire; + final Function(String token) tokenPrivilegeWillExpire; /// Occurs when the remote video state changes. - Function(int uid, VideoRemoteState state, VideoRemoteStateReason reason, - int elapsed)? remoteVideoStateChanged; + final Function(int uid, VideoRemoteState state, VideoRemoteStateReason reason, + int elapsed) remoteVideoStateChanged; /// Occurs when the remote audio state changes. - Function(int uid, AudioRemoteState state, AudioRemoteStateReason reason, - int elapsed)? remoteAudioStateChanged; + final Function(int uid, AudioRemoteState state, AudioRemoteStateReason reason, + int elapsed) remoteAudioStateChanged; /// Occurs when the local audio state changes. - Function(AudioLocalState state, AudioLocalError error)? + final Function(AudioLocalState state, AudioLocalError error) localAudioStateChanged; /// Occurs when the local video state changes. - Function(LocalVideoStreamState localVideoState, LocalVideoStreamError error)? + final Function( + LocalVideoStreamState localVideoState, LocalVideoStreamError error) localVideoStateChanged; /// Reports which user is the loudest speaker. - Function(int uid)? activeSpeaker; + final Function(int uid) activeSpeaker; - AgoraEventHandlers({ - this.userJoined, - this.joinChannelSuccess, - this.onError, - this.activeSpeaker, - this.leaveChannel, - this.localAudioStateChanged, - this.localVideoStateChanged, - this.remoteAudioStateChanged, - this.remoteVideoStateChanged, - this.tokenPrivilegeWillExpire, - this.userOffline, + const AgoraEventHandlers({ + required this.userJoined, + required this.joinChannelSuccess, + required this.onError, + required this.activeSpeaker, + required this.leaveChannel, + required this.localAudioStateChanged, + required this.localVideoStateChanged, + required this.remoteAudioStateChanged, + required this.remoteVideoStateChanged, + required this.tokenPrivilegeWillExpire, + required this.userOffline, }); + factory AgoraEventHandlers.empty() => AgoraEventHandlers( + userJoined: (_, __) {}, + joinChannelSuccess: (_, __, ___) {}, + onError: (_) {}, + activeSpeaker: (_) {}, + leaveChannel: (_) {}, + localAudioStateChanged: (_, __) {}, + localVideoStateChanged: (_, __) {}, + remoteAudioStateChanged: (_, __, ___, ____) {}, + remoteVideoStateChanged: (_, __, ___, ____) {}, + tokenPrivilegeWillExpire: (_) {}, + userOffline: (_, __) {}, + ); + AgoraEventHandlers copyWith({ Function(int uid, int elapsed)? userJoined, Function(String channel, int uid, int elapsed)? joinChannelSuccess, diff --git a/lib/src/agora_client.dart b/lib/src/agora_client.dart index fd8d048..fda34bf 100644 --- a/lib/src/agora_client.dart +++ b/lib/src/agora_client.dart @@ -39,7 +39,7 @@ class AgoraClient { agoraConnectionData: agoraConnectionData, enabledPermission: enabledPermission, agoraChannelData: agoraChannelData, - agoraEventHandlers: agoraEventHandlers, + agoraEventHandlers: agoraEventHandlers ?? AgoraEventHandlers.empty(), ); } @@ -47,7 +47,7 @@ class AgoraClient { required AgoraConnectionData agoraConnectionData, required List enabledPermission, AgoraChannelData? agoraChannelData, - AgoraEventHandlers? agoraEventHandlers, + required AgoraEventHandlers agoraEventHandlers, }) async { try { _sessionController.initializeEngine( diff --git a/lib/src/buttons/buttons.dart b/lib/src/buttons/buttons.dart index dde3b37..fe6ca4a 100644 --- a/lib/src/buttons/buttons.dart +++ b/lib/src/buttons/buttons.dart @@ -15,13 +15,13 @@ class AgoraVideoButtons extends StatefulWidget { final bool? autoHideButtons; /// The default auto hide time = 5 seconds - final int? autoHideButtonTime; + final int autoHideButtonTime; /// Adds a vertical padding to the set of button final double? verticalButtonPadding; /// Alignment for the button class - final Alignment? buttonAlignment; + final Alignment buttonAlignment; /// Use this to style the disconnect button as per your liking while still keeping the default functionality. final Widget? disconnectButtonChild; @@ -41,9 +41,9 @@ class AgoraVideoButtons extends StatefulWidget { this.enabledButtons, this.extraButtons, this.autoHideButtons, - this.autoHideButtonTime, + this.autoHideButtonTime = 5, this.verticalButtonPadding, - this.buttonAlignment, + this.buttonAlignment = Alignment.bottomCenter, this.disconnectButtonChild, this.muteButtonChild, this.switchCameraButtonChild, @@ -61,7 +61,7 @@ class _AgoraVideoButtonsState extends State { void initState() { super.initState(); Future.delayed( - Duration(seconds: widget.autoHideButtonTime ?? 5), + Duration(seconds: widget.autoHideButtonTime), () { if (mounted) { setState(() { @@ -91,7 +91,7 @@ class _AgoraVideoButtonsState extends State { Widget toolbar(List? buttonList) { return Container( - alignment: widget.buttonAlignment ?? Alignment.bottomCenter, + alignment: widget.buttonAlignment, padding: widget.verticalButtonPadding == null ? const EdgeInsets.only(bottom: 48) : EdgeInsets.symmetric( diff --git a/lib/src/layout/floating_layout.dart b/lib/src/layout/floating_layout.dart index 4998f60..f7bdc3f 100644 --- a/lib/src/layout/floating_layout.dart +++ b/lib/src/layout/floating_layout.dart @@ -17,13 +17,13 @@ class FloatingLayout extends StatefulWidget { final double? floatingLayoutContainerWidth; /// Padding of the main user or the active speaker in the floating layout. - final EdgeInsets? floatingLayoutMainViewPadding; + final EdgeInsets floatingLayoutMainViewPadding; /// Padding of the secondary user present in the list. - final EdgeInsets? floatingLayoutSubViewPadding; + final EdgeInsets floatingLayoutSubViewPadding; /// Widget that will be displayed when the local or remote user has disabled it's video. - final Widget? disabledVideoWidget; + final Widget disabledVideoWidget; /// Display the camera and microphone status of a user. This feature is only available in the [Layout.floating] final bool? showAVState; @@ -36,9 +36,9 @@ class FloatingLayout extends StatefulWidget { required this.client, this.floatingLayoutContainerHeight, this.floatingLayoutContainerWidth, - this.floatingLayoutMainViewPadding, - this.floatingLayoutSubViewPadding, - this.disabledVideoWidget, + this.floatingLayoutMainViewPadding = const EdgeInsets.fromLTRB(3, 0, 3, 3), + this.floatingLayoutSubViewPadding = const EdgeInsets.fromLTRB(3, 3, 0, 3), + this.disabledVideoWidget = const DisabledVideoWidget(), this.showAVState = false, this.showNumberOfUsers, }) : super(key: key); @@ -82,8 +82,7 @@ class _FloatingLayoutState extends State { .uid ? Padding( key: Key('$index'), - padding: widget.floatingLayoutSubViewPadding ?? - const EdgeInsets.fromLTRB(3, 3, 0, 3), + padding: widget.floatingLayoutSubViewPadding, child: Container( width: widget.floatingLayoutContainerWidth ?? MediaQuery.of(context).size.width / 3, @@ -117,8 +116,8 @@ class _FloatingLayoutState extends State { _getLocalViews()), ], ) - : widget.disabledVideoWidget ?? - DisabledVideoWidget(), + : widget + .disabledVideoWidget, Positioned.fill( child: Align( alignment: @@ -176,8 +175,7 @@ class _FloatingLayoutState extends State { Container( color: Colors.black, ), - widget.disabledVideoWidget ?? - DisabledVideoWidget(), + widget.disabledVideoWidget, Positioned.fill( child: Align( alignment: @@ -316,8 +314,7 @@ class _FloatingLayoutState extends State { widget.client.sessionController.value.localUid ? Expanded( child: Container( - padding: widget.floatingLayoutMainViewPadding ?? - const EdgeInsets.fromLTRB(3, 0, 3, 3), + padding: widget.floatingLayoutMainViewPadding, child: Column( children: [ _videoView(_getRemoteViews(widget.client @@ -328,12 +325,10 @@ class _FloatingLayoutState extends State { ) : Expanded( child: Container( - padding: widget.floatingLayoutMainViewPadding ?? - const EdgeInsets.fromLTRB(3, 0, 3, 3), + padding: widget.floatingLayoutMainViewPadding, child: widget.client.sessionController.value .isLocalVideoDisabled - ? widget.disabledVideoWidget ?? - DisabledVideoWidget() + ? widget.disabledVideoWidget : Stack( children: [ Container( @@ -361,9 +356,7 @@ class _FloatingLayoutState extends State { ? widget.client.sessionController.value.isLocalVideoDisabled ? Column( children: [ - Expanded( - child: widget.disabledVideoWidget ?? - DisabledVideoWidget()) + Expanded(child: widget.disabledVideoWidget), ], ) : Container( diff --git a/lib/src/layout/layout.dart b/lib/src/layout/layout.dart index f362369..67d9ab2 100644 --- a/lib/src/layout/layout.dart +++ b/lib/src/layout/layout.dart @@ -1,6 +1,7 @@ import 'package:agora_uikit/agora_uikit.dart'; import 'package:agora_uikit/src/layout/floating_layout.dart'; import 'package:agora_uikit/src/layout/grid_layout.dart'; +import 'package:agora_uikit/src/layout/widgets/disabled_video_widget.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -18,13 +19,13 @@ class AgoraVideoViewer extends StatefulWidget { final double? floatingLayoutContainerWidth; /// Padding of the main user or the active speaker in the floating layout. - final EdgeInsets? floatingLayoutMainViewPadding; + final EdgeInsets floatingLayoutMainViewPadding; /// Padding of the secondary user present in the list. - final EdgeInsets? floatingLayoutSubViewPadding; + final EdgeInsets floatingLayoutSubViewPadding; /// Widget that will be displayed when the local or remote user has disabled it's video. - final Widget? disabledVideoWidget; + final Widget disabledVideoWidget; /// Display the camera and microphone status of a user. This feature is only available in the [Layout.floating] final bool showAVState; @@ -38,9 +39,9 @@ class AgoraVideoViewer extends StatefulWidget { this.layoutType = Layout.grid, this.floatingLayoutContainerHeight, this.floatingLayoutContainerWidth, - this.floatingLayoutMainViewPadding, - this.floatingLayoutSubViewPadding, - this.disabledVideoWidget, + this.floatingLayoutMainViewPadding = const EdgeInsets.fromLTRB(3, 0, 3, 3), + this.floatingLayoutSubViewPadding = const EdgeInsets.fromLTRB(3, 3, 0, 3), + this.disabledVideoWidget = const DisabledVideoWidget(), this.showAVState = false, this.showNumberOfUsers = false, }) : super(key: key);