requestPermissions method
Requests necessary permissions from the user.
Returns a map with 'granted' (bool) and 'message' (String) keys. This should be called before attempting to check attendance if permissions are not already granted.
Implementation
@override
Future<Map<String, dynamic>> requestPermissions() async {
try {
final result = await methodChannel.invokeMethod('requestPermissions');
if (result == null) {
return {'granted': false, 'message': 'No response from platform'};
}
// Safely convert the result to Map<String, dynamic>
final Map<String, dynamic> convertedResult = {};
if (result is Map) {
result.forEach((key, value) {
if (key is String) {
convertedResult[key] = value;
}
});
}
return convertedResult.isNotEmpty
? convertedResult
: {'granted': false, 'message': 'Invalid response format'};
} on PlatformException catch (e) {
return {'granted': false, 'message': 'Platform error: ${e.message}'};
} catch (e) {
return {'granted': false, 'message': 'Unexpected error: $e'};
}
}