Commit 079d3247 authored by Q14's avatar Q14

update

parent 00841322
......@@ -9,8 +9,7 @@
import 'package:flutter/material.dart';
import 'macros/ALColors.dart';
import 'macros/ALDevice.dart';
// import 'netWork/ALNetWork.dart';
import 'netWork/DioUtil.dart';
import 'netWork/ALNetWork.dart';
// import 'services/ALNetClient.dart';
// import 'hybrid_stack/hybrid_stack_manager_plugin.dart';
......@@ -153,33 +152,21 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
}
void confimSuggestInfo() {
// ALNetwork(
// success: (NetworkSuccess success){
// setState(() {
ALNetwork(
success: (NetworkSuccess success){
setState(() {
// });
// },
// error: (NetworkError error){
// setState(() {
});
},
error: (NetworkError error){
setState(() {
// });
// },
// api: '/api/v1/suggestion',
// params: {'content': 'aaa', 'phone': 'bbb'}
// );
});
},
api: '/api/v1/suggestion',
params: {'content': 'aaa', 'phone': 'bbb'}
);
DioUtil().get('/api/v1/suggestion',
data: {
'content': 'aaa',
'phone': '18601965003'
},
errorCallback: (statusCode) {
print('Http error code : $statusCode');
}
).then((data) {
print('Http response: $data');
});
}
}
......
......@@ -25,7 +25,7 @@ class NetworkError {
class ALURL {
ALURL({this.api}) : assert(api != null);
final String api;
static final baseUrl = 'https://earth.iyanzhi.com';
static final baseUrl = 'http://earth.igengmei.com';
String get originUrl => (baseUrl + api);
}
......
import 'dart:convert';
import 'dart:io';
import 'package:dio/dio.dart';
class Method {
static final String get = "GET";
static final String post = "POST";
static final String put = "PUT";
static final String head = "HEAD";
static final String delete = "DELETE";
static final String patch = "PATCH";
}
class DioUtil {
static final DioUtil _instance = DioUtil._init();
static Dio _dio;
static BaseOptions _options = getDefOptions();
factory DioUtil() {
return _instance;
}
DioUtil._init() {
_dio = new Dio();
}
static BaseOptions getDefOptions() {
BaseOptions options = BaseOptions();
options.connectTimeout = 10 * 1000;
options.receiveTimeout = 20 * 1000;
options.contentType = ContentType.parse('application/x-www-form-urlencoded');
Map<String, dynamic> headers = Map<String, dynamic>();
headers['Accept'] = 'application/json';
String platform;
if(Platform.isAndroid) {
platform = "Android";
} else if(Platform.isIOS) {
platform = "IOS";
}
headers['OS'] = platform;
options.headers = headers;
return options;
}
setOptions(BaseOptions options) {
_options = options;
_dio.options = _options;
}
Future<Map<String, dynamic>> get(String path, {pathParams, data, Function errorCallback}) {
return request(path, method: Method.get, pathParams: pathParams, data: data, errorCallback: errorCallback);
}
Future<Map<String, dynamic>> post(String path, {pathParams, data, Function errorCallback}) {
return request(path, method: Method.post, pathParams: pathParams, data: data, errorCallback: errorCallback);
}
Future<Map<String, dynamic>> request(String path,{String method, Map pathParams, data, Function errorCallback}) async {
///restful请求处理
if(pathParams != null) {
pathParams.forEach((key, value) {
if(path.indexOf(key) != -1) {
path = path.replaceAll(":$key", value.toString());
}
});
}
Response response = await _dio.request(path, data: data, options: Options(method: method));
if(response.statusCode == HttpStatus.ok || response.statusCode == HttpStatus.created) {
try {
if(response.data is Map) {
return response.data;
} else {
return json.decode(response.data.toString());
}
} catch(e) {
return null;
}
} else {
_handleHttpError(response.statusCode);
if(errorCallback != null) {
errorCallback(response.statusCode);
}
return null;
}
}
///处理Http错误码
void _handleHttpError(int errorCode) {
}
}
\ No newline at end of file
......@@ -5,49 +5,49 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
version: "2.2.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.11"
cookie_jar:
dependency: transitive
description:
name: cookie_jar
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
dio:
dependency: "direct main"
description:
name: dio
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.3"
flutter:
......@@ -73,37 +73,37 @@ packages:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.6.2"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.2"
version: "2.0.3"
sky_engine:
dependency: transitive
description: flutter
......@@ -113,63 +113,63 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.5.5"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.4"
version: "0.2.5"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.6"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
xservice_kit:
dependency: transitive
description:
name: xservice_kit
url: "https://pub.dartlang.org"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.29"
sdks:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment