系统消息 按日期分组显示

hmxc
张萌 3 years ago
parent 2fd9a2348d
commit ab44aa38c8

@ -1,4 +1,5 @@
// Flutter imports:
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
// Package imports:
@ -24,6 +25,7 @@ class SystemMessage extends StatefulWidget {
class _SystemMessageState extends State<SystemMessage> {
EasyRefreshController _refreshController = EasyRefreshController();
String? _sendDate;
@override
Widget build(BuildContext context) {
return AkuScaffold(
@ -34,9 +36,7 @@ class _SystemMessageState extends State<SystemMessage> {
return ListView.separated(
padding: EdgeInsets.symmetric(horizontal: 32.w),
itemBuilder: (context, index) {
return SystemMessageCard(
model: items[index],
);
return _buildCard(items[index]);
},
separatorBuilder: (context, index) {
return 10.w.heightBox;
@ -50,4 +50,18 @@ class _SystemMessageState extends State<SystemMessage> {
),
);
}
Widget _buildCard(SystemMessageItemModel model) {
String _date =
DateUtil.formatDateStr(model.sendDate!, format: 'yyyy-MM-dd');
if (_sendDate == null || _sendDate != _date) {
_sendDate = _date;
return SystemMessageCard(
relationId: model.relationId!,
date: _date,
);
} else {
return SystemMessageCard(relationId: model.relationId!, date: null);
}
}
}

@ -13,17 +13,18 @@ import 'package:velocity_x/velocity_x.dart';
// Project imports:
import 'package:aku_community_manager/const/api.dart';
import 'package:aku_community_manager/models/message/system_message_detail_model.dart';
import 'package:aku_community_manager/models/message/system_message_item_model.dart';
import 'package:aku_community_manager/style/app_style.dart';
import 'package:aku_community_manager/ui/sub_pages/business_and_fix/business_and_fix_page.dart';
import 'package:aku_community_manager/utils/network/base_model.dart';
import 'package:aku_community_manager/utils/network/net_util.dart';
class SystemMessageCard extends StatefulWidget {
final SystemMessageItemModel model;
final int relationId;
final String? date;
SystemMessageCard({
Key? key,
required this.model,
required this.relationId,
required this.date,
}) : super(key: key);
@override
@ -31,13 +32,13 @@ class SystemMessageCard extends StatefulWidget {
}
class _SystemMessageCardState extends State<SystemMessageCard> {
late SystemMessageDetailModel _systemModel;
SystemMessageDetailModel? _systemModel;
bool _onLoad = true;
@override
void initState() {
super.initState();
Future.delayed(Duration(milliseconds: 300), () async {
_systemModel = await getSystemMessage(widget.model.relationId!);
_systemModel = await getSystemMessage(widget.relationId);
_onLoad = false;
setState(() {});
});
@ -182,17 +183,19 @@ class _SystemMessageCardState extends State<SystemMessageCard> {
);
}
Widget _messageList(SystemMessageDetailModel model) {
return _onLoad
Widget _messageList(SystemMessageDetailModel? model) {
return (_systemModel == null || _onLoad)
? _loadingWidget()
: Column(
children: [
Container(
widget.date == null
? SizedBox()
: Container(
margin: EdgeInsets.only(top: 24.w, bottom: 24.w),
alignment: Alignment.center,
width: double.infinity,
child: Text(
widget.model.sendDate!,
widget.date!,
style: TextStyle(
color: AppStyle.minorTextColor, fontSize: 24.sp),
),
@ -224,7 +227,7 @@ class _SystemMessageCardState extends State<SystemMessageCard> {
SizedBox(height: 8.w),
]),
Text(
'你有一条新的${model.sysMesTypeString},请立即处理',
'你有一条新的${model!.sysMesTypeString},请立即处理',
style: TextStyle(
color: AppStyle.primaryTextColor,
fontSize: 28.sp,

Loading…
Cancel
Save