-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.dart
147 lines (131 loc) · 4.31 KB
/
main.dart
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import 'dart:async';
import 'dart:io';
import 'package:banuba_sdk_example/page_camera.dart';
import 'package:banuba_sdk_example/page_image.dart';
import 'package:banuba_sdk_example/page_touchup.dart';
import 'package:banuba_sdk_example/page_arcloud.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:fluttertoast/fluttertoast.dart';
const banubaToken = <#"Place Token here"#>
enum EntryPage { camera, image, touchUp, arCloud }
void main() {
runApp(const MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
final buttonStyle = ElevatedButton.styleFrom(
shape: const StadiumBorder(),
fixedSize: Size(MediaQuery.of(context).size.width / 2.0, 50),
);
Text textWidget(String text) {
return Text(
text.toUpperCase(),
style: const TextStyle(fontSize: 13.0),
);
}
return Scaffold(
appBar: AppBar(
title: const Text('Face AR Flutter Sample'),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
style: buttonStyle,
onPressed: () => _navigateToPage(EntryPage.camera),
child: textWidget('Open Camera'),
),
SizedBox.fromSize(size: const Size.fromHeight(20.0)),
ElevatedButton(
style: buttonStyle,
onPressed: () => _navigateToPage(EntryPage.image),
child: textWidget('Image processing'),
),
SizedBox.fromSize(size: const Size.fromHeight(20.0)),
ElevatedButton(
style: buttonStyle,
onPressed: () => _navigateToPage(EntryPage.touchUp),
child: textWidget('Touch Up features'),
),
SizedBox.fromSize(size: const Size.fromHeight(20.0)),
ElevatedButton(
style: buttonStyle,
onPressed: () => _navigateToPage(EntryPage.arCloud),
child: textWidget('Load from AR Cloud'),
),
],
),
);
}
void _navigateToPage(EntryPage entryPage) {
switch (entryPage) {
case EntryPage.camera:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const CameraPage()),
);
return;
case EntryPage.image:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const ImagePage()),
);
return;
case EntryPage.touchUp:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const TouchUpPage()),
);
return;
case EntryPage.arCloud:
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const ARCloudPage()),
);
return;
}
}
}
Future<String> generateFilePath(String prefix, String fileExt) async {
final directory = await getTemporaryDirectory();
final filename = '$prefix${DateTime.now().millisecondsSinceEpoch}$fileExt';
return '${directory.path}${Platform.pathSeparator}$filename';
}
// 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() {
return [Permission.camera, Permission.microphone];
}
void showToastMessage(String message) {
Fluttertoast.showToast(
msg: message,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
textColor: Colors.white,
fontSize: 14.0);
}