fix: fix bugs

This commit is contained in:
wzp 2024-09-02 18:49:37 +08:00
parent c3c64c620b
commit b791b91616
4 changed files with 297 additions and 218 deletions

View File

@ -223,6 +223,7 @@ class Activity extends StatelessWidget {
return Container(
width: 200,
height: 50,
margin: const EdgeInsetsDirectional.all(5),
padding: const EdgeInsetsDirectional.all(5),
decoration: BoxDecoration(
border: Border.all(
@ -236,7 +237,7 @@ class Activity extends StatelessWidget {
SizedBox(
width: 80,
height: 50,
child: Image.network(imageUrl, fit: BoxFit.cover),
child: Image.network(imageUrl, fit: BoxFit.fill),
),
SizedBox(
width: 100,
@ -352,14 +353,12 @@ class Dynamic extends StatelessWidget {
time = "1 天前";
}
return SizedBox(
width: 500,
height: 150,
child: Stack(
return Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Positioned(
left: 0,
top: 10,
Padding(
padding: const EdgeInsetsDirectional.all(10),
child: Column(
children: [
SizedBox(
@ -380,18 +379,17 @@ class Dynamic extends StatelessWidget {
],
),
),
Positioned(
right: 0,
top: 0,
Expanded(
child: SizedBox(
width: 200,
height: 100,
child: Image.network(imageUrl, fit: BoxFit.cover),
child: Padding(
padding: const EdgeInsetsDirectional.all(2),
child: Image.network(imageUrl, fit: BoxFit.fitHeight)
)
),
)
),
],
),
);
);
}
}
@ -436,19 +434,16 @@ class _DynamicsState extends State<Dynamics> {
return ShowMoreContainer(
title: "社区动态",
showMore: true,
child: SizedBox(
height: 300,
child: ListView(
children: _dynamics.map((dynamic) {
return Dynamic(
title: dynamic['title'],
source: "内容来源",
commentCount: dynamic['commentCount'],
sendTime: dynamic['sendTime'],
imageUrl: dynamic['imageUrl'],
);
}).toList(),
),
child: Column(
children: _dynamics.map((dynamic) {
return Dynamic(
title: dynamic['title'],
source: "内容来源",
commentCount: dynamic['commentCount'],
sendTime: dynamic['sendTime'],
imageUrl: dynamic['imageUrl'],
);
}).toList(),
),
);
}
@ -471,30 +466,32 @@ class Reminder extends StatelessWidget {
height: 50,
child: Icon(icon, color: Colors.green),
),
Container(
margin: const EdgeInsetsDirectional.only(start: 10),
child: Flex(
direction: Axis.vertical,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"认证申请进度提醒",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 20,
Expanded(
child: Container(
margin: const EdgeInsetsDirectional.only(start: 10),
child: Flex(
direction: Axis.vertical,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"认证申请进度提醒",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 20,
),
),
),
SizedBox(
width: 300,
child: Text(
message,
style: const TextStyle(
color: Colors.grey,
fontSize: 12,
overflow: TextOverflow.ellipsis),
),
)
],
SizedBox(
width: 300,
child: Text(
message,
style: const TextStyle(
color: Colors.grey,
fontSize: 12,
overflow: TextOverflow.ellipsis),
),
)
],
),
),
),
Row(

View File

@ -32,6 +32,25 @@ class _ServicePageState extends State<ServicePage> with SingleTickerProviderStat
isLoading = false;
});
}
void updateNotices(){
final e = _controller.index;
print(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);
}
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -49,21 +68,7 @@ class _ServicePageState extends State<ServicePage> with SingleTickerProviderStat
],
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);
}
}
});
updateNotices();
},
),
Expanded(
@ -92,6 +97,12 @@ class _ServicePageState extends State<ServicePage> with SingleTickerProviderStat
],
),
onTap: () {
if (notices[index]['status'] == "未读"){
setState(() {
notices[index]['status'] = "已读";
updateNotices();
});
}
Navigator.push(
context,
MaterialPageRoute(

View File

@ -2,6 +2,71 @@ import 'package:environmental_protection/common/user_information.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
class PostCard extends StatefulWidget {
final Map<String, dynamic> post;
const PostCard({super.key, required this.post});
@override
State<PostCard> createState() => _PostCardState();
}
class _PostCardState extends State<PostCard> {
bool _isLike = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PostDetailPage(postId: widget.post['id']),
),
);
},
child: Flex(
direction: Axis.vertical,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.network(
resolve(widget.post['cover']).toString(),
fit: BoxFit.cover,
height: 150,
width: double.infinity,
),
Padding(
padding: const EdgeInsetsDirectional.only(top: 10),
child: Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(widget.post['nickName'] ?? "未知用户", style: const TextStyle(fontSize: 16)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: TextButton(
onPressed: (){
setState(() {
_isLike = !_isLike;
});
},
child: Row(
children: [
Icon(Icons.favorite, color: _isLike ? Colors.red : Colors.grey, size: 16),
const SizedBox(width: 5),
Text((_isLike ? widget.post['likeNum'] + 1 : widget.post['likeNum']).toString()),
],
)
)
),
],
),
)
],
),
);
}
}
class SocialPage extends StatefulWidget {
const SocialPage({super.key});
@ -48,57 +113,71 @@ class _SocialPageState extends State<SocialPage> {
),
itemCount: posts.length,
itemBuilder: (context, index) {
final post = posts[index];
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PostDetailPage(postId: post['id']),
),
);
},
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.network(
resolve(post['cover']).toString(),
fit: BoxFit.cover,
height: 150,
width: double.infinity,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(post['nickName'] ?? "未知用户", style: const TextStyle(fontSize: 16)),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
children: [
const Icon(Icons.favorite, color: Colors.red, size: 16),
const SizedBox(width: 5),
Text(post['likeNum'].toString()),
],
),
),
],
),
),
);
return PostCard(post: posts[index]);
},
),
floatingActionButton: FloatingActionButton(
/* floatingActionButton: FloatingActionButton(
heroTag: 'uniqueTag',
onPressed: () {
//
},
child: const Icon(Icons.add),
),*/
);
}
}
class Comment extends StatefulWidget {
final Map<String, dynamic> comment;
const Comment({super.key, required this.comment});
@override
State<Comment> createState() => _CommentState();
}
class _CommentState extends State<Comment> {
bool _isLike = false;
@override
Widget build(BuildContext context) {
final comment = widget.comment;
return ListTile(
leading: comment['avatar'] != null && comment['avatar'] != '' ? CircleAvatar(
backgroundImage: NetworkImage(resolve(comment['avatar']).toString()),
) : const SizedBox(width: 40, height: 40, child: Placeholder()),
title: Text(comment['nickName'] ?? "未知用户"),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(comment['content'] ?? ""),
const SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(comment['createTime'] ?? "未知", style: const TextStyle(fontSize: 12, color: Colors.grey)),
TextButton(
onPressed: (){
setState(() {
_isLike = !_isLike;
});
},
child: Row(
children: [
Icon(Icons.favorite, color: _isLike ? Colors.red : Colors.grey, size: 16),
const SizedBox(width: 5),
Text((_isLike ? comment['likeNum'] + 1 : comment['likeNum']).toString()),
],
),
)
],
),
],
),
);
}
}
class PostDetailPage extends StatefulWidget {
final int postId;
@ -185,28 +264,30 @@ class _PostDetailPageState extends State<PostDetailPage> {
title: const Text("帖子详情"),
centerTitle: true,
),
body: post == null
? const Center(child: CircularProgressIndicator())
: ListView(
children: [
Container(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(post!['nickName'] ?? "未知用户", style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const SizedBox(height: 10),
Text("发布时间: ${post!['createTime']}"),
const SizedBox(height: 20),
Text(post!['content'] ?? "无内容", style: const TextStyle(fontSize: 16)),
const SizedBox(height: 10),
Image.network(resolve(post!['cover']).toString()),
],
),
body: Stack(
children: [
Positioned.fill(child: post == null
? const Center(child: CircularProgressIndicator())
: ListView(
children: [
Container(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(post!['nickName'] ?? "未知用户", style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const SizedBox(height: 10),
Text("发布时间: ${post!['createTime']}"),
const SizedBox(height: 20),
Text(post!['content'] ?? "无内容", style: const TextStyle(fontSize: 16)),
const SizedBox(height: 10),
Image.network(resolve(post!['cover']).toString()),
],
),
const Divider(),
Expanded(
child: NotificationListener<ScrollNotification>(
),
const Divider(),
Expanded(
child: NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification scrollInfo) {
if (!isLoading &&
scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) {
@ -227,66 +308,56 @@ class _PostDetailPageState extends State<PostDetailPage> {
child: Center(child: Text("没有更多评论了")),
);
}
final comment = comments[index];
return ListTile(
leading: comment['avatar'] != null && comment['avatar'] != '' ? CircleAvatar(
backgroundImage: NetworkImage(resolve(comment['avatar']).toString()),
) : const SizedBox(width: 40, height: 40, child: Placeholder()),
title: Text(comment['nickName'] ?? "未知用户"),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(comment['content'] ?? ""),
const SizedBox(height: 5),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(comment['createTime'] ?? "未知", style: const TextStyle(fontSize: 12, color: Colors.grey)),
Row(
children: [
const Icon(Icons.favorite, color: Colors.red, size: 16),
const SizedBox(width: 4),
Text(comment['likeNum'].toString()),
],
),
],
),
],
),
);
return Comment(comment: comments[index]);
},
),
)
),
),
const Divider(),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
decoration: const InputDecoration(
hintText: '发表评论...',
border: OutlineInputBorder(),
),
],
)),
Positioned.fill(
bottom: 0,
child: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
decoration: const BoxDecoration(
color: Colors.white
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
decoration: const InputDecoration(
hintText: '发表评论...',
border: OutlineInputBorder(),
),
controller: _commentController,
),
controller: _commentController,
),
),
const SizedBox(width: 10),
ElevatedButton(
onPressed: () {
var global = GlobalInformation.getInstance();
global.requester.post(resolve('api/post/comment'), body: jsonEncode({"postId": widget.postId.toString(), "content": _commentController.text, "likeNum": "0", "parentId": 0}));
_commentController.clear();
},
child: const Text("发布"),
),
],
const SizedBox(width: 10),
ElevatedButton(
onPressed: () {
var global = GlobalInformation.getInstance();
global.requester.post(resolve('api/post/comment'), body: jsonEncode({"postId": widget.postId.toString(), "content": _commentController.text, "likeNum": "0", "parentId": 0}));
_commentController.clear();
},
child: const Text("发布"),
),
],
),
),
),
)
],
)
)
],
)
);
}
}

View File

@ -6,7 +6,7 @@ packages:
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.11.0"
boolean_selector:
@ -14,7 +14,7 @@ packages:
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
characters:
@ -22,7 +22,7 @@ packages:
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
clock:
@ -30,7 +30,7 @@ packages:
description:
name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
collection:
@ -38,7 +38,7 @@ packages:
description:
name: collection
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.18.0"
cupertino_icons:
@ -46,7 +46,7 @@ packages:
description:
name: cupertino_icons
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.8"
fake_async:
@ -54,7 +54,7 @@ packages:
description:
name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
flutter:
@ -67,7 +67,7 @@ packages:
description:
name: flutter_lints
sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.2"
flutter_test:
@ -80,7 +80,7 @@ packages:
description:
name: http
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.2"
http_parser:
@ -88,31 +88,31 @@ packages:
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.2"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
url: "https://pub.flutter-io.cn"
source: hosted
version: "10.0.4"
version: "10.0.5"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.3"
version: "3.0.5"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
lints:
@ -120,7 +120,7 @@ packages:
description:
name: lints
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.0"
matcher:
@ -128,31 +128,31 @@ packages:
description:
name: matcher
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.8.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.12.0"
version: "1.15.0"
path:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.0"
sky_engine:
@ -165,7 +165,7 @@ packages:
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
stack_trace:
@ -173,7 +173,7 @@ packages:
description:
name: stack_trace
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.11.1"
stream_channel:
@ -181,7 +181,7 @@ packages:
description:
name: stream_channel
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
string_scanner:
@ -189,7 +189,7 @@ packages:
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
term_glyph:
@ -197,23 +197,23 @@ packages:
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.0"
version: "0.7.2"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2"
vector_math:
@ -221,23 +221,23 @@ packages:
description:
name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.flutter-io.cn"
source: hosted
version: "14.2.1"
version: "14.2.5"
web:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
url: "https://pub.dev"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
sdks: