瀏覽代碼

feat: handle camera permissions

Léo Salé 3 年之前
父節點
當前提交
8b1b426194

+ 1 - 0
app/android/app/src/main/AndroidManifest.xml

@@ -3,6 +3,7 @@
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE"/>
+   <uses-permission android:name="android.permission.CAMERA" />
    <application
         android:label="PhysiGo"
         android:name="${applicationName}"

+ 2 - 0
app/ios/Runner/Info.plist

@@ -26,6 +26,8 @@
 	<true/>
 	<key>NSLocationWhenInUseUsageDescription</key>
 	<string>Physigo needs access to location when open.</string>
+	<key>NSCameraUsageDescription</key>
+	<string>To verify exercise's execution, please grant camera access</string>
 	<key>UILaunchStoryboardName</key>
 	<string>LaunchScreen</string>
 	<key>UIMainStoryboardFile</key>

+ 24 - 0
app/lib/exercises/exercises_validation/exercise_validation_page.dart

@@ -0,0 +1,24 @@
+import 'package:flutter/material.dart';
+import 'package:physigo/exercises/exercises_validation/utils/permissions_utils.dart';
+
+class ExerciseValidationPage extends StatelessWidget {
+  const ExerciseValidationPage({Key? key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      body: FutureBuilder<void>(
+        future: PermissionUtils.determineCameraPermission(),
+        builder: ((context, snapshot) {
+          if (snapshot.connectionState == ConnectionState.waiting) {
+            return const Center(child: CircularProgressIndicator());
+          }
+          if (snapshot.hasError) {
+            return Center(child: Text(snapshot.error.toString()));
+          }
+          return Container();
+        }),
+      ),
+    );
+  }
+}

+ 16 - 0
app/lib/exercises/exercises_validation/utils/permissions_utils.dart

@@ -0,0 +1,16 @@
+import 'package:permission_handler/permission_handler.dart';
+
+class PermissionUtils {
+  static Future<void> determineCameraPermission() async {
+    var permission = await Permission.camera.status;
+    if (permission.isDenied) {
+      permission = await Permission.camera.request();
+      if (permission.isDenied) {
+        return Future.error('Camera permission is denied');
+      }
+    }
+    if (permission.isPermanentlyDenied) {
+      return Future.error('Camera permission is permanently denied, we cannot request permissions');
+    }
+  }
+}

+ 29 - 12
app/lib/main.dart

@@ -4,6 +4,7 @@ import 'package:latlong2/latlong.dart';
 import 'navigation/navigation_page.dart';
 
 import 'firebase_options.dart';
+import 'package:physigo/exercises/exercises_validation/exercise_validation_page.dart';
 
 void main() async {
   WidgetsFlutterBinding.ensureInitialized();
@@ -34,19 +35,35 @@ class HomePage extends StatelessWidget {
   Widget build(BuildContext context) {
     return Scaffold(
       body: Center(
-        child: TextButton(
-            onPressed: () {
-              Navigator.push(
-                context,
-                MaterialPageRoute(
-                  // Example on how to use NavigationPage
-                  builder: (context) => NavigationPage(
-                    destination: LatLng(51.78036111980833, 19.451262207821234),
+        child: Column(
+          children: [
+            TextButton(
+              onPressed: () {
+                Navigator.push(
+                  context,
+                  MaterialPageRoute(
+                    // Example on how to use NavigationPage
+                    builder: (context) => NavigationPage(
+                      destination: LatLng(51.78036111980833, 19.451262207821234),
+                    ),
                   ),
-                ),
-              );
-            },
-            child: const Text('Navigation')),
+                );
+              },
+              child: const Text('Navigation'),
+            ),
+            TextButton(
+              onPressed: () {
+                Navigator.push(
+                  context,
+                  MaterialPageRoute(
+                    builder: (context) => ExerciseValidationPage(),
+                  ),
+                );
+              },
+              child: const Text('Exercise Validation'),
+            ),
+          ],
+        ),
       ),
     );
   }

+ 35 - 0
app/pubspec.lock

@@ -247,6 +247,41 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.8.0"
+  permission_handler:
+    dependency: "direct main"
+    description:
+      name: permission_handler
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "9.2.0"
+  permission_handler_android:
+    dependency: transitive
+    description:
+      name: permission_handler_android
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "9.0.2+1"
+  permission_handler_apple:
+    dependency: transitive
+    description:
+      name: permission_handler_apple
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "9.0.4"
+  permission_handler_platform_interface:
+    dependency: transitive
+    description:
+      name: permission_handler_platform_interface
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "3.7.0"
+  permission_handler_windows:
+    dependency: transitive
+    description:
+      name: permission_handler_windows
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.1.0"
   plugin_platform_interface:
     dependency: transitive
     description:

+ 1 - 0
app/pubspec.yaml

@@ -38,6 +38,7 @@ dependencies:
   http: ^0.13.4
   flutter_map: ^0.14.0
   flutter_map_location_marker: ^3.1.0
+  permission_handler: ^9.2.0
 
 dev_dependencies:
   flutter_test: