notification_sync_kit 0.2.0
notification_sync_kit: ^0.2.0 copied to clipboard
Capture Android notifications, persist them to a local queue, and sync them to your server via HTTP with Bearer token auth and automatic retry. Enriches each notification with GPS speed, location, and [...]
Changelog #
All notable changes to notification_sync_kit will be documented in this file.
The format follows Keep a Changelog, and this project adheres to Semantic Versioning.
0.2.0 — 2026-05-25 #
Breaking changes #
NotificationRecord.rawremoved. The untypedMap<String, dynamic> rawfield has been deleted. Fields previously accessed viaraware now promoted to typed top-level fields (see Added below).- Records are emitted only after removal. The stream no longer emits on
onNotificationPosted; it emits ononNotificationRemovedso every record arrives fully resolved with its interaction type and delay.
Added #
InteractionTypeenum (ignored,dismissed,opened,replied) withtoJson()/fromJson()that serialise to uppercase strings matching the backend contract.fromJsonfalls back toignoredfor unknown ornullvalues.- New
NotificationRecordfields:canReply(bool) — whether the notification had an inline-reply action.haveExtraPicture(bool) — whether the notification contained an image.speedKmph(double?) — vehicle speed in km/h at notification arrival;nullif GPS unavailable.latitude(double?) — device latitude at notification arrival.longitude(double?) — device longitude at notification arrival.interactionType(InteractionType) — what the driver did:OPENED,DISMISSED,REPLIED, orIGNORED. Defaults toignored.interactionDelayMs(int?) — milliseconds between notification arrival and driver action;nullif removal was never observed.
NotificationRecord.copyWith()— immutable update helper; allows updatinghasRemoved,speedKmph,latitude,longitude,interactionType, andinteractionDelayMswhile preserving all other fields.InteractionDetectorservice (lib/src/services/interaction_detector.dart):- Uses Android
UsageStatsManagervia aMethodChannel(notification_sync_kit/usage_stats) to detect whether the driver opened the app after dismissing a notification. - Detection precedence:
IGNORED(delay > 5 min) →OPENED(app foregrounded within 3 s of removal, detected via UsageStats after a 1.5 s settle delay) →REPLIED(heuristic:canReply=true, removed within 15 s, app not opened) →DISMISSED. - Degrades gracefully to
DISMISSEDwhen Usage Access permission is absent. hasPermission(),requestPermission(),detect()public API.- Channel name configurable via constructor (
channelNameparameter) for easier testing.
- Uses Android
NotificationListenerControllerupdates:- Accepts an optional
interactionDetector:named parameter; defaults to a freshInteractionDetector()instance if not supplied. - GPS is sampled (via
geolocator, 3 s timeout, high accuracy) ononNotificationPostedand attached to the record on removal via an internal_pendingmap keyed bypackageName|eventId. - New
dispose()method cancels the source subscription and closes the broadcast stream controller.
- Accepts an optional
NotificationConfig(lib/src/services/notification_config.dart) — persists the server endpoint URL and Bearer token across app restarts usingSharedPreferences. Exposesinit(),endpoint,token,isConfigured,setEndpoint(), andsetToken(). Now exported from the package barrel.SettingsPage(lib/src/ui/settings_page.dart) — Flutter settings screen for configuring the server endpoint and Bearer token, with URL validation and a show/hide toggle for the token field. Now exported from the package barrel.- Structured logging (
lib/src/logging.dart):setupNotificationSyncKitLogging({Level level, bool includeTimestamp})helper for consumers to enable console output with a single call.- Hierarchical loggers on every service:
notification_sync_kit.controller,.detector,.uploader,.sync,.store.
BACKEND_PAYLOAD.md— reference document describing the exact JSON payload sent to the backend, with field descriptions, interaction type definitions, real-world examples, derivable backend metrics, and HTTP request format.NotificationDetailPagenow shows a Driver Context section (speed, location, interaction type, response time, canReply, hasPicture) in place of the removed Raw Data expansion tile.
Dependencies #
- Added
geolocator: ^13.0.0for GPS speed and coordinates. - Added
logging: ^1.2.0for structured per-component logging.
Android setup (required for upgraders) #
- Add
PACKAGE_USAGE_STATSpermission toAndroidManifest.xml. - Implement the
notification_sync_kit/usage_statsMethodChannelinMainActivity.kt(see README for the full snippet).
0.1.0 — 2026-05-12 #
Added #
NotificationRecordmodel with full JSON serialization (toJson,fromJson,encodeList,decodeList) and afromServiceEventfactory.NotificationListenerController— wrapsnotification_listener_serviceand exposes incoming notifications as a typedStream<NotificationRecord>.NotificationQueueStore—SharedPreferences-backed persistent queue withadd,readAll,count,removeById, andremoveByIds.NotificationUploader— HTTP POST with optional Bearer token auth, configurable endpoint, and graceful error handling.NotificationSyncManager— periodic (default 30 s) flush of queued records with automatic removal of successfully uploaded entries and retry of failures.NotificationDetailPage— optional Flutter widget to display a singleNotificationRecordwith normalized and raw JSON views.- Barrel export at
lib/notification_sync_kit.dartfor a single import. - Example app in
example/demonstrating instant-upload + queue-fallback flow.