Skip to content

Commit 80811a4

Browse files
committed
refactor: further mobile optimization of code examples
- Shortened method names and variable declarations - Split long function calls across multiple lines appropriately - Removed verbose comments that take up mobile screen space - Made code more scannable on small screens
1 parent b504688 commit 80811a4

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

docs/quickstart.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,32 @@ iOS requires a 5-minute setup in Xcode:
5353
```swift
5454
import workmanager
5555

56-
// In application(_:didFinishLaunchingWithOptions:)
57-
WorkmanagerPlugin.registerBGProcessingTask(withIdentifier: "your.task.identifier")
56+
// In application didFinishLaunching
57+
WorkmanagerPlugin.registerBGProcessingTask(
58+
withIdentifier: "your.task.identifier"
59+
)
5860
```
5961

6062
## Basic Usage
6163

6264
### 1. Create Background Task Handler
6365

6466
```dart
65-
@pragma('vm:entry-point') // Required for release builds
67+
@pragma('vm:entry-point')
6668
void callbackDispatcher() {
6769
Workmanager().executeTask((task, inputData) async {
6870
print("Background task: $task");
6971
70-
// Your background logic here
7172
switch (task) {
7273
case "data_sync":
7374
await syncDataWithServer();
7475
break;
75-
case "cleanup":
76+
case "cleanup":
7677
await cleanupOldFiles();
7778
break;
7879
}
7980
80-
return Future.value(true); // Task completed successfully
81+
return Future.value(true);
8182
});
8283
}
8384
```
@@ -86,10 +87,9 @@ void callbackDispatcher() {
8687

8788
```dart
8889
void main() {
89-
// Initialize Workmanager
9090
Workmanager().initialize(
9191
callbackDispatcher,
92-
isInDebugMode: true, // Shows notifications when tasks run
92+
isInDebugMode: true,
9393
);
9494
9595
runApp(MyApp());

docs/usecases/upload-files.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,18 @@ Future<bool> _uploadFile(Map<String, dynamic> inputData) async {
7373
}
7474
7575
// Create multipart request
76-
final request = http.MultipartRequest(
77-
'POST',
78-
Uri.parse('https://api.yourapp.com/upload'),
79-
);
76+
final uri = Uri.parse('https://api.yourapp.com/upload');
77+
final request = http.MultipartRequest('POST', uri);
8078
81-
request.headers['Authorization'] = 'Bearer YOUR_TOKEN';
82-
request.fields.addAll(metadata.map((k, v) => MapEntry(k, v.toString())));
79+
request.headers['Authorization'] = 'Bearer TOKEN';
80+
request.fields.addAll(
81+
metadata.map((k, v) => MapEntry(k, v.toString()))
82+
);
8383
84-
final multipartFile = await http.MultipartFile.fromPath(
85-
'file',
86-
filePath,
84+
final file = await http.MultipartFile.fromPath(
85+
'file', filePath
8786
);
88-
request.files.add(multipartFile);
87+
request.files.add(file);
8988
9089
final response = await request.send().timeout(Duration(minutes: 5));
9190

0 commit comments

Comments
 (0)