app_blocker 2.0.1 copy "app_blocker: ^2.0.1" to clipboard
app_blocker: ^2.0.1 copied to clipboard

Cross-platform app blocking plugin for Flutter. Block apps with custom block screen (Android) and Screen Time Shield (iOS). Supports scheduling and profiles.

app_blocker #

pub package license

A Flutter plugin to block apps on Android and iOS.

  • Android: AccessibilityService + customizable block screen to detect and block apps
  • iOS: Screen Time API
    • FamilyControls — request user authorization to manage Screen Time
    • ManagedSettings — apply shield restrictions on selected apps (required for blocking specific apps, not needed for blockAll())

Supported Functions #

Permissions & capabilities

  • checkPermission() — Check if required permissions are granted
  • requestPermission() — Request permissions from user
  • getCapabilities() — Check which features are available on the current platform

App discovery

  • getApps() — List installed apps (Android) or show FamilyActivityPicker (iOS)

Blocking

  • blockApps(List<String>) — Block specific apps
  • blockAll() — Block all apps
  • unblockApps(List<String>) — Unblock specific apps
  • unblockAll() — Unblock all apps
  • getBlockedApps() — List currently blocked app identifiers
  • getAppStatus(String) — Get block status of a specific app
  • setBlockScreenConfig(BlockScreenConfig) — Customize the block screen (Android only)
  • getBlockScreenConfig() — Get current block screen configuration (Android only)

Schedules (Android only)

  • addSchedule(BlockSchedule) — Add a time-based blocking schedule
  • updateSchedule(BlockSchedule) — Update an existing schedule
  • removeSchedule(String) — Remove a schedule
  • getSchedules() — List all schedules
  • enableSchedule(String) — Enable a schedule
  • disableSchedule(String) — Disable a schedule without removing it

Profiles

  • createProfile(BlockProfile) — Create a profile grouping apps to block together
  • updateProfile(BlockProfile) — Update an existing profile
  • deleteProfile(String) — Delete a profile
  • getProfiles() — List all profiles
  • activateProfile(String) — Activate a profile (blocks its apps)
  • deactivateProfile(String) — Deactivate a profile
  • getActiveProfile() — Get the currently active profile

Events

  • onBlockEvent — Stream of block/unblock/schedule events

Platform Support #

Feature Android iOS
Block / Unblock apps
Block all apps
Get installed apps -
Custom block screen -
Screen Time Shield -
Schedules -
Profiles
Block events stream
Boot persistence

Installation #

dependencies:
  app_blocker: ^2.0.0

Setup #

Android #

Minimum SDK: 24 (Android 7.0)

No additional setup required. The plugin automatically adds these permissions:

  • SCHEDULE_EXACT_ALARM — Time-based blocking (requires requestPermission(), might get auto-granted on Android 12 & 13 (source))
  • QUERY_ALL_PACKAGES — List installed apps
  • RECEIVE_BOOT_COMPLETED — Restore schedules after reboot

During runtime, by calling requestPermission(), the user will be prompted to grant:

  • SCHEDULE_EXACT_ALARM (if not auto-granted)
  • Accessibility Service permission (opens system settings)

iOS #

Minimum iOS: 16.0

  1. Open ios/Runner.xcworkspace in Xcode
  2. Runner target > Signing & Capabilities > add Family Controls
  3. Set deployment target in ios/Podfile:
platform :ios, '16.0'

Usage #

import 'package:app_blocker/app_blocker.dart';

final blocker = AppBlocker.instance;

Permission #

// Check permission status
final status = await blocker.checkPermission();
// Returns: BlockerPermissionStatus.granted / .denied / .restricted

// Request permission (opens system settings on Android, shows dialog on iOS)
// must be called multiple times on Android until all permissions are granted
await blocker.requestPermission();

Get Apps & Block #

Android:

// Get all installed apps (returns list with appName, packageName, icon)
final apps = await blocker.getApps();

// Block using package names
await blocker.blockApps(apps.map((a) => a.packageName).toList());

iOS:

// Opens FamilyActivityPicker — user selects apps → automatically blocked
await blocker.getApps();

Common:

await blocker.blockAll();
await blocker.unblockAll();
final blocked = await blocker.getBlockedApps();

Block Screen Config (Android only) #

await blocker.setBlockScreenConfig(
  const BlockScreenConfig(
    title: 'Stay Focused!',
    subtitle: 'This app is blocked',
    message: 'Get back to work.',
    backgroundColor: Color(0xDD000000),
  ),
);
// iOS uses the system Screen Time Shield automatically

Schedules (Android only) #

// Add a schedule
await blocker.addSchedule(BlockSchedule(
  id: 'work-hours',
  name: 'Work Hours',
  appIdentifiers: ['com.instagram.android'],
  weekdays: [1, 2, 3, 4, 5], // Mon-Fri (ISO 8601)
  startTime: const TimeOfDay(hour: 9, minute: 0),
  endTime: const TimeOfDay(hour: 17, minute: 0),
));

await blocker.enableSchedule('work-hours');
await blocker.disableSchedule('work-hours');
await blocker.removeSchedule('work-hours');
final schedules = await blocker.getSchedules();

Note: Scheduling is not supported on iOS (canSchedule returns false). iOS lacks the background execution mechanism needed to enforce time-based blocking reliably without the DeviceActivity framework (not yet integrated).

Profiles #

// Create a profile grouping apps to block together
await blocker.createProfile(BlockProfile(
  id: 'social-media',
  name: 'Social Media',
  appIdentifiers: ['com.instagram.android', 'com.twitter.android'],
));

// Activate (blocks the profile's apps); deactivates any previously active profile
await blocker.activateProfile('social-media');
await blocker.deactivateProfile('social-media');

final profiles = await blocker.getProfiles();
final active = await blocker.getActiveProfile(); // null if none active

Block Events #

blocker.onBlockEvent.listen((event) {
  print('${event.type}: ${event.packageName}');
});
// Event types: blocked, unblocked, attemptedAccess,
//              scheduleActivated, scheduleDeactivated

Capabilities #

// Check what features are available on current platform
final caps = await blocker.getCapabilities();

Example #

See the example app for a complete working demo.

License #

MIT — see LICENSE.

7
likes
0
points
363
downloads

Publisher

unverified uploader

Weekly Downloads

Cross-platform app blocking plugin for Flutter. Block apps with custom block screen (Android) and Screen Time Shield (iOS). Supports scheduling and profiles.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on app_blocker

Packages that implement app_blocker