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

Configurable Widget #250

Open
dario-digregorio opened this issue Apr 12, 2024 · 2 comments
Open

Configurable Widget #250

dario-digregorio opened this issue Apr 12, 2024 · 2 comments

Comments

@dario-digregorio
Copy link

Hi,
I am currently struggling a bit to implement a configurable Widget for Android.
First of all I use the Glance Implementation for the normal widget and assigned a Configuration Activity and XML View for the configuration screen.
After configuring the Widget I want to save the data in the SharedPreferences and access that in my Flutter Application where I use the value inside my app to call other functions.

I would expect a method inside HomeWidgetPlugin with a saveWidgetData method to save the data with the corresponding Widget Id. I then can access the data with the right key from my Flutter Application.
The same goes for iOS which I did not tried out yet.

I would create a PR if there is a need for such a feature or to add more information to the README.

@dario-digregorio
Copy link
Author

I managed now to retrieve the widget information by saving the configuration with the appWidgetId and the getData()method. I then can iterate in the Flutter part over the widgetIds and can retrieve the configuration. Is this how you would do it?

internal fun saveLocationPref(context: Context, appWidgetId: Int, location: Location?) {
    val prefs = HomeWidgetPlugin.getData(context).edit()
    prefs.putString(PREF_KEY + appWidgetId, Gson().toJson(location))
    prefs.apply()
}

@dario-digregorio
Copy link
Author

I am still struggling with some parts of implementing the configuration. I want to save the configuration information about the widget, let's say a weather location, into the SharedPreferences. While on Android you have methods like onCreate to save the location and onDelete to delete it again. I don't have similar hooks in iOS. I can only retrieve the information from the IntentTimelineProvider when the widget gets initialized with getSnapshot as far as I can see. The problem with that is that is I don't know when the widget is being deleted and therefore I don't know how to delete the location from the SharedPreferences again. Furthermore there is no WidgetId which I could use to uniquely identify a widget from the flutter part.
At this point I am not sure how to implement all this :/

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

No branches or pull requests

1 participant