http_util.dart 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import 'package:dio/dio.dart';
  2. /// Description: http util
  3. /// Time : 09/04/2023 Monday
  4. /// Author : liuyuqi.gov@msn.cn
  5. class HttpUtil {
  6. static const String BASE_URL = "http://";
  7. static const int CONNECT_TIMEOUT = 10000;
  8. static const int RECEIVE_TIMEOUT = 3000;
  9. static HttpUtil? _instance;
  10. static Dio? _dio;
  11. static HttpUtil getInstance() {
  12. _instance ??= HttpUtil();
  13. return _instance!;
  14. }
  15. Future<Map<String, dynamic>> get(String url,
  16. {Map<String, dynamic>? params}) async {
  17. Response response = await _dio!.get(url, queryParameters: params);
  18. return response.data;
  19. }
  20. Future<Map<String, dynamic>> post(String url,
  21. {Map<String, dynamic>? params}) async {
  22. Response response = await _dio!.post(url, data: params);
  23. return response.data;
  24. }
  25. }
  26. class ErrorCode {
  27. int code;
  28. String msg;
  29. ErrorCode(this.code, this.msg);
  30. ErrorCode.fromJson({this.code = 0, this.msg = ""});
  31. Map<String, dynamic> toJson() {
  32. return {
  33. 'code': code,
  34. 'msg': msg,
  35. };
  36. }
  37. }