Skip to content

Commit 51d68e2

Browse files
committed
feat: added toasts for server errors
1 parent fe94304 commit 51d68e2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/api_service.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import 'dart:convert';
44
import 'package:flutter/foundation.dart';
5+
import 'package:flutter/material.dart';
56
import 'package:http/http.dart' as http;
67
import 'package:sqflite/sqflite.dart';
78
import 'package:path/path.dart';
@@ -205,6 +206,11 @@ Future<void> completeTask(String email, String taskUuid) async {
205206
debugPrint('Task completed successfully on server');
206207
} else {
207208
debugPrint('Failed to complete task: ${response.statusCode}');
209+
ScaffoldMessenger.of(context as BuildContext).showSnackBar(const SnackBar(
210+
content: Text(
211+
"Failed to complete task!",
212+
style: TextStyle(color: Colors.red),
213+
)));
208214
}
209215
} catch (e) {
210216
debugPrint('Error completing task: $e');
@@ -250,7 +256,7 @@ Future<void> modifyTaskOnTaskwarrior(String description, String project,
250256
var e = await CredentialsStorage.getEncryptionSecret();
251257
debugPrint(c);
252258
debugPrint(e);
253-
await http.post(
259+
final response = await http.post(
254260
Uri.parse(apiUrl),
255261
headers: {
256262
'Content-Type': 'text/plain',
@@ -268,6 +274,14 @@ Future<void> modifyTaskOnTaskwarrior(String description, String project,
268274
}),
269275
);
270276

277+
if (response.statusCode != 200) {
278+
ScaffoldMessenger.of(context as BuildContext).showSnackBar(const SnackBar(
279+
content: Text(
280+
"Failed to update task!",
281+
style: TextStyle(color: Colors.red),
282+
)));
283+
}
284+
271285
var taskDatabase = TaskDatabase();
272286
await taskDatabase.open();
273287
await taskDatabase._database!.delete(

0 commit comments

Comments
 (0)