Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: A bug fix #592

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks

app/.cxx/*
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ android {
defaultConfig {
applicationId "dev.fluttercommunity.workmanager.example"
compileSdk 34
minSdkVersion 19
minSdkVersion flutter.minSdkVersion
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
2 changes: 1 addition & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.4" apply false
id "com.android.application" version '8.8.1' apply false
id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

Expand Down
26 changes: 10 additions & 16 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ const simpleTaskKey = "be.tramckrijte.workmanagerExample.simpleTask";
const rescheduledTaskKey = "be.tramckrijte.workmanagerExample.rescheduledTask";
const failedTaskKey = "be.tramckrijte.workmanagerExample.failedTask";
const simpleDelayedTask = "be.tramckrijte.workmanagerExample.simpleDelayedTask";
const simplePeriodicTask =
"be.tramckrijte.workmanagerExample.simplePeriodicTask";
const simplePeriodic1HourTask =
"be.tramckrijte.workmanagerExample.simplePeriodic1HourTask";
const iOSBackgroundAppRefresh =
"be.tramckrijte.workmanagerExample.iOSBackgroundAppRefresh";
const iOSBackgroundProcessingTask =
"be.tramckrijte.workmanagerExample.iOSBackgroundProcessingTask";
const simplePeriodicTask = "be.tramckrijte.workmanagerExample.simplePeriodicTask";
const simplePeriodic1HourTask = "be.tramckrijte.workmanagerExample.simplePeriodic1HourTask";
const iOSBackgroundAppRefresh = "be.tramckrijte.workmanagerExample.iOSBackgroundAppRefresh";
const iOSBackgroundProcessingTask = "be.tramckrijte.workmanagerExample.iOSBackgroundProcessingTask";

final List<String> allTasks = [
simpleTaskKey,
Expand Down Expand Up @@ -224,7 +220,6 @@ class _MyAppState extends State<MyApp> {
Workmanager().registerPeriodicTask(
simplePeriodic1HourTask,
simplePeriodic1HourTask,
flexInterval: Duration(minutes: 15),
frequency: Duration(hours: 1),
);
}
Expand Down Expand Up @@ -263,7 +258,7 @@ class _MyAppState extends State<MyApp> {
_showNotInitialized();
return;
}
await Workmanager().registerProcessingTask(
await Workmanager().registerOneOffTask(
iOSBackgroundProcessingTask,
iOSBackgroundProcessingTask,
initialDelay: Duration(seconds: 20),
Expand All @@ -276,11 +271,10 @@ class _MyAppState extends State<MyApp> {
child: Text("isscheduled (Android)"),
onPressed: Platform.isAndroid
? () async {
final workInfo =
await Workmanager().isScheduledByUniqueName(
simplePeriodicTask,
);
print('isscheduled = $workInfo');
// final workInfo = await Workmanager().isScheduledByUniqueName(
// simplePeriodicTask,
// );
// print('isscheduled = $workInfo');
}
: null),
SizedBox(height: 8),
Expand Down Expand Up @@ -327,7 +321,7 @@ class _MyAppState extends State<MyApp> {
}

if (Platform.isIOS) {
Workmanager().printScheduledTasks();
// Workmanager().printScheduledTasks();
}

setState(() {});
Expand Down
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ environment:
sdk: ">=2.18.0 <4.0.0"

dependencies:
path_provider:
path_provider:
shared_preferences:
permission_handler:
flutter:
sdk: flutter
workmanager:
workmanager:
path: ../workmanager

dev_dependencies:
integration_test:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.fluttercommunity.workmanager

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.embedding.engine.plugins.activity.ActivityAware
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
import android.content.Context
import android.os.Handler
import android.os.Looper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package dev.fluttercommunity.workmanager
import android.content.Context
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

class WorkmanagerPlugin : FlutterPlugin {
class WorkmanagerPlugin : FlutterPlugin, MethodCallHandler {
private var methodChannel: MethodChannel? = null
private var workmanagerCallHandler: WorkmanagerCallHandler? = null

Expand All @@ -19,7 +22,11 @@ class WorkmanagerPlugin : FlutterPlugin {
) {
workmanagerCallHandler = WorkmanagerCallHandler(context)
methodChannel = MethodChannel(messenger, "be.tramckrijte.workmanager/foreground_channel_work_manager")
methodChannel?.setMethodCallHandler(workmanagerCallHandler)
methodChannel?.setMethodCallHandler(this)
}

override fun onMethodCall(call: MethodCall, result: Result) {
workmanagerCallHandler?.onMethodCall(call, result)
}

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
Expand All @@ -31,4 +38,4 @@ class WorkmanagerPlugin : FlutterPlugin {
methodChannel = null
workmanagerCallHandler = null
}
}
}
2 changes: 1 addition & 1 deletion workmanager/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: workmanager
description: Flutter Workmanager. This plugin allows you to schedule background work on Android and iOS.
version: 0.5.2
version: 0.5.3
homepage: https://github.com/fluttercommunity/flutter_workmanager
repository: https://github.com/fluttercommunity/flutter_workmanager
issue_tracker: https://github.com/fluttercommunity/flutter_workmanager/issues
Expand Down