@@ -25,9 +25,10 @@ class HomeWidget {
2525 String id,
2626 T ? data, {
2727 bool deleteFile = true ,
28+ String ? appGroupId,
2829 }) async {
2930 if (deleteFile && data == null ) {
30- final raw = await getWidgetData <dynamic >(id);
31+ final raw = await getWidgetData <dynamic >(id, appGroupId : appGroupId );
3132 if (raw is String && _isHomeWidgetManagedFilePath (raw)) {
3233 final file = File (raw);
3334 if (await file.exists ()) {
@@ -40,10 +41,12 @@ class HomeWidget {
4041 }
4142 }
4243
43- return _channel. invokeMethod < bool >( 'saveWidgetData' , {
44+ final arguments = < String , dynamic > {
4445 'id' : id,
4546 'data' : data,
46- });
47+ if (appGroupId != null ) 'appGroupId' : appGroupId,
48+ };
49+ return _channel.invokeMethod <bool >('saveWidgetData' , arguments);
4750 }
4851
4952 /// Updates the HomeScreen Widget
@@ -99,11 +102,17 @@ class HomeWidget {
99102 /// Returns Data saved with [saveWidgetData]
100103 /// [id] of Data Saved
101104 /// [defaultValue] value to use if no data was found
102- static Future <T ?> getWidgetData <T >(String id, {T ? defaultValue}) {
103- return _channel.invokeMethod <T >('getWidgetData' , {
105+ static Future <T ?> getWidgetData <T >(
106+ String id, {
107+ T ? defaultValue,
108+ String ? appGroupId,
109+ }) {
110+ final arguments = < String , dynamic > {
104111 'id' : id,
105112 'defaultValue' : defaultValue,
106- });
113+ if (appGroupId != null ) 'appGroupId' : appGroupId,
114+ };
115+ return _channel.invokeMethod <T >('getWidgetData' , arguments);
107116 }
108117
109118 /// Required on iOS to set the AppGroupId [groupId] in order to ensure
@@ -229,6 +238,7 @@ class HomeWidget {
229238 String key,
230239 Uint8List bytes, {
231240 String extension = 'bin' ,
241+ String ? appGroupId,
232242 }) async {
233243 final ext = _normalizeExtension (extension );
234244 _validateKey (key);
@@ -238,17 +248,18 @@ class HomeWidget {
238248 // coverage:ignore-start
239249 if (Platform .isIOS) {
240250 final PathProviderFoundation provider = PathProviderFoundation ();
251+ final resolvedGroupId = appGroupId ?? HomeWidget .groupId;
241252 assert (
242- HomeWidget .groupId != null ,
253+ resolvedGroupId != null ,
243254 'No groupId defined. Did you forget to call `HomeWidget.setAppGroupId`' ,
244255 );
245256 directory = await provider.getContainerPath (
246- appGroupIdentifier: HomeWidget .groupId ! ,
257+ appGroupIdentifier: resolvedGroupId ! ,
247258 );
248259
249260 if (directory == null ) {
250261 throw StateError (
251- 'Widget storage directory is null for group "${ HomeWidget . groupId } ". '
262+ 'Widget storage directory is null for group "$resolvedGroupId ". '
252263 'Verify App Group configuration and HomeWidget.setAppGroupId.' ,
253264 );
254265 }
@@ -264,7 +275,7 @@ class HomeWidget {
264275 }
265276 await file.writeAsBytes (bytes);
266277
267- await saveWidgetData <String >(key, path);
278+ await saveWidgetData <String >(key, path, appGroupId : appGroupId );
268279
269280 return path;
270281 } catch (e) {
@@ -279,6 +290,7 @@ class HomeWidget {
279290 String key,
280291 ImageProvider imageProvider, {
281292 ImageConfiguration configuration = ImageConfiguration .empty,
293+ String ? appGroupId,
282294 }) async {
283295 _validateKey (key);
284296 final completer = Completer <Uint8List >();
@@ -320,7 +332,7 @@ class HomeWidget {
320332 );
321333 stream.addListener (listener);
322334 final bytes = await completer.future;
323- return saveFile (key, bytes, extension : 'png' );
335+ return saveFile (key, bytes, extension : 'png' , appGroupId : appGroupId );
324336 }
325337
326338 /// Generate a screenshot based on a given widget.
@@ -335,6 +347,7 @@ class HomeWidget {
335347 required String key,
336348 Size logicalSize = const Size (200 , 200 ),
337349 double ? pixelRatio,
350+ String ? appGroupId,
338351 }) async {
339352 pixelRatio ?? =
340353 PlatformDispatcher .instance.implicitView? .devicePixelRatio ?? 1 ;
@@ -417,6 +430,7 @@ class HomeWidget {
417430 key,
418431 byteData.buffer.asUint8List (),
419432 extension : 'png' ,
433+ appGroupId: appGroupId,
420434 );
421435 } catch (e) {
422436 throw Exception ('Failed to save screenshot to app group container: $e ' );
0 commit comments