Implementing Video Call Using ZegoCloud
1. Main.dart import 'package:flutter/material.dart'; import 'package:zego/Homepage.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home:HomePage(), ); } } 2. HomePage.dart
import ‘package:flutter/material.dart’;
import ‘package:zego/videocallpage.dart’;
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘ZEGOCLOUD Demo’),
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Generate random userID and userName
String userID = generateRandomID();
String userName = generateRandomUserName();
String callID = ‘call123’; // Keep callID constant for the same session
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ZegoVideoCallPage(
userID: userID,
userName: userName,
callID: callID,
),
),
);
},
child: Text(‘Start Video Call’),
),
),
);
}
// Generate random userID
String generateRandomID() {
var random = Random();
int randomNumber = random.nextInt(1000); // Generate a random number between 0 and 999
return ‘user_$randomNumber’; // Generate userID in format ‘user_<number>’
}
// Generate random userName
String generateRandomUserName() {
var random = Random();
List<String> names = [‘Sam’, ‘Alex’, ‘Chris’, ‘Taylor’, ‘Jordan’, ‘Morgan’];
return names[random.nextInt(names.length)]; // Randomly select a name from the list
}
}
import 'package:flutter/material.dart'; import 'package:zego_uikit_prebuilt_call/zego_uikit_prebuilt_call.dart'; class ZegoVideoCallPage extends StatelessWidget { final String userID; final String userName; final String callID; ZegoVideoCallPage({ required this.userID, required this.userName, required this.callID, }); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('ZEGOCLOUD Video Call'), ), body: ZegoUIKitPrebuiltCall( appID: 190523610, // Replace with your ZEGOCLOUD App ID appSign: '552c487fc21bc631a90572f87ed36fd7207273d458900acb46bbedd9db1e1f22', // Replace with your ZEGOCLOUD App Sign userID: userID, userName: userName, callID: callID, config: ZegoUIKitPrebuiltCallConfig.groupVideoCall(), ), ); } }
hey there and thank you for your information ?I抳e certainly picked up anything new from right here. I did however expertise a few technical points using this web site, since I experienced to reload the web site a lot of times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I am complaining, but slow loading instances times will often affect your placement in google and could damage your quality score if advertising and marketing with Adwords. Well I抦 adding this RSS to my email and can look out for much more of your respective fascinating content. Make sure you update this again very soon..