Source - Web Apps - Permissions

Best Practices

For those choosing to make a PWA like myself and having problems with permissions feel free to use this code! It works wonderfully.

// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:permission_handler/permission_handler.dart';

import 'package:permission_handler_html/permission_handler_html.dart';

Future gethtmlpermissions() async {
  // request web permissions for camera, microphone, gps, photolibrary, notifications
// Requesting permissions for camera, microphone, gps, photolibrary, notifications

  Map<Permission, PermissionStatus> statuses = await [
    Permission.camera,
    Permission.microphone,
    Permission.location,
    Permission.photos,
    Permission.notification
  ].request();

  // Checking if permissions are granted or not

  if (statuses[Permission.camera] == PermissionStatus.granted &&
      statuses[Permission.microphone] == PermissionStatus.granted &&
      statuses[Permission.location] == PermissionStatus.granted &&
      statuses[Permission.photos] == PermissionStatus.granted &&
      statuses[Permission.notification] == PermissionStatus.granted) {
    print('All permissions granted');
  } else {
    print('Some permissions not granted');
  }
}

7
1 reply