Files
PiliPlus/lib/pages/msg_feed_top/reply_me/view.dart
bggRGjQaUbCoE 8ef163dd38 mod: refresh
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
2025-03-04 12:06:50 +08:00

153 lines
5.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
import '../../../utils/app_scheme.dart';
import 'controller.dart';
class ReplyMePage extends StatefulWidget {
const ReplyMePage({super.key});
@override
State<ReplyMePage> createState() => _ReplyMePageState();
}
class _ReplyMePageState extends State<ReplyMePage> {
late final ReplyMeController _replyMeController =
Get.put(ReplyMeController());
final ScrollController _scrollController = ScrollController();
@override
void initState() {
_replyMeController.queryMsgFeedReplyMe();
super.initState();
_scrollController.addListener(_scrollListener);
}
@override
void dispose() {
_scrollController.removeListener(_scrollListener);
_scrollController.dispose();
super.dispose();
}
Future _scrollListener() async {
if (_scrollController.position.pixels >=
_scrollController.position.maxScrollExtent - 200) {
EasyThrottle.throttle('my-throttler', const Duration(milliseconds: 800),
() async {
await _replyMeController.onLoad();
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('回复我的')),
body: refreshIndicator(
onRefresh: () async {
await _replyMeController.onRefresh();
},
// TODO: refactor
child: Obx(
() {
if (_replyMeController.msgFeedReplyMeList.isEmpty) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.separated(
controller: _scrollController,
itemCount: _replyMeController.msgFeedReplyMeList.length,
physics: const AlwaysScrollableScrollPhysics(),
itemBuilder: (context, int i) {
return ListTile(
onTap: () {
String? nativeUri = _replyMeController
.msgFeedReplyMeList[i].item?.nativeUri;
if (nativeUri != null) {
PiliScheme.routePushFromUrl(nativeUri);
}
// SmartDialog.showToast("跳转至:$nativeUri暂未实现");
},
leading: NetworkImgLayer(
width: 45,
height: 45,
type: 'avatar',
src: _replyMeController.msgFeedReplyMeList[i].user?.avatar,
),
title: Text(
"${_replyMeController.msgFeedReplyMeList[i].user?.nickname} "
"回复了我的${_replyMeController.msgFeedReplyMeList[i].item?.business}",
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(color: Theme.of(context).colorScheme.primary),
),
subtitle: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(
_replyMeController.msgFeedReplyMeList[i].item
?.sourceContent ??
"",
style: Theme.of(context).textTheme.bodyMedium),
const SizedBox(height: 4),
if (_replyMeController.msgFeedReplyMeList[i].item
?.targetReplyContent !=
null &&
_replyMeController.msgFeedReplyMeList[i].item
?.targetReplyContent !=
"")
Text(
"| ${_replyMeController.msgFeedReplyMeList[i].item?.targetReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
height: 1.5)),
if (_replyMeController.msgFeedReplyMeList[i].item
?.rootReplyContent !=
null &&
_replyMeController.msgFeedReplyMeList[i].item
?.rootReplyContent !=
"")
Text(
" | ${_replyMeController.msgFeedReplyMeList[i].item?.rootReplyContent}",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(
color:
Theme.of(context).colorScheme.outline,
height: 1.5)),
]),
);
},
separatorBuilder: (BuildContext context, int index) {
return Divider(
indent: 72,
endIndent: 20,
height: 6,
color: Colors.grey.withOpacity(0.1),
);
},
);
},
),
),
);
}
}