12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import 'package:dio/dio.dart';
- /// Description: http util
- /// Time : 09/04/2023 Monday
- /// Author : liuyuqi.gov@msn.cn
- class HttpUtil {
- static const String BASE_URL = "http://";
- static const int CONNECT_TIMEOUT = 10000;
- static const int RECEIVE_TIMEOUT = 3000;
- static HttpUtil? _instance;
- static Dio? _dio;
- static HttpUtil getInstance() {
- _instance ??= HttpUtil();
- return _instance!;
- }
- Future<Map<String, dynamic>> get(String url,
- {Map<String, dynamic>? params}) async {
- Response response = await _dio!.get(url, queryParameters: params);
- return response.data;
- }
- Future<Map<String, dynamic>> post(String url,
- {Map<String, dynamic>? params}) async {
- Response response = await _dio!.post(url, data: params);
- return response.data;
- }
- }
- class ErrorCode {
- int code;
- String msg;
- ErrorCode(this.code, this.msg);
- ErrorCode.fromJson({this.code = 0, this.msg = ""});
- Map<String, dynamic> toJson() {
- return {
- 'code': code,
- 'msg': msg,
- };
- }
- }
|