145 lines
3.9 KiB
Dart
145 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Community Notice',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
home: const ServicePage(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ServicePage extends StatefulWidget {
|
|
const ServicePage({super.key});
|
|
|
|
@override
|
|
State<ServicePage> createState() => _ServicePageState();
|
|
}
|
|
|
|
class _ServicePageState extends State<ServicePage> {
|
|
List<Map<String, String>> notices = [
|
|
{
|
|
"title": "消杀通知",
|
|
"status": "未读",
|
|
"content": "为了给大家提供一个舒适、卫生的生活环境...",
|
|
"time": "2020-12-05 11:02"
|
|
},
|
|
{
|
|
"title": "缴费通知",
|
|
"status": "未读",
|
|
"content": "为了给大家提供一个舒适、卫生的生活环境...",
|
|
"time": "2020-11-21 09:45"
|
|
},
|
|
{
|
|
"title": "物业通知",
|
|
"status": "已读",
|
|
"content": "为了给大家提供一个舒适、卫生的生活环境...",
|
|
"time": "2020-08-01 13:55"
|
|
},
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("社区公告"),
|
|
),
|
|
body: Column(
|
|
children: [
|
|
_buildStatusMenu(),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: notices.length,
|
|
itemBuilder: (context, index) {
|
|
return _buildNoticeItem(index);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatusMenu() {
|
|
return const Padding(
|
|
padding: EdgeInsets.all(8.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
Text("全部", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
Text("未读", style: TextStyle(color: Colors.grey)),
|
|
Text("已读", style: TextStyle(color: Colors.grey)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildNoticeItem(int index) {
|
|
return Card(
|
|
child: ListTile(
|
|
title: Text(notices[index]["title"]!),
|
|
subtitle: Text(notices[index]["content"]!),
|
|
trailing: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text(notices[index]["status"]!, style: const TextStyle(color: Colors.green)),
|
|
Text(notices[index]["time"]!, style: const TextStyle(fontSize: 12)),
|
|
],
|
|
),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => NoticeDetailPage(notice: notices[index]),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class NoticeDetailPage extends StatelessWidget {
|
|
final Map<String, String> notice;
|
|
|
|
const NoticeDetailPage({super.key, required this.notice});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("公告详情"),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(notice["title"]!, style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 10),
|
|
Text("发布时间: ${notice["time"]}", style: const TextStyle(fontSize: 16)),
|
|
const SizedBox(height: 20),
|
|
const Placeholder(fallbackHeight: 150),
|
|
const SizedBox(height: 20),
|
|
Text(notice["content"]!, style: const TextStyle(fontSize: 16)),
|
|
const SizedBox(height: 20),
|
|
const Text("发布单位: 红星海五期物业管理公司", style: TextStyle(fontSize: 16)),
|
|
const SizedBox(height: 10),
|
|
const Text("联系电话: 88888888", style: TextStyle(fontSize: 16)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|