@@ -195,64 +195,60 @@ class _SyncStatusWidgetState extends State<SyncStatusWidget> {
195195
196196## Platform-Specific Considerations
197197
198- <Tabs >
199- <Tab title = " Android" >
200- ** Android automatically handles** :
201- - Task scheduling and retry logic
202- - Battery optimization (Doze mode)
203- - App standby mode restrictions
204- - Network changes and availability
205-
206- ** Best practices** :
207- ```dart
208- // Use appropriate constraints
209- Workmanager().registerPeriodicTask(
210- "data_sync",
211- "sync_task",
212- frequency: Duration(hours: 1),
213- constraints: Constraints(
214- networkType: NetworkType.connected,
215- requiresBatteryNotLow: true, // Respect battery optimization
216- requiresCharging: false, // Don't wait for charging
217- ),
218- );
219- ```
220-
221- ** Minimum frequency** : 15 minutes (Android WorkManager limitation)
222- </Tab >
223-
224- <Tab title = " iOS" >
225- ** iOS has additional restrictions** :
226- - Background App Refresh must be enabled
227- - Tasks may be limited to 30 seconds
228- - iOS learns usage patterns and schedules accordingly
229- - No guaranteed execution time
230-
231- ** Setup required in AppDelegate.swift** :
232- ```swift
233- import workmanager
234-
235- // In application(_ :didFinishLaunchingWithOptions:)
236- WorkmanagerPlugin.registerPeriodicTask(
237- withIdentifier: "data_sync_task",
238- frequency: NSNumber(value: 60 * 60) // 1 hour in seconds
239- )
240- ```
241-
242- ** Info.plist configuration** :
243- ```xml
244- <key >BGTaskSchedulerPermittedIdentifiers</key >
245- <array >
246- <string >data_sync_task</string >
247- </array >
248- ```
249-
250- ** Best practices** :
251- - Keep sync operations under 30 seconds
252- - Use incremental sync (only fetch changes)
253- - Handle task expiration gracefully
254- </Tab >
255- </Tabs >
198+ ### Android
199+ ** Android automatically handles** :
200+ - Task scheduling and retry logic
201+ - Battery optimization (Doze mode)
202+ - App standby mode restrictions
203+ - Network changes and availability
204+
205+ ** Best practices** :
206+ ``` dart
207+ // Use appropriate constraints
208+ Workmanager().registerPeriodicTask(
209+ "data_sync",
210+ "sync_task",
211+ frequency: Duration(hours: 1),
212+ constraints: Constraints(
213+ networkType: NetworkType.connected,
214+ requiresBatteryNotLow: true, // Respect battery optimization
215+ requiresCharging: false, // Don't wait for charging
216+ ),
217+ );
218+ ```
219+
220+ ** Minimum frequency** : 15 minutes (Android WorkManager limitation)
221+
222+ ### iOS
223+ ** iOS has additional restrictions** :
224+ - Background App Refresh must be enabled
225+ - Tasks may be limited to 30 seconds
226+ - iOS learns usage patterns and schedules accordingly
227+ - No guaranteed execution time
228+
229+ ** Setup required in AppDelegate.swift** :
230+ ``` swift
231+ import workmanager
232+
233+ // In application(_:didFinishLaunchingWithOptions:)
234+ WorkmanagerPlugin.registerPeriodicTask (
235+ withIdentifier : " data_sync_task" ,
236+ frequency : NSNumber (value : 60 * 60 ) // 1 hour in seconds
237+ )
238+ ```
239+
240+ ** Info.plist configuration** :
241+ ``` xml
242+ <key >BGTaskSchedulerPermittedIdentifiers</key >
243+ <array >
244+ <string >data_sync_task</string >
245+ </array >
246+ ```
247+
248+ ** Best practices** :
249+ - Keep sync operations under 30 seconds
250+ - Use incremental sync (only fetch changes)
251+ - Handle task expiration gracefully
256252
257253## Testing Your Implementation
258254
@@ -299,60 +295,49 @@ Future<void> _checkSyncHealth() async {
299295
300296## Common Issues & Solutions
301297
302- <AccordionGroup >
303- <Accordion title = " Sync Not Running" >
304- ** Possible causes** :
305- - Missing platform setup (Android/iOS configuration)
306- - App battery optimization preventing background tasks
307- - No network connectivity when task tries to run
308- - App hasn't been used recently (iOS restriction)
309-
310- ** Solutions** :
311- - Verify platform setup is complete
312- - Ask users to disable battery optimization for your app
313- - Use network constraints appropriately
314- - Encourage regular app usage
315- </Accordion >
316-
317- <Accordion title = " Partial Data Sync" >
318- ** Implement incremental sync** :
319- ```dart
320- Future<bool > _ performIncrementalSync() async {
321- final prefs = await SharedPreferences .getInstance ();
322- final lastSyncTime = prefs .getString (' last_sync_time' ) ?? ' ' ;
323-
324- final response = await http .get (
325- Uri .parse (' https://api.yourapp.com/data?since=$lastSyncTime' ),
326- );
327-
328- // Only sync changed data
329- if (response .statusCode == 200 ) {
330- final changes = json .decode (response .body );
331- await _applyChanges(changes );
332- return true;
333- }
334- return false ;
335- }
336- ```
337- </Accordion >
338-
339- <Accordion title = " High Battery Usage" >
340- ** Optimize your sync logic** :
341- - Use appropriate frequency (not too often)
342- - Add battery constraints
343- - Implement smart syncing (only when data actually changed)
344- - Use compression for large payloads
345- - Cache API responses appropriately
346- </Accordion >
347- </AccordionGroup >
298+ ### Sync Not Running
299+ ** Possible causes** :
300+ - Missing platform setup (Android/iOS configuration)
301+ - App battery optimization preventing background tasks
302+ - No network connectivity when task tries to run
303+ - App hasn't been used recently (iOS restriction)
304+
305+ ** Solutions** :
306+ - Verify platform setup is complete
307+ - Ask users to disable battery optimization for your app
308+ - Use network constraints appropriately
309+ - Encourage regular app usage
310+
311+ ### Partial Data Sync
312+ ** Implement incremental sync** :
313+ ``` dart
314+ Future<bool> _performIncrementalSync() async {
315+ final prefs = await SharedPreferences.getInstance();
316+ final lastSyncTime = prefs.getString('last_sync_time') ?? '';
317+
318+ final response = await http.get(
319+ Uri.parse('https://api.yourapp.com/data?since=$lastSyncTime'),
320+ );
321+
322+ // Only sync changed data
323+ if (response.statusCode == 200) {
324+ final changes = json.decode(response.body);
325+ await _applyChanges(changes);
326+ return true;
327+ }
328+ return false;
329+ }
330+ ```
331+
332+ ### High Battery Usage
333+ ** Optimize your sync logic** :
334+ - Use appropriate frequency (not too often)
335+ - Add battery constraints
336+ - Implement smart syncing (only when data actually changed)
337+ - Use compression for large payloads
338+ - Cache API responses appropriately
348339
349340## Related Use Cases
350341
351- <CardGroup cols = { 2 } >
352- <Card title = " Upload Files" icon = " cloud-arrow-up" href = " /usecases/upload-files" >
353- Upload user content in the background
354- </Card >
355- <Card title = " Fetch Notifications" icon = " bell" href = " /usecases/fetch-notifications" >
356- Check for new notifications from your server
357- </Card >
358- </CardGroup >
342+ - ** [ Upload Files] ( upload-files ) ** - Upload user content in the background
343+ - ** [ Fetch Notifications] ( fetch-notifications ) ** - Check for new notifications from your server
0 commit comments