zego_uikit_signal_plugin 1.0.6 zego_uikit_signal_plugin: ^1.0.6 copied to clipboard
ZegoUIKitSignalPlugin is a low-code plugin collection that provides the signal related function extensions for ZegoUIKit, which helps you to integarte features easier and faster.
// Dart imports:
import 'dart:math' as math;
// Flutter imports:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
// Package imports:
import 'package:zego_uikit_signal_plugin/zego_uikit_signal_plugin.dart';
/// Note that the userID needs to be globally unique,
final String localUserID = math.Random().nextInt(10000).toString();
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(home: CallPage(isVideoCall: true));
}
}
class CallPage extends StatefulWidget {
final bool isVideoCall;
const CallPage({Key? key, required this.isVideoCall}) : super(key: key);
@override
State<CallPage> createState() => _CallPageState();
}
class _CallPageState extends State<CallPage> {
TextEditingController inviteeUsersIDTextCtrl = TextEditingController();
@override
Widget build(BuildContext context) {
return ZegoUIKitPrebuiltCallWithInvitation(
appID: /*input your AppID*/,
appSign: /*input your AppSign*/,
userID: localUserID,
userName: "user_$localUserID",
// we will ask you for config when we need it, you can customize your app with data
requireConfig: (ZegoCallInvitationData data) {
late ZegoUIKitPrebuiltCallConfig config;
if (data.invitees.length > 1) {
/// group call
config = ZegoInvitationType.videoCall == data.type
? ZegoUIKitPrebuiltCallConfig.groupVideoCall()
: ZegoUIKitPrebuiltCallConfig.groupVoiceCall();
} else {
/// one on one call
config = ZegoInvitationType.videoCall == data.type
? ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall()
: ZegoUIKitPrebuiltCallConfig.oneOnOneVoiceCall();
config.onOnlySelfInRoom = () {
Navigator.of(context).pop();
};
}
return config;
},
child: body(context),
);
}
Widget body(BuildContext context) {
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: SafeArea(
child: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Your ID: $localUserID'),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
inviteeUserIDInput(),
const SizedBox(width: 5),
callButton(false),
const SizedBox(width: 5),
callButton(true),
],
),
],
),
),
),
);
}
Widget inviteeUserIDInput() {
return SizedBox(
width: 200,
child: TextFormField(
controller: inviteeUsersIDTextCtrl,
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp('[0-9,]')),
],
decoration: const InputDecoration(
isDense: true,
hintText: "Please Enter Invitees ID",
labelText: "Invitees ID, Separate ids by ','",
),
),
);
}
Widget callButton(bool isVideoCall) {
return ValueListenableBuilder<TextEditingValue>(
valueListenable: inviteeUsersIDTextCtrl,
builder: (context, inviteeUserID, _) {
var invitees = getInvitesFromTextCtrl(inviteeUsersIDTextCtrl.text);
return ZegoSendCallInvitationButton(
isVideoCall: isVideoCall,
invitees: invitees,
iconSize: const Size(40, 40),
buttonSize: const Size(50, 50),
);
},
);
}
List<ZegoUIKitUser> getInvitesFromTextCtrl(String textCtrlText) {
List<ZegoUIKitUser> invitees = [];
var inviteeIDs = textCtrlText.trim().replaceAll(',', '');
inviteeIDs.split(",").forEach((inviteeUserID) {
invitees.add(ZegoUIKitUser(
id: inviteeUserID,
name: 'user_$inviteeUserID',
));
});
return invitees;
}
}