Skip to content

Instantly share code, notes, and snippets.

@jamesmoore255
Created January 7, 2020 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmoore255/1d13f0c00e79088b63de4d1a961965f2 to your computer and use it in GitHub Desktop.
Save jamesmoore255/1d13f0c00e79088b63de4d1a961965f2 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
typedef void VideoCreatedCallback(VideoController controller);
class TwilioVideoTutorial extends StatefulWidget {
TwilioVideoTutorial({
Key key,
this.twilioToken,
this.onVideoCreated,
}) : super(key: key);
final String twilioToken;
final VideoCreatedCallback onVideoCreated;
@override
_TwilioVideoTutorialState createState() => _TwilioVideoTutorialState();
}
class _TwilioVideoTutorialState extends State<TwilioVideoTutorial> {
VideoController _controller;
@override
void initState() {
super.initState();
_controller = VideoController();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: double.infinity,
width: double.infinity,
child: AndroidView(
viewType: 'twilioVideoPlugin',
onPlatformViewCreated: _onPlatformCreated,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: FloatingActionButton(
heroTag: null,
backgroundColor: Colors.red.shade700,
child: Icon(Icons.call_end, size: 32),
onPressed: () async {
try {
await _controller.hangup();
Navigator.pop(context);
} catch (error) {
print("Error hanging up: ${error.message}");
}
},
),
);
}
void _onPlatformCreated(int id) {
if (_onVideoCreated == null) {
return;
}
_onVideoCreated();
}
void _onVideoCreated() {
_controller.init(widget.twilioToken);
}
}
class VideoController {
MethodChannel _methodChannel = new MethodChannel("twilioVideoPlugin");
Future<void> init(String token) {
assert(token != null);
return _methodChannel.invokeMethod('init', {'token': "tokentoken"});
}
Future<bool> hangup() {
return _methodChannel.invokeMethod('hangup');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment