-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.dart
More file actions
108 lines (93 loc) · 3.26 KB
/
main.dart
File metadata and controls
108 lines (93 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'dart:io';
import 'package:permission_handler/permission_handler.dart';
import 'package:banuba_sdk/banuba_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
final _banubaSdkManager = BanubaSdkManager();
final _epWidget = EffectPlayerWidget(key: null);
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
await _banubaSdkManager.initialize([],
<#"Place Token here"#>,
SeverityLevel.info);
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
// It is required to grant all permissions for the plugin: Camera, Micro, Storage
requestPermissions().then((granted) {
if (granted) {
debugPrint('CameraPage: Thanks! All permissions are granted!');
openCamera();
} else {
debugPrint('CameraPage: WARNING! Not all required permissions are granted!');
// Plugin cannot be used. Handle this state on your app side
SystemNavigator.pop();
}
}).onError((error, stackTrace) {
debugPrint('CameraPage: ERROR! Plugin cannot be used : $error');
// Plugin cannot be used. Handle this state on your app side
SystemNavigator.pop();
});
}
Future<void> openCamera() async {
await _banubaSdkManager.openCamera();
await _banubaSdkManager.attachWidget(_epWidget.banubaId);
await _banubaSdkManager.startPlayer();
await _banubaSdkManager.loadEffect("effects/TrollGrandma", false);
}
@override
Widget build(BuildContext context) {
return MaterialApp(home: _epWidget);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
_banubaSdkManager.startPlayer();
} else {
_banubaSdkManager.stopPlayer();
}
}
}
// This is a sample implementation of requesting permissions.
// It is expected that the user grants all permissions. This solution does not handle the case
// when the user denies access or navigating the user to Settings for granting access.
// Please implement better permissions handling in your project.
Future<bool> requestPermissions() async {
final requiredPermissions = _getPlatformPermissions();
for (var permission in requiredPermissions) {
var ps = await permission.status;
if (!ps.isGranted) {
ps = await permission.request();
if (!ps.isGranted) {
return false;
}
}
}
return true;
}
List<Permission> _getPlatformPermissions() {
if (Platform.isAndroid) {
return [Permission.camera, Permission.microphone/*, Permission.storage*/];
} else if (Platform.isIOS) {
return [Permission.camera, Permission.microphone];
} else {
throw Exception('Platform is not supported!');
}
}