@@ -43,7 +43,8 @@ import '../main.dart';
4343/// After, a new receipt object is crafted and send to the [ReceiptForm] .
4444/// The receipt form uses this object to fill the corresponding text fields.
4545class NetworkClient {
46- final _protocol = "https://" ;
46+ final _https = "https://" ;
47+ final _http = "http://" ;
4748 final _uploadPath = "/api/upload" ;
4849 final _trainingPath = "/api/training" ;
4950 final _token = "?access_token=" ;
@@ -59,19 +60,20 @@ class NetworkClient {
5960
6061 NetworkClient ._internal ();
6162
62- init () {
63- /// override the agent to provide support for self signed
64- /// certificates.
65- ///
66- /// Since the server runs local and the certificate is protected
67- /// with a password, the security risk is small.
68- HttpOverrides .global = new SelfSignedHttpAgent ();
69- }
70-
7163 String getAPIUrl (final ip, final token, final legacyParser, final gaussian,
72- final grayscale, final rotate) {
73- if (token == null || token == "" )
74- return _protocol +
64+ final grayscale, final rotate, final https) {
65+
66+ if (https)
67+ /// override the agent to provide support for self signed
68+ /// certificates.
69+ ///
70+ /// Since the server runs local and the certificate is protected
71+ /// with a password, the security risk is small.
72+ HttpOverrides .global = new SelfSignedHttpAgent ();
73+
74+ String protocol = https ? _https : _http;
75+ if (token == null || token == "" ) {
76+ return protocol +
7577 ip +
7678 ":" +
7779 _port +
@@ -84,7 +86,9 @@ class NetworkClient {
8486 getValue (gaussian) +
8587 "&rotate=" +
8688 getValue (rotate);
87- return _protocol +
89+ }
90+
91+ return protocol +
8892 ip +
8993 ":" +
9094 _port +
@@ -119,7 +123,6 @@ class NetworkClient {
119123
120124 sendTrainingData (String ip, String token, String company, String date,
121125 String total, BuildContext context) async {
122- init ();
123126
124127 log ("Submit training data." );
125128 Map <String , String > headers = {"Content-type" : "application/json" };
@@ -142,7 +145,6 @@ class NetworkClient {
142145 /// Send image via post request to the server and capture the response.
143146 sendImage (File imageFile, NetworkClientHolder holder, BuildContext context,
144147 [GlobalKey <ScaffoldState > key]) async {
145- init ();
146148
147149 log ("Try to upload new image." );
148150 if (holder.ip == null || holder.ip.isEmpty) {
@@ -163,7 +165,7 @@ class NetworkClient {
163165
164166 var length = await imageFile.length ();
165167 var uri = Uri .parse (getAPIUrl (holder.ip, holder.token, holder.legacyParser,
166- holder.gaussian, holder.grayscale, holder.rotate));
168+ holder.gaussian, holder.grayscale, holder.rotate, holder.https ));
167169
168170 log (uri.toString ());
169171
@@ -325,7 +327,7 @@ class NetworkClient {
325327 }
326328
327329 getTrainingUrl (String ip, String token) {
328- return _protocol + ip + ":" + _port + _trainingPath + _token + token;
330+ return _https + ip + ":" + _port + _trainingPath + _token + token;
329331 }
330332}
331333
0 commit comments