This commit is contained in:
wzp 2024-08-30 15:08:31 +08:00
parent 860fd5f62e
commit bd875adc24
2 changed files with 56 additions and 62 deletions

View File

@ -14,7 +14,7 @@ main() async {
'username': 'WUvFG3gY',
'password': 'ZogPgBF6'
}));
print(response.body);
// print(response.body);
global.token = jsonDecode(response.body)['token'];
runApp(const DigitalLife());
}

View File

@ -1,24 +1,8 @@
import 'dart:convert';
import 'package:environmental_protection/common/user_information.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});
@ -26,39 +10,64 @@ class ServicePage extends StatefulWidget {
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"
},
];
class _ServicePageState extends State<ServicePage> with SingleTickerProviderStateMixin {
late final TabController _controller;
List<Map<String, String>> notices = [];
List<Map<String, String>> allNotices = [];
bool isLoading = true;
@override
void initState() {
_controller = TabController(length: 3, vsync: this);
_fetchNoticeData();
super.initState();
}
void _fetchNoticeData() async {
var list = await GlobalInformation.getInstance().requester.get(resolve("api/notice/list"));
var bodyList = jsonDecode(list.body);
setState((){
bodyList['rows'].forEach((e) {
allNotices.add({"title": e['noticeTitle'], "status": e['status'] == "0" ? "未读" : "已读", "time": e["updateTime"], "content": e["noticeContent"], "phone": e['phone'], "unit": e['unit']});
});
notices.addAll(allNotices);
isLoading = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("社区公告"),
),
body: Column(
children: [
_buildStatusMenu(),
TabBar(
tabs: const [
Text("全部"),
Text("未读"),
Text("已读")
],
controller: _controller,
onTap: (e) {
setState(() {
notices.clear();
var targetType = "未读";
if (e == 0){
notices.addAll(allNotices);
return;
}else if (e == 2) {
targetType = "已读";
}
for (var e in allNotices) {
if (e['status'] == targetType){
notices.add(e);
}
}
});
},
),
Expanded(
child: ListView.builder(
child: isLoading ? const Center(child: CircularProgressIndicator()) : ListView.builder(
itemCount: notices.length,
itemBuilder: (context, index) {
return _buildNoticeItem(index);
@ -70,25 +79,11 @@ class _ServicePageState extends State<ServicePage> {
);
}
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"]!),
subtitle: Text(notices[index]["content"]!, overflow: TextOverflow.ellipsis, maxLines: 3,),
trailing: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
@ -129,13 +124,12 @@ class NoticeDetailPage extends StatelessWidget {
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)),
Text("发布单位: ${notice['unit']}", style: const TextStyle(fontSize: 16)),
const SizedBox(height: 10),
const Text("联系电话: 88888888", style: TextStyle(fontSize: 16)),
Text("联系电话: ${notice['phone']}", style: const TextStyle(fontSize: 16)),
],
),
),