You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by avorio-dev January 4, 2025
Hello,
I'm having an issue with the home_widget package, specifically with the interactiveCallback function. Once the refresh icon is pressed in my widget, I want it to update the data using the appropriate method in my Flutter class. I don't understand why the event is not triggering. Please, could you provide any suggestions?
Below, there is my code. What I expect is the trigger of backgroundCallback: Anyway, the normal update of elements in my widget is correct. Only the background callback not working
class MyAppHomeWidget : HomeWidgetProvider() {
override fun onReceive(context: Context?, intent: Intent?) {
super.onReceive(context, intent)
}
override fun onUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: IntArray,
widgetData: SharedPreferences
) {
appWidgetIds.forEach { appWidgetId ->
val views = RemoteViews(context.packageName, R.layout.my_app_home_widget).apply {
// Open App on Widget Click
val openAppOnClickIntent =
HomeWidgetLaunchIntent.getActivity(context, MainActivity::class.java)
setOnClickPendingIntent(R.id.widget_container, openAppOnClickIntent)
// Swap Title Text by calling Dart Code in the Background
val refreshDataIntent =
HomeWidgetBackgroundIntent.getBroadcast(
context, Uri.parse("myHomeWidget://updateLocationAndForecast")
)
setOnClickPendingIntent(R.id.refreshDataIcon, refreshDataIntent)
// Update widget data
setTextViewText(
R.id.widgetLocation,
widgetData.getString("widgetLocation", "Somewhere")
)
setTextViewText(
R.id.widgetWeatherCondition,
widgetData.getString("widgetWeatherCondition", "Unknown")
)
setTextViewText(
R.id.widgetTemperature,
widgetData.getString("widgetTemperature", "N/A")
)
setTextViewText(R.id.widgetHumidity, widgetData.getString("widgetHumidity", "N/A"))
setTextViewText(R.id.widgetRainProb, widgetData.getString("widgetRainProb", "N/A"))
setTextViewText(R.id.widgetWind, widgetData.getString("widgetWind", "N/A"))
setTextViewText(
R.id.widgetLastUpdateDate,
widgetData.getString("widgetLastUpdateDate", "N/A") ?: "No Title Set"
)
//setTextViewText(R.id.widgetLastUpdateDate, widgetData.getString("widgetLastUpdateDate", "Unknown"))
}
appWidgetManager.updateAppWidget(appWidgetId, views)
}
}
override fun onEnabled(context: Context) {
// Enter relevant functionality for when the first widget is created
}
override fun onDisabled(context: Context) {
// Enter relevant functionality for when the last widget is disabled
}
}
Dart
class HomeWidgetController {
static const String _classname = 'HomeWidgetController';
/// Called when Doing Background Work initiated from Widget
@pragma("vm:entry-point")
static Future<void> backgroundCallback(Uri? data) async {
AppLogger.info(_classname, 'App Widget call with URI: $data');
if (data?.host == 'updateLocationAndForecast') {
}
}
static Future<void> initialize() async {
HomeWidget.setAppGroupId(GlobalVar.widgetGroupId);
await HomeWidget.registerInteractivityCallback(backgroundCallback);
}
}
the method initialize is called in main.dart as follow:
Discussed in #323
Originally posted by avorio-dev January 4, 2025
Hello,
I'm having an issue with the home_widget package, specifically with the interactiveCallback function. Once the refresh icon is pressed in my widget, I want it to update the data using the appropriate method in my Flutter class. I don't understand why the event is not triggering. Please, could you provide any suggestions?
Below, there is my code. What I expect is the trigger of backgroundCallback: Anyway, the normal update of elements in my widget is correct. Only the background callback not working
Manifest.xml
Kotlin
Dart
the method initialize is called in main.dart as follow:
The text was updated successfully, but these errors were encountered: