flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

🐞 WorkManager isolate is not inferring List subtype from inputData

Open AdamBridges opened this issue 3 years ago • 0 comments

  • [x] I have read the README
  • [x] I have done the setup for Android
  • [x] I have done the setup for iOS
  • [ ] I have ran the sample app and it does not work there

Version

Technology Version
Workmanager version 0.5.0
Xcode version
Swift version
iOS deployment target

Describe the error The WorkManager isolate does not seem to be inferring the subtype within Lists and instead returns List<dynamic>, which throws an error when trying to pass the inputData into other tasks.

Example Code:

@pragma('vm:entry-point')
void workmanagerHandler() {
   return Workmanager().executeTask((task, inputData) async {
     try {
     debugPrint("Native called background task: $task | inputData: $inputData");

     final types = inputData.entries.map((e) => e.value.runtimeType).toList();
     debugPrint("types = $types");

     await Workmanager().registerOneOffTask(
        "uniqueName",
        "taskName",
        tag: "retryLaterProcessTag",
        existingWorkPolicy: ExistingWorkPolicy.append,
        constraints: Constraints(
            networkType: NetworkType.not_required,
            requiresBatteryNotLow: false,
            requiresCharging: false,
            requiresDeviceIdle: false,
            requiresStorageNotLow: false
        ),
        inputData: inputData, // make sure inputData has a List in it.
    );

     return Future.value(true);
     } catch(e) {
     debugPrint(e);
     }
    });
}

Returns: Exception: argument strings has wrong type. WorkManager supports only int, bool, double, String and their list

Output of flutter doctor -v [√] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.19044.2006], locale en-CA) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.10) [√] Android Studio (version 2021.2) [√] Android Studio (version 2021.3) [√] VS Code (version 1.71.0) [√] Connected device (4 available) [√] HTTP Host Availability

• No issues found!

AdamBridges avatar Sep 28 '22 00:09 AdamBridges