265 lines
9.3 KiB
Dart
Executable File
265 lines
9.3 KiB
Dart
Executable File
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/mine/message/messageList/messageList_state.dart';
|
|
import 'package:star_lock/tools/noData.dart';
|
|
|
|
import '../../../appRouters.dart';
|
|
import '../../../app_settings/app_colors.dart';
|
|
import '../../../tools/EasyRefreshTool.dart';
|
|
import '../../../tools/dateTool.dart';
|
|
import '../../../tools/showTipView.dart';
|
|
import '../../../tools/storage.dart';
|
|
import 'messageList_entity.dart';
|
|
import 'messageList_logic.dart';
|
|
|
|
class MessageListXHJPage extends StatefulWidget {
|
|
MessageListXHJPage({Key? key, this.showAppBar = true}) : super(key: key);
|
|
bool showAppBar;
|
|
|
|
@override
|
|
State<MessageListXHJPage> createState() => _MessageListXHJPageState();
|
|
}
|
|
|
|
class _MessageListXHJPageState extends State<MessageListXHJPage>
|
|
with TickerProviderStateMixin ,AutomaticKeepAliveClientMixin {
|
|
final MessageListLogic logic = Get.put(MessageListLogic());
|
|
final MessageListState state = Get.find<MessageListLogic>().state;
|
|
|
|
void getHttpData() {
|
|
logic.messageListDataRequest().then((MessageListEntity value) {
|
|
if (mounted) {
|
|
setState(() {});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
getHttpData();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: null,
|
|
body: Column(
|
|
children: <Widget>[
|
|
SizedBox(
|
|
height: 15.h,
|
|
),
|
|
Container(
|
|
width: 1.sw,
|
|
height: 0.2.sw,
|
|
margin: EdgeInsets.symmetric(horizontal: 15.w),
|
|
padding: EdgeInsets.symmetric(horizontal: 25.w),
|
|
decoration: BoxDecoration(
|
|
image: const DecorationImage(
|
|
image: AssetImage('images/xhj_main_bg.jpg'),
|
|
fit: BoxFit.cover,
|
|
),
|
|
borderRadius: BorderRadius.circular(20.r),
|
|
boxShadow: <BoxShadow>[
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.15),
|
|
offset: const Offset(0, 0),
|
|
blurRadius: 10.r,
|
|
spreadRadius: 0,
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text(
|
|
'智能分析'.tr,
|
|
style: TextStyle(
|
|
color: AppColors.blackColor,
|
|
fontSize: 28.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
Text(
|
|
'精准识别设备事件,过滤无效信息'.tr,
|
|
style: TextStyle(
|
|
color: AppColors.blackColor.withOpacity(0.6),
|
|
fontSize: 20.sp,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: EasyRefreshTool(onRefresh: () {
|
|
logic.pageNo = 1;
|
|
getHttpData();
|
|
}, onLoad: () {
|
|
getHttpData();
|
|
}, child: Obx(() {
|
|
return state.itemDataList.isEmpty
|
|
? NoData()
|
|
: SlidableAutoCloseBehavior(
|
|
child: ListView.builder(
|
|
itemCount: state.itemDataList.length,
|
|
padding: EdgeInsets.only(top: 20.h),
|
|
itemBuilder: (BuildContext c, int index) {
|
|
final MessageItemEntity messageItemEntity =
|
|
state.itemDataList[index];
|
|
return Slidable(
|
|
key: ValueKey<String?>(messageItemEntity.id),
|
|
endActionPane: ActionPane(
|
|
extentRatio: 0.2,
|
|
motion: const ScrollMotion(),
|
|
children: <Widget>[
|
|
SlidableAction(
|
|
onPressed: (BuildContext context) {
|
|
logic.deletMessageDataRequest(
|
|
messageItemEntity.id!, () {
|
|
logic.pageNo = 1;
|
|
getHttpData();
|
|
});
|
|
},
|
|
backgroundColor: Colors.red,
|
|
foregroundColor: Colors.white,
|
|
label: '删除'.tr,
|
|
padding:
|
|
EdgeInsets.only(left: 5.w, right: 5.w),
|
|
),
|
|
],
|
|
),
|
|
child: _messageListItem(messageItemEntity, () {
|
|
Get.toNamed(Routers.messageDetailPage,
|
|
arguments: <String, MessageItemEntity>{
|
|
'messageItemEntity': messageItemEntity
|
|
});
|
|
}),
|
|
);
|
|
}),
|
|
);
|
|
})),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
backgroundColor: AppColors.mainColor,
|
|
child: Icon(
|
|
Icons.delete_sweep,
|
|
color: AppColors.blackColor,
|
|
),
|
|
onPressed: () async {
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
ShowTipView().showIosTipWithContentDialog('是否清空?'.tr, () async {
|
|
logic.deletAllMessageDataRequest();
|
|
});
|
|
} else {
|
|
logic.showToast('演示模式'.tr);
|
|
}
|
|
},
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(100.r))),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _messageListItem(
|
|
MessageItemEntity messageItemEntity, Function() action) {
|
|
final bool isNotRead = messageItemEntity.readAt! == 0;
|
|
return GestureDetector(
|
|
onTap: action,
|
|
child: Container(
|
|
margin: EdgeInsets.symmetric(vertical: 12.h, horizontal: 15.w),
|
|
padding: EdgeInsets.symmetric(vertical: 20.h, horizontal: 20.w),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20.w),
|
|
boxShadow: <BoxShadow>[
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.15),
|
|
offset: const Offset(0, 0),
|
|
blurRadius: 10.r,
|
|
spreadRadius: 0,
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
if (isNotRead)
|
|
Stack(
|
|
children: [
|
|
Image.asset(
|
|
'images/news_not_read.png',
|
|
width: 48.r,
|
|
height: 48.r,
|
|
),
|
|
Positioned(
|
|
right: 1.5.r,
|
|
top: 7.r,
|
|
child: Container(
|
|
width: 12.r,
|
|
height: 12.r,
|
|
decoration: const BoxDecoration(
|
|
color: Colors.red, // 小圆点颜色
|
|
shape: BoxShape.circle, // 形状为圆形
|
|
),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
else
|
|
SizedBox(
|
|
width: 48.r,
|
|
height: 48.r,
|
|
child: Center(
|
|
child: Image.asset('images/news_read.png',
|
|
width: 32.r, height: 32.r),
|
|
)),
|
|
SizedBox(width: 15.w),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
messageItemEntity.data!,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.start,
|
|
style: TextStyle(
|
|
fontSize: 22.sp,
|
|
color: messageItemEntity.readAt! == 0
|
|
? AppColors.blackColor
|
|
: AppColors.placeholderTextColor),
|
|
),
|
|
SizedBox(
|
|
height: 5.h,
|
|
),
|
|
Text(
|
|
DateTool().dateToYMDHNString(
|
|
messageItemEntity.createdAt!.toString()),
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
color: messageItemEntity.readAt! == 0
|
|
? AppColors.blackColor
|
|
: AppColors.placeholderTextColor)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
}
|