import 'package:flutter/material.dart'; import '../api/oa_client.dart'; import '../widgets/common.dart'; import 'notice_detail_page.dart'; class NoticesPage extends StatefulWidget { const NoticesPage({super.key, required this.api}); final OaClient api; @override State createState() => _NoticesPageState(); } class _NoticesPageState extends State { List> _items = []; bool _loading = true; @override void initState() { super.initState(); _load(); } Future _load() async { try { final data = await widget.api.get('/office/notices'); if (!mounted) return; setState(() { _items = asMaps(data); _loading = false; }); } catch (_) { if (mounted) setState(() => _loading = false); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('公司公告')), body: _loading ? const Center(child: CircularProgressIndicator()) : _items.isEmpty ? const EmptyHint('暂无公告') : RefreshIndicator( onRefresh: _load, child: ListView( children: [ for (final r in _items) KvTile( title: '${r['title'] ?? ''}', subtitle: '${r['excerpt'] ?? ''} ${fmtTime(r['createdAt'])}', onTap: () => Navigator.of(context).push(MaterialPageRoute( builder: (_) => NoticeDetailPage( api: widget.api, id: '${r['id']}', title: '${r['title'] ?? '公告'}', ), )), ), ], ), ), ); } }