Skip to content

Commit

Permalink
chore: optimize dart
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Mar 26, 2021
1 parent b583cce commit 1ba9c19
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 76 deletions.
5 changes: 5 additions & 0 deletions example/lib/config/agora.config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const appId = YOUR_APP_ID;
/// Please refer to https://docs.agora.io/en/Agora%20Platform/token
const token = YOUR_TOEKN;

/// Your channel ID
const channelId = YOUR_CHANNEL_ID;

/// Your int user ID
const uid = YOUR_UID;

/// Your string user ID
const stringUid = YOUR_STRING_UID;
1 change: 1 addition & 0 deletions example/lib/examples/advanced/index.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:agora_rtc_engine_example/examples/advanced/multi_channel.dart';

/// Data source for advanced examples
final Advanced = [
{'name': 'Advanced'},
{'name': 'MultiChannel', 'widget': MultiChannel()}
Expand Down
44 changes: 22 additions & 22 deletions example/lib/examples/advanced/multi_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

const channelId0 = 'channel0';
const channelId1 = 'channel1';
const _channelId0 = 'channel0';
const _channelId1 = 'channel1';

/// MultiChannel Example
class MultiChannel extends StatefulWidget {
Expand Down Expand Up @@ -54,7 +54,7 @@ class _State extends State<MultiChannel> {
await [Permission.microphone, Permission.camera].request();
}

widget._channel0 = await RtcChannel.create(channelId0);
widget._channel0 = await RtcChannel.create(_channelId0);
this._addListener(widget._channel0);

await widget._channel0.setClientRole(ClientRole.Broadcaster);
Expand All @@ -67,7 +67,7 @@ class _State extends State<MultiChannel> {
await [Permission.microphone, Permission.camera].request();
}

widget._channel1 = await RtcChannel.create(channelId1);
widget._channel1 = await RtcChannel.create(_channelId1);
this._addListener(widget._channel1);

await widget._channel1.setClientRole(ClientRole.Broadcaster);
Expand All @@ -80,11 +80,11 @@ class _State extends State<MultiChannel> {
channel.setEventHandler(
RtcChannelEventHandler(joinChannelSuccess: (channel, uid, elapsed) {
log('joinChannelSuccess ${channel} ${uid} ${elapsed}');
if (channelId == channelId0) {
if (channelId == _channelId0) {
setState(() {
isJoined0 = true;
});
} else if (channelId == channelId1) {
} else if (channelId == _channelId1) {
setState(() {
isJoined1 = true;
});
Expand All @@ -95,12 +95,12 @@ class _State extends State<MultiChannel> {
log('userOffline ${channel.channelId} $uid $reason');
}, leaveChannel: (stats) {
log('leaveChannel ${channel.channelId} ${stats.toJson()}');
if (channelId == channelId0) {
if (channelId == _channelId0) {
this.setState(() {
isJoined0 = false;
remoteUid0.clear();
});
} else if (channelId == channelId1) {
} else if (channelId == _channelId1) {
this.setState(() {
isJoined1 = false;
remoteUid1.clear();
Expand All @@ -109,21 +109,21 @@ class _State extends State<MultiChannel> {
}, remoteVideoStateChanged: (uid, state, reason, elapsed) {
log('remoteVideoStateChanged ${uid} ${state} ${reason} ${elapsed}');
if (state == VideoRemoteState.Starting) {
if (channelId == channelId0) {
if (channelId == _channelId0) {
this.setState(() {
remoteUid0.add(uid);
});
} else if (channelId == channelId1) {
} else if (channelId == _channelId1) {
this.setState(() {
remoteUid1.add(uid);
});
}
} else if (state == VideoRemoteState.Stopped) {
if (channelId == channelId0) {
if (channelId == _channelId0) {
this.setState(() {
remoteUid0.removeWhere((element) => element == uid);
});
} else if (channelId == channelId1) {
} else if (channelId == _channelId1) {
this.setState(() {
remoteUid1.removeWhere((element) => element == uid);
});
Expand Down Expand Up @@ -168,7 +168,7 @@ class _State extends State<MultiChannel> {
this._joinChannel0();
}
},
child: Text('${isJoined0 ? 'Leave' : 'Join'} $channelId0'),
child: Text('${isJoined0 ? 'Leave' : 'Join'} $_channelId0'),
),
)
],
Expand All @@ -185,7 +185,7 @@ class _State extends State<MultiChannel> {
this._joinChannel1();
}
},
child: Text('${isJoined1 ? 'Leave' : 'Join'} $channelId1'),
child: Text('${isJoined1 ? 'Leave' : 'Join'} $_channelId1'),
),
)
],
Expand All @@ -200,27 +200,27 @@ class _State extends State<MultiChannel> {
children: [
RaisedButton(
onPressed: this._publishChannel0,
child: Text('Publish ${channelId0}'),
child: Text('Publish ${_channelId0}'),
),
RaisedButton(
onPressed: () {
setState(() {
renderChannelId = channelId0;
renderChannelId = _channelId0;
});
},
child: Text('Render ${channelId0}'),
child: Text('Render ${_channelId0}'),
),
RaisedButton(
onPressed: this._publishChannel1,
child: Text('Publish ${channelId1}'),
child: Text('Publish ${_channelId1}'),
),
RaisedButton(
onPressed: () {
setState(() {
renderChannelId = channelId1;
renderChannelId = _channelId1;
});
},
child: Text('Render ${channelId1}'),
child: Text('Render ${_channelId1}'),
),
],
),
Expand All @@ -231,9 +231,9 @@ class _State extends State<MultiChannel> {

_renderVideo() {
List<int> remoteUid = null;
if (renderChannelId == channelId0) {
if (renderChannelId == _channelId0) {
remoteUid = remoteUid0;
} else if (renderChannelId == channelId1) {
} else if (renderChannelId == _channelId1) {
remoteUid = remoteUid1;
}
return Expanded(
Expand Down
1 change: 1 addition & 0 deletions example/lib/examples/basic/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:agora_rtc_engine_example/examples/basic/join_channel_audio.dart'
import 'package:agora_rtc_engine_example/examples/basic/join_channel_video.dart';
import 'package:agora_rtc_engine_example/examples/basic/string_uid.dart';

/// Data source for basic examples
final Basic = [
{'name': 'Basic'},
{'name': 'JoinChannelAudio', 'widget': JoinChannelAudio()},
Expand Down
35 changes: 17 additions & 18 deletions example/lib/examples/basic/join_channel_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,26 @@ class _State extends State<JoinChannelVideo> {
child: Stack(
children: [
RtcLocalView.SurfaceView(),
if (remoteUid != null)
Align(
alignment: Alignment.topLeft,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.of(remoteUid.map(
(e) => GestureDetector(
onTap: this._switchRender,
child: Container(
width: 120,
height: 120,
child: RtcRemoteView.SurfaceView(
uid: e,
),
Align(
alignment: Alignment.topLeft,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: List.of(remoteUid.map(
(e) => GestureDetector(
onTap: this._switchRender,
child: Container(
width: 120,
height: 120,
child: RtcRemoteView.SurfaceView(
uid: e,
),
),
)),
),
),
)),
),
)
),
)
],
),
);
Expand Down
7 changes: 4 additions & 3 deletions lib/agora_rtc_engine_web.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

// In order to *not* need this ignore, consider extracting the "web" version
// of your plugin as a separate package, instead of inlining it in the same
// package as the core of your plugin.
Expand All @@ -11,7 +12,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart';
/// A web implementation of the AgoraRtcEngine plugin.
class AgoraRtcEngineWeb {
static void registerWith(Registrar registrar) {
final MethodChannel channel = MethodChannel(
final channel = MethodChannel(
'agora_rtc_engine',
const StandardMethodCodec(),
registrar.messenger,
Expand All @@ -28,11 +29,11 @@ class AgoraRtcEngineWeb {
switch (call.method) {
case 'getPlatformVersion':
return getPlatformVersion();
break;
default:
throw PlatformException(
code: 'Unimplemented',
details: 'agora_rtc_engine for web doesn\'t implement \'${call.method}\'',
details:
'agora_rtc_engine for web doesn\'t implement \'${call.method}\'',
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rtc_channel.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'src/events.dart' show RtcChannelEventHandler;
export 'src/events.dart' hide RtcEngineEventHandler;
export 'src/rtc_channel.dart' show RtcChannel;
2 changes: 1 addition & 1 deletion lib/rtc_engine.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export 'src/classes.dart';
export 'src/enums.dart';
export 'src/events.dart' show RtcEngineEventHandler;
export 'src/events.dart' hide RtcChannelEventHandler;
export 'src/rtc_engine.dart' show RtcEngine;
export 'src/rtc_engine_extension.dart';
Loading

0 comments on commit 1ba9c19

Please sign in to comment.