| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import 'package:dio/dio.dart';
- import 'Result.dart';
- import 'package:intl/intl.dart';
- class HttpManager {
- static String baseUrl = "http://49.4.66.233:8201/";
- // static String baseUrl='http://192.168.50.121:8080/';
- static String token;
- static bool debug;
- static Dio _createDio() {
- Map<String, dynamic> headers = Map();
- headers["token"] = token;
- BaseOptions options = BaseOptions(baseUrl: baseUrl, headers: headers);
- return Dio(options);
- }
- static Future<Result> post(String url, {Map<String, dynamic> data}) {
- return Future(() async {
- FormData formData = FormData.from(data ?? {});
- Response response = await _createDio().post(url, data: formData);
- print(response);
- if (response.statusCode != 200) {
- return Future.error("httpCode" + response.statusCode.toString());
- }
- Result result = Result.fromJson(response.data);
- return result;
- });
- }
- static Future<Result> get(String url, {Map<String, dynamic> data}) {
- return Future(() async {
- Response response =
- await _createDio().get(url, queryParameters: data ?? {});
- if (response.statusCode != 200) {
- return Future.error("httpCode" + response.statusCode.toString());
- }
- Result result = Result.fromJson(response.data);
- return result;
- });
- }
- }
- String readTimestamp(int timestamp,String _timeType) {
-
- return DateFormat(_timeType).format(DateTime.fromMillisecondsSinceEpoch(timestamp));
- }
|