flutter_system_events 0.3.0 copy "flutter_system_events: ^0.3.0" to clipboard
flutter_system_events: ^0.3.0 copied to clipboard

A Flutter plugin for listening to keyboard, lifecycle, network, memory, and battery events on Android and iOS.

flutter_system_events #

A small Flutter plugin for listening to system events with one API.

Version 0.3.0 focuses on Android and iOS:

  • Keyboard show / hide / height
  • App lifecycle changes
  • Network status changes
  • Memory warnings
  • Battery level and charging state

Other platforms currently expose a no-op implementation.

Installation #

dependencies:
  flutter_system_events: ^0.3.0

Usage #

Initialize once, then listen to the event stream.

import 'dart:async';

import 'package:flutter_system_events/flutter_system_events.dart';

StreamSubscription<SystemEvent>? subscription;

Future<void> startSystemEvents() async {
  subscription = SystemEvents.events.listen((event) {
    switch (event) {
      case KeyboardEvent(:final visible, :final height):
        print('keyboard visible=$visible height=$height');
      case LifecycleEvent(:final state):
        print('lifecycle ${state.name}');
      case NetworkEvent(:final online, :final networkType):
        print('network online=$online type=${networkType.name}');
      case MemoryEvent(:final state, :final level):
        print('memory state=${state.name} level=$level');
      case BatteryEvent(:final level, :final charging, :final state):
        print('battery level=$level charging=$charging state=${state.name}');
    }
  });

  await SystemEvents.initialize();
}

Future<void> stopSystemEvents() async {
  await subscription?.cancel();
  await SystemEvents.dispose();
}

By default, initialize() starts keyboard, lifecycle, network, and memory events. Enable only the events you need with a config:

await SystemEvents.initialize(
  config: const SystemEventsConfig(
    network: NetworkConfig(),
    battery: BatteryConfig(),
  ),
);

Events #

KeyboardEvent #

Emitted when the software keyboard visibility changes.

KeyboardEvent(
  visible: true,
  height: 320,
)

Fields:

  • visible: whether the keyboard is visible
  • height: keyboard height in logical pixels

LifecycleEvent #

Emitted when the app lifecycle changes.

LifecycleEvent(
  state: LifecycleState.resumed,
)

States:

  • resumed
  • inactive
  • paused
  • detached

NetworkEvent #

Emitted when the network status changes.

NetworkEvent(
  online: true,
  networkType: NetworkType.wifi,
)

Types:

  • wifi
  • cellular
  • ethernet
  • other
  • none

MemoryEvent #

Emitted when the operating system reports memory pressure.

MemoryEvent(
  state: MemoryState.warning,
  level: 0,
)

States:

  • warning
  • low
  • trim

BatteryEvent #

Emitted when battery level or charging state changes.

BatteryEvent(
  level: 80,
  charging: true,
  state: BatteryState.charging,
)

States:

  • charging
  • discharging
  • full
  • unknown

Platform support #

Event Android iOS macOS Windows Linux Web
Keyboard Yes Yes No-op No-op No-op No-op
Lifecycle Yes Yes No-op No-op No-op No-op
Network Yes Yes No-op No-op No-op No-op
Memory Yes Yes No-op No-op No-op No-op
Battery Yes Yes No-op No-op No-op No-op

Example #

Run the example app and open each event page:

cd example
flutter run

The example includes separate pages for:

  • Keyboard
  • Lifecycle
  • Network
  • Memory
  • Battery

Each page shows the latest event value at the top and provides a simple way to trigger or manually verify the event.

1
likes
0
points
630
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for listening to keyboard, lifecycle, network, memory, and battery events on Android and iOS.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface

More

Packages that depend on flutter_system_events

Packages that implement flutter_system_events