Commit f5f15dff authored by jinzhu's avatar jinzhu

update comment_suggest

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