FakePermissionPlatform class

An in-memory OS for tests: drive the whole permission flow — dialogs included — in a widget test, with no device and no method channel.

final os = FakePermissionPlatform()
  ..whenRequested(Permission.camera, PermissionStatus.permanentlyDenied)
  ..onOpenAppSettings = (os) => os.setStatus(
    Permission.camera,
    PermissionStatus.granted,
  );
final permissions = os.createHandler();

It mimics the OS behaviours the package works around, so tests exercise the same paths real devices do:

  • Android hides permanent denial from status checks. After a request returns permanentlyDenied, status reports denied, as Android does. iOS reports it as is.
  • A permanently denied or restricted permission never prompts. A request returns the current status without consuming a scripted answer.
  • iOS reports location as permanentlyDenied while Location Services are off (setService on Permission.location), and a request then returns at once.
  • iOS reports locationAlways as permanentlyDenied once locationWhenInUse is granted, before the upgrade was ever asked for. A request still shows the upgrade prompt.

An unscripted request is answered granted — the user tapped Allow.

Inheritance

Constructors

FakePermissionPlatform({PlatformInfo info = const PlatformInfo.android(34)})

Properties

appSettingsOpened ↔ int
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
info ↔ PlatformInfo
getter/setter pair
onOpenAppSettings ↔ void Function(FakePermissionPlatform os)?
Runs when the flow opens app settings — change statuses here to act as the user.
getter/setter pair
onOpenServiceSettings ↔ void Function(FakePermissionPlatform os, ServiceSettingsType type)?
getter/setter pair
rationale → Set<Permission>
Permissions for which shouldShowRequestPermissionRationale is true.
final
requestedPermissions → List<Permission>
Every native permission requested so far, flattened.
no setter
requestError ↔ Object?
getter/setter pair
requestErrors → Map<Permission, Object>
Make any request that includes one of these permissions throw its error — as iOS fails a whole request when one permission in it lacks its usage description.
final
requests → List<List<Permission>>
Every platform request, in order — one list per call.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serviceSettingsOpened → List<ServiceSettingsType>
final
settingsOpens ↔ bool
What openAppSettings reports.
getter/setter pair
statusError ↔ Object?
Make the matching call throw, to test error containment.
getter/setter pair

Methods

createHandler({PermissionConfig config = const PermissionConfig(debugLogging: false)}) → BaabaPermissions
A BaabaPermissions wired to this fake, returning from Settings instantly.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openAppSettings() → Future<bool>
Opens this app's page in the Settings app.
override
openServiceSettings(ServiceSettingsType type) → Future<bool>
Opens the system screen where a service is switched on. Returns whether something was opened.
override
platformInfo() → Future<PlatformInfo>
override
rawStatus(Permission p) → PermissionStatus
The stored status, before the Android masking in status.
request(List<Permission> permissions) → Future<Map<Permission, PermissionStatus>>
Requests every permission in permissions in one platform call, which on Android shows them as one flow.
override
serviceStatus(PermissionWithService permission) → Future<ServiceStatus>
override
setService(Permission p, ServiceStatus status) → void
setStatus(Permission p, PermissionStatus status) → void
shouldShowRationale(Permission permission) → Future<bool>
Android's shouldShowRequestPermissionRationale. Always false on iOS.
override
status(Permission permission) → Future<PermissionStatus>
override
toString() → String
A string representation of this object.
inherited
whenRequested(Permission p, PermissionStatus answer, [List<PermissionStatus> more = const []]) → void
Queues the user's answer(s) to the next request(s) for p.

Operators

operator ==(Object other) → bool
The equality operator.
inherited