You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

651 lines
22 KiB

4 years ago
import 'package:dio/dio.dart';
4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/message.dart';
import 'package:huixiang/retrofit/data/msg_stats.dart';
4 years ago
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/my_footer.dart';
4 years ago
import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:huixiang/view_widget/round_button.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
class SystemMessagePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _SystemMessagePage();
}
}
class _SystemMessagePage extends State<SystemMessagePage> {
4 years ago
ApiService apiService;
int pageNum = 1;
List<Message> messages = [];
List<MsgStats> msgStats = [];
Map <String,int> msgNumber = {
"1":0,
"2":0,
"3":0,
"4":0,
"5":0,
"6":0,
};
int state = 0;
4 years ago
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) {
apiService =
ApiService(Dio(), token: value.getString("token"), context: context);
queryMessage();
queryMsgStats();
4 years ago
});
}
_refresh() {
pageNum = 1;
queryMessage();
queryMsgStats();
4 years ago
}
queryMessage() async {
3 years ago
BaseData<PageInfo<Message>> baseData = await apiService.msgList({
4 years ago
"pageNum": pageNum,
"pageSize": 10,
"searchKey": "",
"state": "",
"typed": ""
}).catchError((onError) {
_refreshController.loadFailed();
_refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
if (pageNum == 1) {
messages.clear();
}
List<Message> message = [];
message.addAll(baseData.data.list);
message.forEach((element) {
if(element.typed==2 || element.typed==3){
messages.add(element);
}
});
4 years ago
_refreshController.loadComplete();
_refreshController.refreshCompleted();
4 years ago
if (mounted) setState(() {});
3 years ago
if (pageNum * 10 > int.tryParse(baseData.data.total)) {
4 years ago
_refreshController.loadNoData();
} else {
pageNum += 1;
}
} else {
_refreshController.loadFailed();
_refreshController.refreshFailed();
}
}
queryMsgStats() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
}
BaseData<List<MsgStats>> baseData = await apiService.stats().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
msgStats.clear();
msgStats = baseData.data;
msgStats.forEach((element) {
if(msgNumber.containsKey(element.name)){
msgNumber[element.name] = element.number;
}
});
});
_refreshController.loadComplete();
_refreshController.refreshCompleted();
}
EasyLoading.dismiss();
}
4 years ago
RefreshController _refreshController = RefreshController();
4 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
4 years ago
appBar: MyAppBar(
background: Colors.white,
4 years ago
leadingColor: Colors.black,
title: S.of(context).xiaoxi,
4 years ago
titleSize: 18.sp,
titleColor: Colors.black,
actions: [
Container(
margin: EdgeInsets.only(right: 16.w),
alignment: Alignment.centerRight,
child: GestureDetector(
onTap: () {
setState(() {
queryMsgStats();
});
},
child: Text(
"标为已读",
style: TextStyle(
fontSize: 16.sp,
fontWeight:MyFontWeight.semi_bold,
color: Color(0xFF353535),
),
),
),
),
],
4 years ago
),
body: SmartRefresher(
enablePullDown: true,
enablePullUp: true,
header: MyHeader(),
physics: BouncingScrollPhysics(),
footer: CustomFooter(
loadStyle: LoadStyle.ShowWhenLoading,
builder: (BuildContext context, LoadStatus mode) {
return (messages.length == 0)?Container():MyFooter(mode);
4 years ago
},
),
4 years ago
controller: _refreshController,
onRefresh: _refresh,
onLoading: () {
setState(() {
_refresh();
});
4 years ago
},
child: Container(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Container(
child: Column(
children: [
newsSurvey(),
SizedBox(height: 16.h,),
buildMessage(),
],
),
),
),
),
4 years ago
),
);
}
Widget newsSurvey(){
4 years ago
return Container(
color: Colors.white,
padding: EdgeInsets.only(top: 16.h,bottom: 16.h),
child: Row(
4 years ago
children: [
Expanded(child: GestureDetector(
onTap: (){
Navigator.of(context)
.pushNamed('/router/system_details',arguments: {"msgType":5});
},
child:Column(
children: [
Stack(
children: [
Image.asset(
"assets/image/icon_z.png",
width: 40,
height: 40,
),
if(msgNumber["5"].toString() != "0")
Container(
width:48,
alignment: Alignment.topRight,
child:Container(
width:20,
height:17,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(
width: 1,
color: Colors.white,
style: BorderStyle.solid,
),
color:Color(0xFFFF441A),
),
child:RoundButton(
text:msgNumber["5"].toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize:8.sp,
radius: 100,
)
),
)
],
),
SizedBox(height: 6.h),
Text(
"点赞",
style: TextStyle(
fontSize: 14.sp,
fontWeight:MyFontWeight.medium,
color: Color(0xFF060606),
4 years ago
),
)
],
)
)
),
Expanded(child:
GestureDetector(
onTap: (){
Navigator.of(context)
.pushNamed('/router/system_details',arguments: {"msgType":6});
},
child: Column(
children: [
Stack(
children: [
Image.asset(
"assets/image/icon_pl.png",
width: 40,
height: 40,
),
if(msgNumber["6"].toString() != "0")
Container(
width:48,
alignment: Alignment.topRight,
child:Container(
width:16,
height:16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(
width: 1,
color: Colors.white,
style: BorderStyle.solid,
),
color:Color(0xFFFF441A),
),
child:RoundButton(
text: msgNumber["6"].toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize:8.sp,
radius: 100,
)
),
)
],
4 years ago
),
SizedBox(height: 6.h),
Text(
S.of(context).pinglun,
style: TextStyle(
fontSize: 14.sp,
fontWeight:MyFontWeight.medium,
color: Color(0xFF060606),
),
),
],
)
)),
Expanded(child:
GestureDetector(
onTap: (){
Navigator.of(context)
.pushNamed('/router/system_details',arguments: {"msgType":4});
},
child:Column(
children: [
Stack(
children: [
Image.asset(
"assets/image/icon_gz.png",
width: 40,
height: 40,
),
if(msgNumber["4"].toString() != "0")
Container(
width:48,
alignment: Alignment.topRight,
child:Container(
width:16,
height:16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(
width: 1,
color: Colors.white,
style: BorderStyle.solid,
),
color:Color(0xFFFF441A),
),
child:RoundButton(
text: msgNumber["4"].toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize:8.sp,
radius: 100,
)
),
)
],
),
SizedBox(height: 6.h),
Text(
S.of(context).guanzhu,
style: TextStyle(
fontSize: 14.sp,
fontWeight:MyFontWeight.medium,
color: Color(0xFF060606),
),
),
],
)
)
),
],
),
);
}
Widget buildMessage(){
return Container(
color: Colors.white,
width: double.infinity,
padding: EdgeInsets.all(20.w),
child:Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
S.of(context).xitongxiaoxi,
style: TextStyle(
fontSize: 16.sp,
fontWeight:MyFontWeight.semi_bold,
color: Colors.black,
4 years ago
),
),
(messages == null || messages.length == 0)
? NoDataView(
isShowBtn: false,
text: S.of(context).haimeiyouxiaoxi,
fontSize: 16.sp,
margin: EdgeInsets.only(top: 120.h),
)
:ListView.builder(
padding: EdgeInsets.only(top: 16),
itemCount: messages.length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, position) {
return GestureDetector(
onTap: () {
if(messages[position].typed == 2)
Navigator.of(context)
.pushNamed('/router/system_details',arguments: {"msgType":2});
else if(messages[position].typed == 3)
Navigator.of(context)
.pushNamed('/router/system_details',arguments: {"msgType":3});
},
child: buildMessageItem(messages[position]),
);
}),
],
)
);
}
Widget buildMessageItem(Message message) {
return Container(
margin: EdgeInsets.only(top: 8.h, bottom: 8.h),
// margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 8.h, bottom: 8.h),
// padding: EdgeInsets.all(20.w),
// decoration: BoxDecoration(
// color: Colors.white,
// boxShadow: [
// BoxShadow(
// color: Colors.black.withAlpha(12),
// offset: Offset(0, 3),
// blurRadius: 14,
// spreadRadius: 0,
// )
// ],
// borderRadius: BorderRadius.circular(8),
// ),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset(
(message.typed == 1)
? "assets/image/icon_system_message.png"
: (message.typed == 2)
? "assets/image/icon_system_message.png"
: "assets/image/c_z.png",
width: 40.w,
height: 40.h,
),
SizedBox(
width:12.w,
),
Expanded(child:Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
4 years ago
children: [
Row(
children: [
Expanded(child:Text(
(message.typed == 1)
? S.of(context).xitongtongzhi
: (message.typed == 2)
? S.of(context).dingdanxiaoxi
: S.of(context).chongzhixiaoxi,
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF060606),
),
)),
Text(
message.updateTime,
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFFA29E9E),
),
),
],
),
SizedBox(height:4.h,),
(message.typed != 3) ?
Row(
mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child:
Text(
S.of(context).ninyouyigexindedingdan,
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF353535),
),
),),
if(msgNumber["2"].toString() != "0")
RoundButton(
width: 16,
height: 16,
text:msgNumber["2"].toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize:10.sp,
radius: 100,
),
],
):
Row(
mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child:
Text(
message.content,
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFF353535),
),
)),
if(msgNumber["3"].toString() != "0")
RoundButton(
width: 16,
height: 16,
text:msgNumber["3"].toString(),
textColor: Colors.white,
fontWeight: MyFontWeight.regular,
backgroup: Color(0xFFFF441A),
fontSize:10.sp,
radius: 100,
),
],
4 years ago
),
],
)),
],
),
Container(
margin: EdgeInsets.only(top: 16.h,bottom:8.h),
height: 1.h,
width: double.infinity,
color: Color(0xFFF7F7F7),
),
4 years ago
],
),
// Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Row(
// children: [
// Image.asset(
// (message.typed == 1)
// ? "assets/image/icon_system_notices.png"
// : (message.typed == 2)
// ? "assets/image/icon_system_order.png"
// : "assets/image/icon_system_recharge.png",
// width: 24.w,
// height: 24.h,
// ),
// SizedBox(
// width: 4.w,
// ),
// Text(
// (message.typed == 1)
// ? S.of(context).xitongtongzhi
// : (message.typed == 2)
// ? S.of(context).dingdanxiaoxi
// : S.of(context).chongzhixiaoxi,
// style: TextStyle(
// fontSize: 14.sp,
// fontWeight: FontWeight.bold,
// color: Color(0xFF060606),
// ),
// )
// ],
// ),
// Text(
// message.updateTime,
// style: TextStyle(
// fontSize: 10.sp,
// color: Color(0xFFA29E9E),
// ),
// ),
// ],
// ),
// if (message.typed != 3)
// Container(
// margin: EdgeInsets.only(left: 28.w, top: 12.h),
// child: Text(
// S.of(context).ninyouyigexindedingdan,
// style: TextStyle(
// fontSize: 10.sp,
// color: Color(0xFF353535),
// ),
// ),
// )
// else
// Container(
// margin: EdgeInsets.only(left: 28.w, top: 18.h),
// child: Text(
// message.title,
// style: TextStyle(
// fontSize: 20.sp,
// fontWeight: MyFontWeight.semi_bold,
// color: Color(0xFF353535),
// ),
// ),
// ),
// if (message.typed != 3)
// Container(
// margin: EdgeInsets.only(left: 28.w, top: 22.h),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: [
// Text(
// S.of(context).chakangengduo,
// style: TextStyle(
// fontSize: 12.sp,
// fontWeight: FontWeight.bold,
// color: Color(0xFF353535),
// ),
// ),
// Icon(
// Icons.keyboard_arrow_right,
// color: Colors.black,
// )
// ],
// ),
// )
// else
// Container(
// margin: EdgeInsets.only(left: 28.w, top: 22.h),
// child: Text(
// message.content,
// style: TextStyle(
// fontSize: 10.sp,
// color: Color(0xFF353535),
// ),
// ),
// ),
// ],
// ),
4 years ago
);
}
}