Skip to content

Conversation

ened
Copy link
Collaborator

@ened ened commented Aug 5, 2025

Summary

  • Fix NullPointerException in BackgroundWorker that causes app crashes
  • Add proper null safety handling for dart task retrieval
  • Improve error reporting and graceful failure handling

Changes

  • Remove non-null assertion operator (!!) from dartTask property getter
  • Add null checks in all methods that access dartTask
  • Each null check includes proper error reporting via WorkmanagerDebug.onExceptionEncountered
  • Graceful failure with Result.failure() when dart task is null

Root Cause

The issue was caused by renaming the DART_TASK_KEY in a previous commit, which broke compatibility with existing cached worker data. Apps would crash until users cleared cache or reinstalled.

Credit

This fix is based on the excellent work and analysis by @ColinSchmale in PR #635. Thank you for identifying the issue and providing the solution!

Testing

  • ✅ All pre-commit checks passed
  • ✅ Dart analyze - no issues
  • ✅ All unit tests passing
  • ✅ Android and iOS example apps build successfully
  • ✅ Native Android tests passing

Closes #635

Co-authored-by: ColinSchmale colin@schmale.dev

ened added 5 commits August 1, 2025 07:32
 - workmanager_apple@0.9.1
 - workmanager@0.9.0+1
- Remove invalid 'processing' value from UIBackgroundModes
- Add clarification that BGTaskScheduler doesn't require UIBackgroundModes
- Link to Apple's official UIBackgroundModes documentation
- Update workmanager version to 0.9.0 in installation instructions

Fixes #633
- Replace Xcode Help link with Apple's Configuration Guide
- Add link to UIBackgroundModes property list documentation
- Provide both practical configuration and technical reference links

Fixes #633
- Remove non-null assertion operator (!!) from dartTask property
- Add null checks in all methods that use dartTask
- Handle null dart task gracefully with proper error reporting
- Fixes crash when DART_TASK_KEY is missing from worker input data

Fixes #635
Copy link

docs-page bot commented Aug 5, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/fluttercommunity/flutter_workmanager~636

Documentation is deployed and generated using docs.page.

@ened ened merged commit d34763d into main Aug 6, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant