mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
146 lines
5.3 KiB
Dart
146 lines
5.3 KiB
Dart
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 AtMePage extends StatefulWidget {
|
||
const AtMePage({super.key});
|
||
|
||
@override
|
||
State<AtMePage> createState() => _AtMePageState();
|
||
}
|
||
|
||
class _AtMePageState extends State<AtMePage> {
|
||
late final AtMeController _atMeController = Get.put(AtMeController());
|
||
final ScrollController _scrollController = ScrollController();
|
||
|
||
@override
|
||
void initState() {
|
||
_atMeController.queryMsgFeedAtMe();
|
||
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 _atMeController.onLoad();
|
||
});
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
title: const Text('@我的'),
|
||
),
|
||
body: refreshIndicator(
|
||
onRefresh: () async {
|
||
await _atMeController.onRefresh();
|
||
},
|
||
child: SingleChildScrollView(
|
||
controller: _scrollController,
|
||
child: LayoutBuilder(
|
||
builder: (BuildContext context, BoxConstraints constraints) {
|
||
return Obx(
|
||
() {
|
||
if (_atMeController.msgFeedAtMeList.isEmpty) {
|
||
return const Center(
|
||
child: CircularProgressIndicator(),
|
||
);
|
||
}
|
||
return ListView.separated(
|
||
itemCount: _atMeController.msgFeedAtMeList.length,
|
||
shrinkWrap: true,
|
||
physics: const NeverScrollableScrollPhysics(),
|
||
itemBuilder: (context, int i) {
|
||
return ListTile(
|
||
onTap: () {
|
||
String? nativeUri =
|
||
_atMeController.msgFeedAtMeList[i].item?.nativeUri;
|
||
if (nativeUri != null) {
|
||
PiliScheme.routePushFromUrl(nativeUri);
|
||
}
|
||
// SmartDialog.showToast("跳转至:$nativeUri(暂未实现)");
|
||
},
|
||
leading: NetworkImgLayer(
|
||
width: 45,
|
||
height: 45,
|
||
type: 'avatar',
|
||
src: _atMeController.msgFeedAtMeList[i].user?.avatar,
|
||
),
|
||
title: Text(
|
||
"${_atMeController.msgFeedAtMeList[i].user?.nickname} "
|
||
"在${_atMeController.msgFeedAtMeList[i].item?.business}中@了我",
|
||
style: Theme.of(context)
|
||
.textTheme
|
||
.titleMedium!
|
||
.copyWith(
|
||
color: Theme.of(context).colorScheme.primary,
|
||
)),
|
||
subtitle: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
_atMeController
|
||
.msgFeedAtMeList[i].item?.sourceContent ??
|
||
"",
|
||
maxLines: 3,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: Theme.of(context)
|
||
.textTheme
|
||
.bodyMedium!
|
||
.copyWith(
|
||
color: Theme.of(context)
|
||
.colorScheme
|
||
.outline))
|
||
],
|
||
),
|
||
trailing: _atMeController
|
||
.msgFeedAtMeList[i].item?.image !=
|
||
null &&
|
||
_atMeController.msgFeedAtMeList[i].item?.image !=
|
||
""
|
||
? NetworkImgLayer(
|
||
width: 45,
|
||
height: 45,
|
||
type: 'cover',
|
||
src: _atMeController
|
||
.msgFeedAtMeList[i].item?.image,
|
||
)
|
||
: null,
|
||
);
|
||
},
|
||
separatorBuilder: (BuildContext context, int index) {
|
||
return Divider(
|
||
indent: 72,
|
||
endIndent: 20,
|
||
height: 6,
|
||
color: Colors.grey.withOpacity(0.1),
|
||
);
|
||
},
|
||
);
|
||
},
|
||
);
|
||
}),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|