| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- import 'package:tdesign_flutter/tdesign_flutter.dart';
- import '../../core/theme/app_colors.dart';
- import '../../core/utils/date_utils.dart' as du;
- import '../../core/utils/responsive.dart';
- import '../../shared/widgets/empty_state.dart';
- import '../../shared/widgets/loading_widget.dart';
- import 'announcement_list_controller.dart';
- import 'announcement_model.dart';
- class AnnouncementListPage extends ConsumerStatefulWidget {
- const AnnouncementListPage({super.key});
- @override
- ConsumerState<AnnouncementListPage> createState() =>
- _AnnouncementListPageState();
- }
- class _AnnouncementListPageState extends ConsumerState<AnnouncementListPage> {
- @override
- Widget build(BuildContext context) {
- final itemsAsync = ref.watch(announcementListProvider);
- final r = ResponsiveHelper.of(context);
- return Scaffold(
- appBar: TDNavBar(
- title: '公告通知',
- titleColor: Colors.white,
- backgroundColor: const Color(0xFF00ABF3),
- centerTitle: false,
- ),
- body: Center(
- child: ConstrainedBox(
- constraints: BoxConstraints(maxWidth: r.listMaxWidth),
- child: itemsAsync.when(
- loading: () => const LoadingWidget(),
- error: (_, __) => const EmptyState(message: '加载失败'),
- data: (items) => items.isEmpty
- ? const EmptyState(message: '暂无公告')
- : ListView.builder(
- padding: const EdgeInsets.symmetric(vertical: 4),
- itemCount: items.length,
- itemBuilder: (_, index) => _buildItem(items[index]),
- ),
- ),
- ),
- ),
- );
- }
- Widget _buildItem(AnnouncementModel item) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
- child: TDCell(
- title: item.title,
- titleWidget: Row(
- children: [
- if (item.isTop)
- Padding(
- padding: const EdgeInsets.only(right: 6),
- child: TDTag(
- '置顶',
- size: TDTagSize.small,
- theme: TDTagTheme.warning,
- shape: TDTagShape.square,
- ),
- ),
- Expanded(
- child: Text(
- item.title,
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- style: const TextStyle(
- fontWeight: FontWeight.w600,
- fontSize: 14,
- color: AppColors.textPrimary),
- ),
- ),
- ],
- ),
- descriptionWidget: Text(
- '${item.type} · ${item.publisherName} ${du.DateUtils.formatDate(item.publishTime)}',
- style: const TextStyle(
- color: AppColors.textSecondary, fontSize: 12),
- ),
- noteWidget: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(Icons.visibility_outlined,
- size: 13, color: AppColors.textHint),
- const SizedBox(width: 3),
- Text('${item.readCount}',
- style: const TextStyle(
- color: AppColors.textHint, fontSize: 11)),
- ],
- ),
- arrow: true,
- bordered: true,
- onClick: (_) => context.push('/announcement/detail/${item.id}'),
- ),
- );
- }
- }
|