requestPermissions method

Future<bool> requestPermissions (
  1. {bool force: false}
)

Opens an OS settings page

Returns true if:

  • OS is iOS, or
  • permission has already been given, or
  • the settings screen has not been opened by this app before, or
  • opening the screen this time is forced

Returns false if:

  • OS is Android, and
  • permission has not been given by the user, and
  • the settings screen has been opened by this app before

Implementation

Future<bool> requestPermissions({bool force = false}) async {
  if (Platform.isIOS) return true;

  final directory = await getApplicationDocumentsDirectory();
  final file = File('${directory.path}/com.gomes.nowplaying');
  if (!force && await file.exists()) return false;

  file.create();
  await _channel.invokeMethod<bool>('requestPermissions');
  return true;
}