I am trying to add video calling functionality to my flutter app and have chosen Agora. Everything seems to work perfect, but the moment I start the video call it keeps loading. Even if I try to get two users to join the same channel, nothing seems to work. I have tried variations of the widget, but nothing.
This is the code I am using.
import 'dart:convert';
import 'package:agora_uikit/agora_uikit.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
class VideoCall extends StatefulWidget {
String channelName = "test";
VideoCall({required this.channelName});
@override
_VideoCallState createState() => _VideoCallState();
}
class _VideoCallState extends State<VideoCall> {
late final AgoraClient _client;
bool _loading = true;
String tempToken = "token";
@override
void initState() {
getToken();
super.initState();
}
Future<void> getToken() async {
String link =
"http://agora-node-tokenserver-1.dianagil2.repl.co/access_token?channelName=${widget.channelName}";
Response _response = await get(Uri.parse(link));
Map data = jsonDecode(_response.body);
setState(() {
tempToken = data["token"];
});
_client = AgoraClient(
agoraConnectionData: AgoraConnectionData(
appId: "a936e47b75744dbf892ff34345001530",
tempToken: tempToken,
channelName: widget.channelName,
),
enabledPermission: [Permission.camera, Permission.microphone]);
Future.delayed(Duration(seconds: 1)).then(
(value) => setState(() => _loading = false),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: _loading
? Center(
child: CircularProgressIndicator(),
)
: Stack(
children: [
AgoraVideoViewer(
client: _client,
),
AgoraVideoButtons(client: _client)
],
),
),
);
}
}
EDIT: You might have some issues in Android Emulator. Try in real device.
You could try this.
Add this in pubspec.yaml
Create a new dart file and paste the below code.
Open the new Page from your desired page: