11import 'dart:convert' ;
22import 'package:http/http.dart' as http;
3- import 'package:flutter/material .dart' ;
3+ import 'package:flutter/foundation .dart' ;
44import 'package:taskwarrior/app/utils/taskchampion/credentials_storage.dart' ;
5- import 'package:path/path.dart' ;
65
7- Future <void > completeTask (String email, String taskUuid) async {
6+ Future <void > completeTask (String email, String taskUuid,
7+ {http.Client ? client}) async {
8+ final httpClient = client ?? http.Client ();
89 var c = await CredentialsStorage .getClientId ();
910 var e = await CredentialsStorage .getEncryptionSecret ();
1011 var baseUrl = await CredentialsStorage .getApiUrl ();
@@ -17,7 +18,7 @@ Future<void> completeTask(String email, String taskUuid) async {
1718 });
1819
1920 try {
20- final response = await http .post (
21+ final response = await httpClient .post (
2122 url,
2223 headers: {
2324 'Content-Type' : 'application/json' ,
@@ -29,13 +30,10 @@ Future<void> completeTask(String email, String taskUuid) async {
2930 debugPrint ('Task completed successfully on server' );
3031 } else {
3132 debugPrint ('Failed to complete task: ${response .statusCode }' );
32- ScaffoldMessenger .of (context as BuildContext ).showSnackBar (const SnackBar (
33- content: Text (
34- "Failed to complete task!" ,
35- style: TextStyle (color: Colors .red),
36- )));
33+ throw Exception ('Failed to complete task: ${response .statusCode }' );
3734 }
38- } catch (e) {
39- debugPrint ('Error completing task: $e ' );
35+ } catch (e, s) {
36+ debugPrint ('Error completing task: $e \n $s ' );
37+ rethrow ;
4038 }
4139}
0 commit comments