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
To get automatic Updates you should extend from [HomeWidgetGlanceWidgetReceiver](android/src/main/kotlin/es/antonborri/home_widget/HomeWidgetGlanceWidgetReceiver.kt)
@@ -103,22 +182,6 @@ which will give you access to the same SharedPreferences
103
182
### More Information
104
183
For more Information on how to create and configure Android Widgets, check out [this guide](https://developer.android.com/develop/ui/views/appwidgets) on the Android Developers Page.
105
184
106
-
### Jetpack Glance
107
-
In Jetpack Glance, you have to write your receiver (== provider), that returns a widget.
108
-
Add it to AndroidManifest the same way as written above for android widgets.
If you need to access HomeWidget shared preferences, use this:
117
-
118
-
```kotlin
119
-
HomeWidgetPlugin.getData(context)
120
-
```
121
-
122
185
</details>
123
186
124
187
## Usage
@@ -145,14 +208,17 @@ HomeWidget.updateWidget(
145
208
);
146
209
```
147
210
148
-
The name for Android will be chosen by checking `qualifiedAndroidName`, falling back to `<packageName>.androidName` and if that was not provided it
149
-
will fallback to `<packageName>.name`.
211
+
The name forAndroid will be chosen by checking `qualifiedAndroidName`, falling back to `<packageName>.androidName` andif that was not provided it will fallback to `<packageName>.name`.
150
212
ThisName needs to be equal to the Classname of the [WidgetProvider](#Write-your-Widget)
151
213
152
214
The name for iOS will be chosen by checking `iOSName` if that was not provided it will fallback to `name`.
153
215
This name needs to be equal to the Kind specified in you Widget
154
216
155
-
#### Android
217
+
#### Android (JetpackGlance)
218
+
219
+
If you followed the guide and use `HomeWidgetGlanceWidgetReceiver` as your Receiver, `HomeWidgetGlanceStateDefinition` as the AppWidgetStateDefinition, `currentState()` in the composable view and `currentState.preferences` for data access. No further work is necessary.
220
+
221
+
#### Android (XML)
156
222
Calling `HomeWidget.updateWidget` only notifies the specified provider.
157
223
To update widgets using this provider,
158
224
update them from the provider like this:
@@ -173,36 +239,6 @@ class HomeWidgetExampleProvider : HomeWidgetProvider() {
173
239
}
174
240
```
175
241
176
-
#### Jetpack Glance
177
-
Updating widgets in Jetpack Glance is a bit more tricky,
178
-
widgets are only updated when their state changes,
179
-
therefore simple update will not refresh them.
180
-
To update them, you have to fake state update like this:
To retrieve the current Data saved in the Widget call `HomeWidget.getWidgetData<String>('id', defaultValue: data)`
@@ -301,7 +337,40 @@ Android and iOS (starting with iOS 17) allow widgets to have interactive Element
301
337
This code tells the system to always perform the Intent in the App and not in a process attached to the Widget. Note however that this will start your Flutter App using the normal main entrypoint meaning your full app might be run in the background. To counter this you should add checks in the very first Widget you build inside `runApp` to only perform necessary calls/setups while the App is launched in the background
0 commit comments