app-starlock/lib/mine/message/messageList/messageList_page.dart
2024-05-18 09:37:50 +08:00

186 lines
6.5 KiB
Dart
Executable File

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.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 '../../../tools/titleAppBar.dart';
import '../../../translations/trans_lib.dart';
import 'messageList_entity.dart';
import 'messageList_logic.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
class MessageListPage extends StatefulWidget {
MessageListPage({Key? key, this.showAppBar = true}) : super(key: key);
bool showAppBar;
@override
State<MessageListPage> createState() => _MessageListPageState();
}
class _MessageListPageState extends State<MessageListPage>
with TickerProviderStateMixin {
final logic = Get.put(MessageListLogic());
final state = Get.find<MessageListLogic>().state;
void getHttpData() {
logic.messageListDataRequest().then((MessageListEntity value) {
setState(() {});
});
}
@override
void initState() {
super.initState();
getHttpData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: widget.showAppBar
? TitleAppBar(
barTitle: TranslationLoader.lanKeys!.message!.tr,
haveBack: true,
actionsList: [
TextButton(
child: Text(
"清空".tr,
style: TextStyle(color: Colors.white, fontSize: 24.sp),
),
onPressed: () async {
var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
if (isDemoMode == false) {
ShowTipView().showIosTipWithContentDialog("是否清空?".tr, () async {
logic.deletAllMessageDataRequest();
});
} else {
logic.showToast("演示模式".tr);
}
},
),
],
backgroundColor: AppColors.mainColor)
: null,
body: EasyRefreshTool(onRefresh: () {
logic.pageNo = 1;
getHttpData();
}, onLoad: () {
getHttpData();
}, child: Obx(() {
return state.itemDataList.value.isEmpty
? NoData()
: SlidableAutoCloseBehavior(
child: ListView.builder(
itemCount: state.itemDataList.value.length,
itemBuilder: (c, index) {
MessageItemEntity messageItemEntity =
state.itemDataList.value[index];
return Slidable(
key: ValueKey(messageItemEntity.id),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const ScrollMotion(),
children: [
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: {
"messageItemEntity": messageItemEntity
});
}),
);
}),
);
})),
);
}
Widget _messageListItem(
MessageItemEntity messageItemEntity, Function() action) {
return GestureDetector(
onTap: action,
child: Container(
height: 90.h,
width: 1.sw,
margin: EdgeInsets.only(bottom: 2.h),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.w),
),
child: Container(
width: 1.sw,
margin: EdgeInsets.only(left: 20.w, right: 20.w),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
messageItemEntity.readAt! == 0 ? Container(
width: 10.w,
height: 10.w,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(5.w),
),
):Container(),
messageItemEntity.readAt! == 0 ? SizedBox(width: 5.w) : Container(),
Flexible(
child: Text(
messageItemEntity.data!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 22.sp,
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor),
),
),
],
),
SizedBox(height: 10.h),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// Image.asset('images/mine/icon_mine_gatewaySignal_strong.png', width: 40.w, height: 40.w,),
// SizedBox(width: 10.w,),
Text(
DateTool().dateToYMDHNString(
messageItemEntity.createdAt!.toString()),
style: TextStyle(
fontSize: 18.sp,
color: messageItemEntity.readAt! == 0
? AppColors.blackColor
: AppColors.placeholderTextColor)),
],
),
SizedBox(width: 20.h),
],
),
),
),
);
}
}