File tree Expand file tree Collapse file tree 2 files changed +21
-13
lines changed
Expand file tree Collapse file tree 2 files changed +21
-13
lines changed Original file line number Diff line number Diff line change 11import 'package:http/http.dart' as http;
22
3- Future <String > sendJSON (Uri uri, String data) async {
4- var response = await http.post (
5- uri,
6- headers: {
7- 'Content-Type' : 'application/json' ,
8- },
9- body: data,
10- );
3+ Future <String > sendJSON (http.Client client, Uri uri, String data) async {
4+ try {
5+ var response = await client.post (
6+ uri,
7+ headers: {
8+ 'Content-Type' : 'application/json' ,
9+ },
10+ body: data,
11+ );
1112
12- if (response.statusCode == 200 ) {
13- return response.body;
14- } else {
15- throw response.body;
13+ if (response.statusCode == 200 ) {
14+ return response.body;
15+ } else {
16+ throw response.body;
17+ }
18+ } finally {
19+ client.close ();
1620 }
1721}
Original file line number Diff line number Diff line change 11library emailjs;
22
33import 'dart:convert' ;
4+ import 'package:http/http.dart' as http;
45
56import 'package:emailjs/utils/validate_params.dart' ;
67import 'package:emailjs/api/send_json.dart' ;
78
89class EmailJS {
910 static String _publicKey = '' ;
1011 static String _origin = 'api.emailjs.com' ;
12+ static http.Client _httpClient = http.Client ();
1113
12- static void init (String publicKey, [String ? origin]) {
14+ static void init (String publicKey, [String ? origin, http. Client ? httpClient ]) {
1315 EmailJS ._publicKey = publicKey;
1416 EmailJS ._origin = origin ?? 'api.emailjs.com' ;
17+ EmailJS ._httpClient = httpClient ?? http.Client ();
1518 }
1619
1720 static Future <String > send (
@@ -33,6 +36,7 @@ class EmailJS {
3336 };
3437
3538 return await sendJSON (
39+ EmailJS ._httpClient,
3640 Uri .https (EmailJS ._origin, 'api/v1.0/email/send' ),
3741 json.encode (params),
3842 );
You can’t perform that action at this time.
0 commit comments