Commit 34109a02 authored by 林生雨's avatar 林生雨

commit

parent 396c9647
......@@ -21,7 +21,7 @@ class ReputationsModel extends BaseModel {
init(BuildContext context) {
Map<String, dynamic> headMap = new Map();
headMap.putIfAbsent("Cookie", () => cookie);
DioUtil().addHead = headMap;
DioUtil.addHeadMap=headMap;
PrestigeRepository.getInstance().getReputations().listen((value) {
if (value != null) {
prestigeLive.notifyView(value);
......
......@@ -24,21 +24,23 @@ class ReputationsState extends State<ReputationsPage> {
ReputationsState(this._model);
@override
void initState() {
super.initState();
_model.init(context);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'我的专家声望',
style: TextStyle(fontSize: 16),
),
title: MyText(16, '我的专家声望', 0xff323232),
centerTitle: true,
leading: IconButton(
// alignment: Alignment.centerLeft,
onPressed: () => Navigator.pop(context),
// padding: EdgeInsets.fromLTRB(22, 0, 0, 0),
icon: Icon(
Icons.keyboard_arrow_left,
size: 30,
),
)),
body: StreamBuilder<PrestigeEntity>(
......@@ -51,23 +53,33 @@ class ReputationsState extends State<ReputationsPage> {
if (data.data.error != 0 || data.data.data == null) {
return errorItem(data.data.message);
}
return Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(17, 24, 0, 0),
child: MyText(
16.0, data.data.data.introduce[0].question, 0xff323232),
),
Container(
margin: EdgeInsets.fromLTRB(19, 16, 0, 0),
child: MyText(
13.0, data.data.data.introduce[0].answer, 0xff8E8E8E),
),
ListView.builder(
itemCount: data.data.data.reputations.length,
itemBuilder: (context, index) {
return listItem(data, index);
}),
return CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
if (index == 0) {
return Container(
margin: EdgeInsets.fromLTRB(17, 24, 17, 0),
child: MyText(16.0, data.data.data.introduce[0].question,
0xff323232),
);
}
if (index == 1) {
return Container(
margin: EdgeInsets.fromLTRB(19, 16, 19, 32),
child: MyText(
13.0, data.data.data.introduce[0].answer, 0xff8E8E8E),
);
}
if (index == data.data.data.reputations.length + 2) {
//bottom margin
return Container(
height: 20,
);
}
return listItem(data, index - 2);
}, childCount: data.data.data.reputations.length + 3)),
],
);
},
......@@ -75,25 +87,40 @@ class ReputationsState extends State<ReputationsPage> {
}
Widget listItem(AsyncSnapshot<PrestigeEntity> data, int index) {
int allSize = data.data.data.reputations[index].expertTags.length;
var item = data.data.data.reputations[index];
int allSize;
int bringSize = 0;
for (var item in data.data.data.reputations[index].expertTags) {
if (item.level > 0) {
bringSize++;
if (item.expertTags == null) {
allSize = 0;
bringSize = 0;
} else {
allSize = item.expertTags.length;
for (var item in item.expertTags) {
if (item.level > 0) {
bringSize = bringSize + 1;
}
}
}
double itemHeight = 154.0;
// int col = (allSize / 3).ceil();
// print("size $col");
// double allHeight;
// if (col == 0) {
// allHeight = 30;
// } else {
// allHeight = itemHeight * col;
// }
return Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(0, 32, 0, 0),
color: Color(0xffDADADA),
width: double.maxFinite,
height: 30,
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(16, 0, 0, 0),
child: MyText(14.0, data.data.data.reputations[index].category,
0xffffffff),
child: MyText(14.0, item.category, 0xffffffff),
),
Expanded(
child: Container(),
......@@ -106,26 +133,51 @@ class ReputationsState extends State<ReputationsPage> {
),
),
GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, mainAxisSpacing: 4, crossAxisSpacing: 10.0),
itemBuilder: (context, gridIndex) {
var item =
data.data.data.reputations[index].expertTags[gridIndex];
bool isBright = item.level > 0;
return Column(
children: <Widget>[
isBright
? CachedNetworkImage(imageUrl: item.lightBadge)
: CachedNetworkImage(imageUrl: item.grayBadge),
Container(
margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
physics: new NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: allSize,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
),
itemBuilder: (context, gridIndex) {
if (item.expertTags == null) {
return Container();
}
bool isBright = item.expertTags[gridIndex].level > 0;
return Container(
height: itemHeight,
child: Column(
children: <Widget>[
Expanded(
child: Container(),
),
Container(
height: 80,
width: 80,
child: isBright
? MyText(13.0, "Lv${item.level} ${item.tagName}",
0xff8E8E8E)
: MyText(13.0, "${item.tagName}", 0xffC4C4C4))
],
);
})
? CachedNetworkImage(
imageUrl: item.expertTags[gridIndex].lightBadge)
: CachedNetworkImage(
imageUrl: item.expertTags[gridIndex].grayBadge),
),
Container(
margin: EdgeInsets.fromLTRB(0, 5, 0, 0),
child: isBright
? MyText(
13.0,
"Lv${item.expertTags[gridIndex].level} ${item.expertTags[gridIndex].tagName}",
0xff8E8E8E)
: MyText(
13.0,
"${item.expertTags[gridIndex].tagName}",
0xffC4C4C4)),
Expanded(
child: Container(),
)
],
));
},
)
],
);
}
......@@ -137,7 +189,9 @@ class ReputationsState extends State<ReputationsPage> {
}
Widget loadingItem() {
return CircularProgressIndicator();
return Center(
child: CircularProgressIndicator(),
);
}
Text MyText(double size, String text, int color) {
......
......@@ -177,23 +177,23 @@ class _CommentSuggestPageState extends State<CommentSuggestPage> {
DioUtil().setConfig(config);
String content = (this.opinionCtrl.text.length > 0)? this.opinionCtrl.text : '';
String phone = (this.telCtrl.text.length > 0)? this.telCtrl.text : '';
DioUtil().requestR(Method.post, "api/v1/suggestion",data: {"content": content, "phone": phone}).then((res){
if (res.code == 0) {
Toast.show(context, '提交成功');
FlutterBoost.singleton.closePageForContext(context);
} else {
Toast.show(context, res.msg);
}
}
).then((error){
if (error != null) {
Toast.show(context, '提交失败');
print(error);
} else {
// FlutterBoost.singleton.closePageForContext(context);
}
});
// DioUtil().requestR(Method.post, "api/v1/suggestion",data: {"content": content, "phone": phone}).then((res){
// if (res.code == 0) {
// Toast.show(context, '提交成功');
// FlutterBoost.singleton.closePageForContext(context);
// } else {
// Toast.show(context, res.msg);
// }
// }
// ).then((error){
// if (error != null) {
// Toast.show(context, '提交失败');
// print(error);
// } else {
// // FlutterBoost.singleton.closePageForContext(context);
// }
//
// });
}
}
......
......@@ -157,7 +157,7 @@ class DioUtil {
String _proxy = '172.30.9.117:8888';
Map<String, dynamic> addHeadMap;
static Map<String, dynamic> addHeadMap ;
/// 是否是debug模式.
static bool _isDebug = !inProduction;
......@@ -170,40 +170,24 @@ class DioUtil {
return _instance;
}
static var interceptor = InterceptorsWrapper(onRequest: (opt) {
var headers = opt.headers;
if (addHeadMap != null) {
print("请求之前");
addHeadMap.forEach((k, v) {
headers.putIfAbsent(k, () => v);
print("HEADDD ${k} ${v}");
});
}
}, onResponse: (response) {
print("相应之前");
}, onError: (e) {
print("网络错误 $e");
});
DioUtil._init() {
_dio = new Dio(_options);
initDeviceInfo().then((value) {
_dio.interceptors
.add(InterceptorsWrapper(onRequest: (RequestOptions options) {
//TODO fix it
var queryParameters = options.queryParameters;
queryParameters.putIfAbsent("app_name", () => value.packageName);
queryParameters.putIfAbsent("version", () => value.version);
queryParameters.putIfAbsent(
"platform", () => Platform.isIOS ? "ios" : "android");
var headers = options.headers;
if (addHeadMap != null) {
addHeadMap.forEach((k, v) {
headers.putIfAbsent(k, () => v);
});
}
print("请求之前");
// Do something before request is sent
return options; //continue
}, onResponse: (Response response) {
print("响应之前");
// Do something with response data
return response; // continue
}, onError: (DioError e) {
print("错误之前");
// Do something with response error
return e; //continue
}));
}).catchError((error) {
print(error);
});
//TODO
_dio.interceptors.add(interceptor);
}
set addHead(Map<String, dynamic> map) {
......@@ -339,142 +323,6 @@ class DioUtil {
}
}
/// Make http request with options.
/// [method] The request method.
/// [path] The url path.
/// [data] The request data
/// [options] The request options.
/// Map<String, dynamic> queryParameters,
/// <BaseResp<T> 返回 status code msg data .
Future<BaseResp<T>> request<T>(String method, String path,
{Map<String, dynamic> queryParameters,
data,
Options options,
CancelToken cancelToken}) async {
// _dio.request(path, que)
// _dio.request(path, )
Response response = await _dio.request(path,
data: data,
queryParameters: queryParameters,
options: _checkOptions(method, options),
cancelToken: cancelToken);
_printHttpLog(response);
String _status;
int _code;
String _msg;
T _data;
T _extra;
T _userType;
_status = response.statusCode.toString();
if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) {
try {
if (response.data is Map) {
_code = (response.data[_codeKey] is String)
? int.tryParse(response.data[_codeKey])
: response.data[_codeKey];
_msg = response.data[_msgKey];
_data = response.data[_dataKey];
_extra = response.data[_extraKey];
} else {
Map<String, dynamic> _dataMap = _decodeData(response);
_code = (_dataMap[_codeKey] is String)
? int.tryParse(_dataMap[_codeKey])
: _dataMap[_codeKey];
_msg = _dataMap[_msgKey];
_data = _dataMap[_dataKey];
_extra = response.data[_extraKey];
_userType = response.data[_userType];
}
print(
"------ MSG ${_msg} DATA ${_data} EXTRA${_extra} USERTYPE${_userType}");
return new BaseResp(_status, _code, _msg, _data, _extra, _userType);
} catch (e) {
return new Future.error(new DioError(
response: response,
message: "data parsing exception...",
type: DioErrorType.RESPONSE,
));
}
}
return new Future.error(new DioError(
response: response,
message: "statusCode: $response.statusCode, service error",
type: DioErrorType.RESPONSE,
));
}
/// Make http request with options.
/// [method] The request method.
/// [path] The url path.
/// [data] The request data
/// [options] The request options.
/// <BaseRespR<T> 返回 status code msg data Response.
Future<BaseRespR<T>> requestR<T>(String method, String path,
{Map<String, dynamic> queryParameters,
data,
Options options,
CancelToken cancelToken}) async {
// _dio.request(path,queryParameters: )
Response response = await _dio.request(path,
data: data,
queryParameters: queryParameters,
options: _checkOptions(method, options),
cancelToken: cancelToken);
_printHttpLog(response);
String _status;
int _code;
String _msg;
T _data;
T _extra;
T _userType;
_status = response.statusCode.toString();
if (response.statusCode == HttpStatus.ok ||
response.statusCode == HttpStatus.created) {
try {
if (response.data is Map) {
_code = (response.data[_codeKey] is String)
? int.tryParse(response.data[_codeKey])
: response.data[_codeKey];
_msg = response.data[_msgKey];
_data = response.data[_dataKey];
} else {
Map<String, dynamic> _dataMap = _decodeData(response);
_code = (_dataMap[_codeKey] is String)
? int.tryParse(_dataMap[_codeKey])
: _dataMap[_codeKey];
_msg = _dataMap[_msgKey];
_data = _dataMap[_dataKey];
_extra = response.data[_extraKey];
_userType = response.data[_userType];
}
return new BaseRespR(
_status, _code, _msg, _data, _extra, _userType, response);
} catch (e) {
return new Future.error(new DioError(
response: response,
message: "data parsing exception...",
type: DioErrorType.RESPONSE,
));
}
} else {
_code = 1;
_msg = '请求失败';
}
return new Future.error(new DioError(
response: response,
message: "statusCode: $response.statusCode, service error",
type: DioErrorType.RESPONSE,
));
}
/// Download the file and save it in local. The default http method is "GET",you can custom it by [Options.method].
/// [urlPath]: The file url.
/// [savePath]: The path to save the downloading file later.
/// [onProgress]: The callback to listen downloading progress.please refer to [OnDownloadProgress].
Future<Response> download(
String urlPath,
savePath, {
......@@ -614,4 +462,5 @@ class DioUtil {
options.headers = headers;
return options;
}
}
......@@ -65,51 +65,51 @@ class _MessageHomePageState extends State<MessageHomePage> {
}
Future<List<ListItem>> _fetchMesssageList() async {
List<Message> messageList = List<Message>();
BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/reply/my", queryParameters: {'page': pageIndex, 'count': 10});
if (baseresp.code != 0) {
return new Future.error(baseresp.msg);
}
if (baseresp.data != null) {
messageList = baseresp.data.map((value) {
return Message.fromJson(value);
}).toList();
}
// List<Message> messageList = List<Message>();
// BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/reply/my", queryParameters: {'page': pageIndex, 'count': 10});
// if (baseresp.code != 0) {
// return new Future.error(baseresp.msg);
// }
//
// if (baseresp.data != null) {
// messageList = baseresp.data.map((value) {
// return Message.fromJson(value);
// }).toList();
// }
_refreshController.refreshCompleted();
return messageList;
}
Future<List<ListItem>> _fetchNewestInfo() async {
List<ListItem> notiData = List<ListItem>();
BaseRespR noteResp = await DioUtil().requestR(Method.get, 'api/v1/push/newest/info');
Map noteData = noteResp.data;
String noteContent = noteData['content'];
NotificationItem noteItem = NotificationItem('images/message_noti.png', noteContent, 0, '通知');
notiData.add(noteItem);
BaseRespR likeResp = await DioUtil().requestR(Method.get, 'api/v1/message/unread',queryParameters: {'type': 0});
print(likeResp);
Map likeData = likeResp.data;
String likeContent = '';
NotificationItem likeItem = NotificationItem('images/message_like.png', likeContent, likeData['count'], 'Like');
if (likeItem.count > 0) {
likeItem.content = '有${likeItem.count}个人Like了你';
} else {
likeItem.content = '还没有人给你Like哦~';
}
notiData.add(likeItem);
BaseRespR attentionResp = await DioUtil().requestR(Method.get, 'api/v1/message/unread',queryParameters: {'type': 1});
Map attData = attentionResp.data;
String attContent = '';
NotificationItem attItem = NotificationItem('images/message_att.png', attContent, attData['count'], '关注');
if (attItem.count > 0) {
attItem.content = '有${attItem.count}个人关注了你';
} else {
attContent = '还没有人给你关注哦~';
}
notiData.add(attItem);
// BaseRespR noteResp = await DioUtil().requestR(Method.get, 'api/v1/push/newest/info');
// Map noteData = noteResp.data;
// String noteContent = noteData['content'];
// NotificationItem noteItem = NotificationItem('images/message_noti.png', noteContent, 0, '通知');
// notiData.add(noteItem);
//
// BaseRespR likeResp = await DioUtil().requestR(Method.get, 'api/v1/message/unread',queryParameters: {'type': 0});
// print(likeResp);
// Map likeData = likeResp.data;
// String likeContent = '';
// NotificationItem likeItem = NotificationItem('images/message_like.png', likeContent, likeData['count'], 'Like');
// if (likeItem.count > 0) {
// likeItem.content = '有${likeItem.count}个人Like了你';
// } else {
// likeItem.content = '还没有人给你Like哦~';
// }
// notiData.add(likeItem);
// BaseRespR attentionResp = await DioUtil().requestR(Method.get, 'api/v1/message/unread',queryParameters: {'type': 1});
// Map attData = attentionResp.data;
// String attContent = '';
// NotificationItem attItem = NotificationItem('images/message_att.png', attContent, attData['count'], '关注');
// if (attItem.count > 0) {
// attItem.content = '有${attItem.count}个人关注了你';
// } else {
// attContent = '还没有人给你关注哦~';
// }
// notiData.add(attItem);
// this.dataArr = dataArr;
return notiData;
}
......
......@@ -44,16 +44,16 @@ class _NotificationListState extends State<NotificationList> {
Future<List<ListItem>> _fetchMesssageList() async {
List<NotificationModel> messageList = List<NotificationModel>();
BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/message/notice", queryParameters: {'page': pageIndex, 'count': 10});
if (baseresp.code != 0) {
return new Future.error(baseresp.msg);
}
if (baseresp.data != null) {
messageList = baseresp.data.map((value) {
return NotificationModel.fromJson(value);
}).toList();
}
// BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/message/notice", queryParameters: {'page': pageIndex, 'count': 10});
// if (baseresp.code != 0) {
// return new Future.error(baseresp.msg);
// }
//
// if (baseresp.data != null) {
// messageList = baseresp.data.map((value) {
// return NotificationModel.fromJson(value);
// }).toList();
// }
_refreshController.refreshCompleted();
return messageList;
}
......
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