mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-05 08:40:12 +08:00
42
lib/pages/common/dyn/reaction/controller.dart
Normal file
42
lib/pages/common/dyn/reaction/controller.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:PiliPlus/http/dynamics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_reaction/data.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_reaction/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DynReactController
|
||||
extends CommonListController<DynReactionData, DynReactionItem> {
|
||||
DynReactController(this.id, {int count = -1}) : count = RxInt(count);
|
||||
final Object id;
|
||||
|
||||
String? _offset;
|
||||
final RxInt count;
|
||||
|
||||
@override
|
||||
List<DynReactionItem>? getDataList(DynReactionData response) {
|
||||
_offset = response.offset;
|
||||
if (response.hasMore != true) {
|
||||
isEnd = true;
|
||||
}
|
||||
return response.items;
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success<DynReactionData> response) {
|
||||
if (isRefresh) {
|
||||
count.value = response.response.total;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<DynReactionData>> customGetData() =>
|
||||
DynamicsHttp.dynReaction(id: id, offset: _offset);
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
_offset = null;
|
||||
return super.onRefresh();
|
||||
}
|
||||
}
|
||||
93
lib/pages/common/dyn/reaction/view.dart
Normal file
93
lib/pages/common/dyn/reaction/view.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:PiliPlus/common/widgets/flutter/list_tile.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/pendant_avatar.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/dynamic/dyn_reaction/item.dart';
|
||||
import 'package:PiliPlus/pages/common/dyn/common_dyn_page.dart';
|
||||
import 'package:PiliPlus/pages/common/dyn/reaction/controller.dart';
|
||||
import 'package:flutter/material.dart' hide ListTile;
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DynReactPage extends StatelessWidget {
|
||||
const DynReactPage({
|
||||
super.key,
|
||||
required this.id,
|
||||
this.isPortrait = true,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
final Object id;
|
||||
final bool isPortrait;
|
||||
final DynReactController controller;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
if (controller.loadingState.value == .loading()) {
|
||||
controller.queryData();
|
||||
}
|
||||
Widget buildBody(
|
||||
ThemeData theme,
|
||||
LoadingState<List<DynReactionItem>?> state,
|
||||
) {
|
||||
return switch (state) {
|
||||
Loading() => const SliverFillRemaining(child: m3eLoading),
|
||||
Success(:final response) =>
|
||||
response != null && response.isNotEmpty
|
||||
? SliverList.builder(
|
||||
itemCount: response.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == response.length - 1) {
|
||||
controller.onLoadMore();
|
||||
}
|
||||
|
||||
final item = response[index];
|
||||
return ListTile(
|
||||
dense: true,
|
||||
safeArea: false,
|
||||
visualDensity: .standard,
|
||||
onTap: () => Get.toNamed('/member?mid=${item.mid}'),
|
||||
leading: PendantAvatar(item.face!, size: 36),
|
||||
title: Text.rich(
|
||||
TextSpan(
|
||||
text: item.name,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: ' ${item.action}',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: theme.colorScheme.outline,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
: HttpError(onReload: controller.onReload),
|
||||
Error(:final errMsg) => HttpError(
|
||||
errMsg: errMsg,
|
||||
onReload: controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
final child = CustomScrollView(
|
||||
key: const PageStorageKey(DynType.reaction),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: .only(
|
||||
bottom: MediaQuery.viewPaddingOf(context).bottom + 100,
|
||||
),
|
||||
sliver: Obx(() => buildBody(theme, controller.loadingState.value)),
|
||||
),
|
||||
],
|
||||
);
|
||||
if (isPortrait) return child;
|
||||
return refreshIndicator(onRefresh: controller.onRefresh, child: child);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user