196 lines
7.0 KiB
Dart
Executable File
196 lines
7.0 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/eventBusEventManage.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 'messageList_entity.dart';
|
|
import 'messageList_logic.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 MessageListLogic logic = Get.put(MessageListLogic());
|
|
final MessageListState 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: '消息'.tr,
|
|
haveBack: true,
|
|
actionsList: <Widget>[
|
|
TextButton(
|
|
child: Text(
|
|
'清空'.tr,
|
|
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
|
),
|
|
onPressed: () async {
|
|
final bool? 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: (BuildContext c, int index) {
|
|
final MessageItemEntity messageItemEntity =
|
|
state.itemDataList.value[index];
|
|
return Slidable(
|
|
key: ValueKey(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
|
|
});
|
|
}),
|
|
);
|
|
}),
|
|
);
|
|
})),
|
|
);
|
|
}
|
|
|
|
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: <Widget>[
|
|
Row(
|
|
children: <Widget>[
|
|
if (messageItemEntity.readAt! == 0)
|
|
Container(
|
|
width: 10.w,
|
|
height: 10.w,
|
|
decoration: BoxDecoration(
|
|
color: Colors.red,
|
|
borderRadius: BorderRadius.circular(5.w),
|
|
),
|
|
)
|
|
else
|
|
Container(),
|
|
if (messageItemEntity.readAt! == 0)
|
|
SizedBox(width: 5.w)
|
|
else
|
|
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: <Widget>[
|
|
// 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),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|