系统消息 按日期分组显示

hmxc
张萌 4 years ago
parent 2fd9a2348d
commit ab44aa38c8

@ -1,4 +1,5 @@
// Flutter imports: // Flutter imports:
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Package imports: // Package imports:
@ -24,6 +25,7 @@ class SystemMessage extends StatefulWidget {
class _SystemMessageState extends State<SystemMessage> { class _SystemMessageState extends State<SystemMessage> {
EasyRefreshController _refreshController = EasyRefreshController(); EasyRefreshController _refreshController = EasyRefreshController();
String? _sendDate;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AkuScaffold( return AkuScaffold(
@ -34,9 +36,7 @@ class _SystemMessageState extends State<SystemMessage> {
return ListView.separated( return ListView.separated(
padding: EdgeInsets.symmetric(horizontal: 32.w), padding: EdgeInsets.symmetric(horizontal: 32.w),
itemBuilder: (context, index) { itemBuilder: (context, index) {
return SystemMessageCard( return _buildCard(items[index]);
model: items[index],
);
}, },
separatorBuilder: (context, index) { separatorBuilder: (context, index) {
return 10.w.heightBox; 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: // Project imports:
import 'package:aku_community_manager/const/api.dart'; 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_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/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/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/base_model.dart';
import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:aku_community_manager/utils/network/net_util.dart';
class SystemMessageCard extends StatefulWidget { class SystemMessageCard extends StatefulWidget {
final SystemMessageItemModel model; final int relationId;
final String? date;
SystemMessageCard({ SystemMessageCard({
Key? key, Key? key,
required this.model, required this.relationId,
required this.date,
}) : super(key: key); }) : super(key: key);
@override @override
@ -31,13 +32,13 @@ class SystemMessageCard extends StatefulWidget {
} }
class _SystemMessageCardState extends State<SystemMessageCard> { class _SystemMessageCardState extends State<SystemMessageCard> {
late SystemMessageDetailModel _systemModel; SystemMessageDetailModel? _systemModel;
bool _onLoad = true; bool _onLoad = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
Future.delayed(Duration(milliseconds: 300), () async { Future.delayed(Duration(milliseconds: 300), () async {
_systemModel = await getSystemMessage(widget.model.relationId!); _systemModel = await getSystemMessage(widget.relationId);
_onLoad = false; _onLoad = false;
setState(() {}); setState(() {});
}); });
@ -182,17 +183,19 @@ class _SystemMessageCardState extends State<SystemMessageCard> {
); );
} }
Widget _messageList(SystemMessageDetailModel model) { Widget _messageList(SystemMessageDetailModel? model) {
return _onLoad return (_systemModel == null || _onLoad)
? _loadingWidget() ? _loadingWidget()
: Column( : Column(
children: [ children: [
Container( widget.date == null
? SizedBox()
: Container(
margin: EdgeInsets.only(top: 24.w, bottom: 24.w), margin: EdgeInsets.only(top: 24.w, bottom: 24.w),
alignment: Alignment.center, alignment: Alignment.center,
width: double.infinity, width: double.infinity,
child: Text( child: Text(
widget.model.sendDate!, widget.date!,
style: TextStyle( style: TextStyle(
color: AppStyle.minorTextColor, fontSize: 24.sp), color: AppStyle.minorTextColor, fontSize: 24.sp),
), ),
@ -224,7 +227,7 @@ class _SystemMessageCardState extends State<SystemMessageCard> {
SizedBox(height: 8.w), SizedBox(height: 8.w),
]), ]),
Text( Text(
'你有一条新的${model.sysMesTypeString},请立即处理', '你有一条新的${model!.sysMesTypeString},请立即处理',
style: TextStyle( style: TextStyle(
color: AppStyle.primaryTextColor, color: AppStyle.primaryTextColor,
fontSize: 28.sp, fontSize: 28.sp,

Loading…
Cancel
Save