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.
316 lines
11 KiB
316 lines
11 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:huixiang/generated/l10n.dart'; |
|
import 'package:huixiang/data/base_data.dart'; |
|
import 'package:huixiang/data/message.dart'; |
|
import 'package:huixiang/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_footer.dart'; |
|
import 'package:huixiang/view_widget/no_data_view.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
class SystemNotice extends StatefulWidget { |
|
@override |
|
State<StatefulWidget> createState() { |
|
return _SystemNotice(); |
|
} |
|
} |
|
|
|
class _SystemNotice extends State<SystemNotice> { |
|
ApiService? apiService; |
|
int pageNum = 1; |
|
List<Message> messages = []; |
|
int msgType = 0; |
|
|
|
// String parenId = "0"; |
|
var commentFocus = FocusNode(); |
|
String hintText = S.current.liuxianinjingcaidepinglunba; |
|
bool isKeyBoardShow = false; |
|
final GlobalKey commentKey = GlobalKey(); |
|
final GlobalKey inputKey = GlobalKey(); |
|
final TextEditingController commentTextController = TextEditingController(); |
|
int indexMsg = 0; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
// msgType = widget.arguments["msgType"]; |
|
|
|
SharedPreferences.getInstance().then((value) { |
|
apiService = |
|
ApiService(Dio(), token: value.getString("token"), context: context); |
|
queryMessage(); |
|
}); |
|
} |
|
|
|
_refresh() { |
|
pageNum = 1; |
|
queryMessage(); |
|
} |
|
|
|
queryMessage() async { |
|
BaseData<PageInfo<Message>>? baseData = await apiService?.msgList({ |
|
"pageNum": pageNum, |
|
"pageSize": 10, |
|
"searchKey": "", |
|
"state": "", |
|
"typed": "" |
|
}).catchError((onError) { |
|
_refreshController.loadFailed(); |
|
_refreshController.refreshFailed(); |
|
}); |
|
|
|
if (baseData?.isSuccess ?? false) { |
|
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); |
|
} |
|
}); |
|
_refreshController.loadComplete(); |
|
_refreshController.refreshCompleted(); |
|
if (mounted) setState(() {}); |
|
if (pageNum * 10 > (int.tryParse("${baseData?.data?.total}") ?? 0)) { |
|
_refreshController.loadNoData(); |
|
} else { |
|
pageNum += 1; |
|
} |
|
} else { |
|
_refreshController.loadFailed(); |
|
_refreshController.refreshFailed(); |
|
} |
|
} |
|
|
|
RefreshController _refreshController = RefreshController(); |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
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); |
|
}, |
|
), |
|
controller: _refreshController, |
|
onRefresh: _refresh, |
|
onLoading: () { |
|
queryMessage(); |
|
}, |
|
child: Container( |
|
child: SingleChildScrollView( |
|
physics: BouncingScrollPhysics(), |
|
child: Container( |
|
child: Column( |
|
children: [ |
|
Container( |
|
color: Colors.white, |
|
padding: EdgeInsets.only( |
|
top: MediaQuery.of(context).padding.top + 10.h, |
|
bottom: 10.h, |
|
right: 16.w), |
|
child: Row( |
|
children: [ |
|
GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
child: Container( |
|
alignment: Alignment.centerRight, |
|
margin: EdgeInsets.only( |
|
left: 12, |
|
), |
|
padding: EdgeInsets.all(6), |
|
child: Icon( |
|
Icons.arrow_back_ios, |
|
color: Colors.black, |
|
size: 24, |
|
), |
|
), |
|
), |
|
Text( |
|
"消息通知", |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontSize: 18.sp, |
|
fontWeight: MyFontWeight.bold, |
|
), |
|
), |
|
], |
|
), |
|
), |
|
buildMessage() |
|
], |
|
), |
|
), |
|
), |
|
), |
|
), |
|
); |
|
} |
|
|
|
Widget buildMessage() { |
|
return Container( |
|
color: Colors.white, |
|
width: double.infinity, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
(messages.length == 0) |
|
? NoDataView( |
|
src: "assets/image/icon_empty.webp", |
|
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( |
|
behavior: HitTestBehavior.opaque, |
|
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, left: 16.w, right: 17.w), |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Row( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Image.asset( |
|
(message.typed == 1) |
|
? "assets/image/icon_order.webp" |
|
: (message.typed == 2) |
|
? "assets/image/icon_order.webp" |
|
: "assets/image/icon_cz.webp", |
|
width: 24.w, |
|
height: 24.h, |
|
), |
|
SizedBox( |
|
width: 8.w, |
|
), |
|
Expanded( |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
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: 24.h, |
|
), |
|
(message.typed != 3) |
|
? Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
// crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Expanded( |
|
child: Text( |
|
S.of(context).ninyouyigexindedingdan, |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
), |
|
Icon( |
|
Icons.keyboard_arrow_right, |
|
size: 24, |
|
), |
|
], |
|
) |
|
: Row( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.end, |
|
children: [ |
|
Expanded( |
|
child: Text( |
|
message.content ?? "", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF353535), |
|
), |
|
), |
|
), |
|
Icon( |
|
Icons.keyboard_arrow_right, |
|
size: 24, |
|
), |
|
], |
|
), |
|
Container( |
|
margin: EdgeInsets.only(top: 16.h, bottom: 8.h), |
|
height: 1.h, |
|
width: double.infinity, |
|
color: Color(0xFFF7F7F7), |
|
), |
|
], |
|
), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
); |
|
} |
|
}
|
|
|