Commit f5f15dff authored by jinzhu's avatar jinzhu

update comment_suggest

parent 26a89835
......@@ -145,7 +145,8 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
void confimSuggestInfo() {
print('11111111----come----confimSuggestInfo');
BaseOptions options = DioUtil.getDefOptions();
HttpConfig config = new HttpConfig(options: options, nativeCookie: widget.nativeCookie);
final cookie = new Map<String, dynamic>.from(widget.nativeCookie);
HttpConfig config = new HttpConfig(options: options, nativeCookie: cookie);
DioUtil().setConfig(config);
print('aaaaaaaa----come----config');
print(config.nativeCookie);
......@@ -153,20 +154,20 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
print(widget.nativeCookie);
DioUtil().requestR(Method.post, "api/v1/suggestion",data: {"content": "add", "phone": "aaa"}).then((res){
showAlertDialog(context, res.data);
print('请求成功');
print(res);
// showAlertDialog(context, '请求成功');
}
).then((error){
print(error);
});
}
void showAlertDialog(BuildContext context, Text testStr) {
void showAlertDialog(BuildContext context, String textStr) {
showDialog(
context: context,
builder: (_) => new AlertDialog(
title: testStr,
title: new Text(textStr),
content: new Text("This is my content"),
actions:<Widget>[
new FlatButton(child:new Text("CANCEL"), onPressed: (){
......@@ -174,8 +175,6 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
},),
new FlatButton(child:new Text("OK"), onPressed: (){
// Navigator.of(context).pop();
},)
]
......
......@@ -35,28 +35,36 @@ class _MyAppState extends State<MyApp> {
FlutterBoost.handleOnStartPage();
}
@override
@override
Widget build(BuildContext context) {
return MaterialApp(
locale: Locale('en', 'US'),
supportedLocales: [
Locale('en', 'US'),
Locale('zh', 'CN'),
],
debugShowCheckedModeBanner: false,
// home: NavigatorDemo(),
initialRoute: '/test',
routes: {
'/': (context) => CommentSuggest({'cookie': '124'}),
},
theme: ThemeData(
primarySwatch: Colors.yellow,
highlightColor: Color.fromRGBO(255, 255, 255, 0.5),
splashColor: Colors.white70,
accentColor: Color.fromRGBO(3, 54, 255, 1.0),
)
);
title: 'Flutter Boost example',
builder: FlutterBoost.init(postPush: _onRoutePushed),
home: Container());
}
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// locale: Locale('en', 'US'),
// supportedLocales: [
// Locale('en', 'US'),
// Locale('zh', 'CN'),
// ],
// debugShowCheckedModeBanner: false,
// // home: NavigatorDemo(),
// initialRoute: '/test',
// routes: {
// '/': (context) => CommentSuggest({'cookie': '124'}),
// },
// builder: FlutterBoost.init(postPush: _onRoutePushed),
// theme: ThemeData(
// primarySwatch: Colors.yellow,
// highlightColor: Color.fromRGBO(255, 255, 255, 0.5),
// splashColor: Colors.white70,
// accentColor: Color.fromRGBO(3, 54, 255, 1.0),
// )
// );
// }
void _onRoutePushed(
String pageName, String uniqueId, Map params, Route route, Future _) {
......
......@@ -8,8 +8,10 @@ class BaseResp<T> {
int code;
String msg;
T data;
T extra;
T userType;
BaseResp(this.status, this.code, this.msg, this.data);
BaseResp(this.status, this.code, this.msg, this.data, this.extra, this.userType);
@override
String toString() {
......@@ -18,6 +20,8 @@ class BaseResp<T> {
sb.write(",\"code\":$code");
sb.write(",\"msg\":\"$msg\"");
sb.write(",\"data\":\"$data\"");
sb.write(",\"extra\":\"$extra\"");
sb.write(",\"userType\":\"$userType\"");
sb.write('}');
return sb.toString();
}
......@@ -29,9 +33,11 @@ class BaseRespR<T> {
int code;
String msg;
T data;
T extra;
T userType;
Response response;
BaseRespR(this.status, this.code, this.msg, this.data, this.response);
BaseRespR(this.status, this.code, this.msg, this.data, this.extra, this.userType, this.response);
@override
String toString() {
......@@ -40,8 +46,10 @@ class BaseRespR<T> {
sb.write(",\"code\":$code");
sb.write(",\"msg\":\"$msg\"");
sb.write(",\"data\":\"$data\"");
sb.write(",\"extra\":\"$extra\"");
sb.write(",\"userType\":\"$userType\"");
sb.write('}');
return sb.toString();
return sb.toString();;
}
}
......@@ -110,15 +118,21 @@ class DioUtil {
/// BaseResp [String status]字段 key, 默认:status.
String _statusKey = "status";
/// BaseResp [int code]字段 key, 默认:errorCode.
String _codeKey = "errorCode";
/// BaseResp [int code]字段 key, 默认:error = 0 代表成功.
String _codeKey = "error";
/// BaseResp [String msg]字段 key, 默认:errorMsg.
String _msgKey = "errorMsg";
String _msgKey = "message";
/// BaseResp [T data]字段 key, 默认:data.
String _dataKey = "data";
/// BaseResp [T data]字段 key, 默认:extra.
String _extraKey = 'extra';
// BaseResp [T data]字段 key, 默认:user_type.
String _userType = 'user_type';
/// Options.
static BaseOptions _options = getDefOptions();
......@@ -132,7 +146,7 @@ class DioUtil {
String _pKCSPwd;
/// 是否是debug模式.
static bool _isDebug = false;
static bool _isDebug = true;
static DioUtil getInstance() {
return _instance;
......@@ -158,6 +172,7 @@ class DioUtil {
_msgKey = config.msg ?? _msgKey;
_dataKey = config.data ?? _dataKey;
_mergeOption(config.options);
_mergeNativeCookie(config);
_pem = config.pem ?? _pem;
if (_dio != null) {
_dio.options = _options;
......@@ -204,6 +219,8 @@ class DioUtil {
int _code;
String _msg;
T _data;
T _extra;
T _userType;
if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) {
try {
......@@ -216,6 +233,7 @@ class DioUtil {
: response.data[_codeKey];
_msg = response.data[_msgKey];
_data = response.data[_dataKey];
_extra = response.data[_extraKey];
} else {
Map<String, dynamic> _dataMap = _decodeData(response);
_status = (_dataMap[_statusKey] is int)
......@@ -226,8 +244,10 @@ class DioUtil {
: _dataMap[_codeKey];
_msg = _dataMap[_msgKey];
_data = _dataMap[_dataKey];
_extra = response.data[_extraKey];
_userType = response.data[_userType];
}
return new BaseResp(_status, _code, _msg, _data);
return new BaseResp(_status, _code, _msg, _data, _extra, _userType);
} catch (e) {
return new Future.error(new DioError(
response: response,
......@@ -260,6 +280,10 @@ class DioUtil {
int _code;
String _msg;
T _data;
T _extra;
T _userType;
print('打印http response');
print(response);
if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) {
try {
......@@ -282,8 +306,10 @@ class DioUtil {
: _dataMap[_codeKey];
_msg = _dataMap[_msgKey];
_data = _dataMap[_dataKey];
_extra = response.data[_extraKey];
_userType = response.data[_userType];
}
return new BaseRespR(_status, _code, _msg, _data, response);
return new BaseRespR(_status, _code, _msg, _data, _extra, _userType, response);
} catch (e) {
return new Future.error(new DioError(
response: response,
......@@ -328,8 +354,6 @@ class DioUtil {
/// check Options.
Options _checkOptions(method, options) {
print('_checkOptionsAAAA');
print(options);
if (options == null) {
options = new Options();
}
......@@ -351,6 +375,14 @@ class DioUtil {
_options.followRedirects = opt.followRedirects ?? _options.followRedirects;
}
void _mergeNativeCookie(HttpConfig config) {
//合并native cookie
_options.headers = (new Map.from(_options.headers))..addAll(config.nativeCookie);
print('cookie---------');
print(_options.headers);
}
/// print Http Log.
void _printHttpLog(Response response) {
if (!_isDebug) {
......
......@@ -47,10 +47,6 @@ class _WidgetAState extends State<WidgetA> {
child: Column(
children: <Widget>[
Center(
<<<<<<< HEAD
// child1: Text('data'),
=======
>>>>>>> dev
child: FlatButton(
child: Text('hit me'),
onPressed: (){
......
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