Created
December 23, 2020 08:48
-
-
Save ShaiqAhmedkhan/8a5658b2a7365f56d6effd8a33b16612 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:agora_rtc_engine/rtc_engine.dart'; | |
import 'package:permission_handler/permission_handler.dart'; | |
import './video_call.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() => IndexState(); | |
} | |
class IndexState extends State<HomePage> { | |
final _channelController = TextEditingController(); | |
bool _validateError = false; | |
ClientRole _role = ClientRole.Broadcaster; | |
@override | |
void dispose() { | |
_channelController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
automaticallyImplyLeading: false, | |
title: Text('Flutter Video Call Demo'), | |
centerTitle: true, | |
), | |
body: Center( | |
child: Container( | |
padding: const EdgeInsets.symmetric(horizontal: 20), | |
height: 400, | |
child: Column( | |
children: <Widget>[ | |
Row( | |
children: <Widget>[ | |
Expanded( | |
child: TextField( | |
controller: _channelController, | |
decoration: InputDecoration( | |
errorText: | |
_validateError ? 'Channel name is mandatory' : null, | |
border: UnderlineInputBorder( | |
borderSide: BorderSide(width: 1), | |
), | |
hintText: 'Channel name', | |
), | |
)) | |
], | |
), | |
Column( | |
children: [ | |
ListTile( | |
title: Text(ClientRole.Broadcaster.toString()), | |
leading: Radio( | |
value: ClientRole.Broadcaster, | |
groupValue: _role, | |
onChanged: (ClientRole value) { | |
setState(() { | |
_role = value; | |
}); | |
}, | |
), | |
), | |
ListTile( | |
title: Text(ClientRole.Audience.toString()), | |
leading: Radio( | |
value: ClientRole.Audience, | |
groupValue: _role, | |
onChanged: (ClientRole value) { | |
setState(() { | |
_role = value; | |
}); | |
}, | |
), | |
) | |
], | |
), | |
Padding( | |
padding: const EdgeInsets.symmetric(vertical: 20), | |
child: Row( | |
children: <Widget>[ | |
Expanded( | |
child: RaisedButton( | |
onPressed: onJoin, | |
child: Text('Join'), | |
color: Colors.blueAccent, | |
textColor: Colors.white, | |
), | |
) | |
], | |
), | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
Future<void> onJoin() async { | |
// update input validation | |
setState(() { | |
_channelController.text.isEmpty | |
? _validateError = true | |
: _validateError = false; | |
}); | |
if (_channelController.text.isNotEmpty) { | |
await _handleCameraAndMic(Permission.camera); | |
await _handleCameraAndMic(Permission.microphone); | |
await Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (context) => VideoCall( | |
channelName: _channelController.text, | |
role: _role, | |
), | |
), | |
); | |
} | |
} | |
Future<void> _handleCameraAndMic(Permission permission) async { | |
final status = await permission.request(); | |
print(status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment