Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. https://stackoverflow.com/questions/55018479/offsets-are-different-ontap-and-ondrag-flutter
  2.  
  3.  
  4. https://pub.dev/packages/dio#examples
  5.  
  6.  
  7. class ServerProxy
  8. {
  9. Dio dio;
  10.  
  11. Singleton._privateCtor() {
  12.  
  13. BaseOptions options = new BaseOptions(
  14. baseUrl: "https://www.xx.com/api",
  15. connectTimeout: 5000,
  16. receiveTimeout: 3000,
  17. );
  18.  
  19. dio = Dio(options);
  20. }
  21.  
  22.  
  23. static final ServerProxy _singleton = ServerProxy._privateCtor();
  24.  
  25. factory ServerProxy() => _singleton;
  26.  
  27.  
  28. String getAsTextEndPoint = "/getAsText";
  29. Future<String> getAsText(Image img) {
  30. FormData formData = FormData.from({
  31. "file": await MultipartFile.fromFile(IDK_WHAT_TO_PUT_HERE, filename: "upload.txt") //TODO
  32. });
  33. Response response = await dio.post(
  34. getAsTextEndPoint,
  35. data: formData
  36. onSendProgress: (int sent, int total) { //TODO
  37. print("$sent $total");
  38. }
  39. );
  40.  
  41. int statusCode = response.statusCode;
  42. const int SUCCESS_CODE = 123 //TODO
  43.  
  44. if(statusCode != SUCCESS_CODE)
  45. throw("request unsuccessfu! [STATUS CODE: $statusCode");
  46.  
  47. return response.data.toString();
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement