mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-29 12:38:34 +00:00
feat: search member dynamic [wip]
refactor: member search Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:PiliPalaX/pages/member_search/search_archive.dart';
|
||||
import 'package:PiliPalaX/pages/member_search/search_dynamic.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPalaX/common/widgets/http_error.dart';
|
||||
import 'package:PiliPalaX/common/widgets/video_card_h.dart';
|
||||
|
||||
import '../../common/constants.dart';
|
||||
import '../../utils/grid.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class MemberSearchPage extends StatefulWidget {
|
||||
@@ -16,166 +11,81 @@ class MemberSearchPage extends StatefulWidget {
|
||||
State<MemberSearchPage> createState() => _MemberSearchPageState();
|
||||
}
|
||||
|
||||
class _MemberSearchPageState extends State<MemberSearchPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final MemberSearchController _memberSearchCtr =
|
||||
Get.put(MemberSearchController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_memberSearchCtr.scrollController.addListener(
|
||||
() {
|
||||
if (_memberSearchCtr.scrollController.position.pixels >=
|
||||
_memberSearchCtr.scrollController.position.maxScrollExtent - 300) {
|
||||
EasyThrottle.throttle('history', const Duration(seconds: 1), () {
|
||||
_memberSearchCtr.onLoad();
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
// _tabController = TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// _tabController.dispose();
|
||||
_memberSearchCtr.scrollController.removeListener(() {});
|
||||
super.dispose();
|
||||
}
|
||||
class _MemberSearchPageState extends State<MemberSearchPage> {
|
||||
final _memberSearchCtr = Get.put(MemberSearchController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: () => _memberSearchCtr.submit(),
|
||||
icon: const Icon(Icons.search, size: 22)),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
title: Obx(
|
||||
() => TextField(
|
||||
autofocus: true,
|
||||
focusNode: _memberSearchCtr.searchFocusNode,
|
||||
controller: _memberSearchCtr.controller.value,
|
||||
textInputAction: TextInputAction.search,
|
||||
onChanged: (value) => _memberSearchCtr.onChange(value),
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: _memberSearchCtr.hintText,
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: () => _memberSearchCtr.onClear(),
|
||||
),
|
||||
),
|
||||
onSubmitted: (String value) => _memberSearchCtr.submit(),
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: _memberSearchCtr.submit,
|
||||
icon: const Icon(Icons.search, size: 22),
|
||||
),
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
focusNode: _memberSearchCtr.searchFocusNode,
|
||||
controller: _memberSearchCtr.textEditingController,
|
||||
textInputAction: TextInputAction.search,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索',
|
||||
border: InputBorder.none,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: '清空',
|
||||
icon: const Icon(Icons.clear, size: 22),
|
||||
onPressed: _memberSearchCtr.onClear,
|
||||
),
|
||||
),
|
||||
onSubmitted: (value) => _memberSearchCtr.submit(),
|
||||
onChanged: (value) {
|
||||
if (value.isEmpty) {
|
||||
_memberSearchCtr.hasData.value = false;
|
||||
}
|
||||
},
|
||||
),
|
||||
body: Obx(
|
||||
() {
|
||||
if (_memberSearchCtr.loadingStatus.value == 'init') {
|
||||
return FractionallySizedBox(
|
||||
),
|
||||
body: Obx(
|
||||
() => _memberSearchCtr.hasData.value
|
||||
? Column(
|
||||
children: [
|
||||
Obx(
|
||||
() => TabBar(
|
||||
controller: _memberSearchCtr.tabController,
|
||||
tabs: [
|
||||
Tab(
|
||||
text:
|
||||
'视频 ${_memberSearchCtr.archiveCount.value != -1 ? '${_memberSearchCtr.archiveCount.value}' : ''}'),
|
||||
Tab(
|
||||
text:
|
||||
'动态 ${_memberSearchCtr.dynamicCount.value != -1 ? '${_memberSearchCtr.dynamicCount.value}' : ''}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _memberSearchCtr.tabController,
|
||||
children: [
|
||||
SearchArchive(ctr: _memberSearchCtr),
|
||||
SearchDynamic(ctr: _memberSearchCtr),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: FractionallySizedBox(
|
||||
heightFactor: 0.5,
|
||||
widthFactor: 1.0,
|
||||
child: Center(
|
||||
child: Text('搜索「${_memberSearchCtr.uname.value}」的动态、视频'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _memberSearchCtr.scrollController,
|
||||
slivers: <Widget>[
|
||||
FutureBuilder(
|
||||
future: _memberSearchCtr.searchArchives(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done &&
|
||||
snapshot.hasData) {
|
||||
Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
return SliverPadding(
|
||||
padding:
|
||||
const EdgeInsets.all(StyleString.safeSpace),
|
||||
sliver: Obx(
|
||||
() => _memberSearchCtr.archiveList.isNotEmpty
|
||||
? SliverGrid(
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString
|
||||
.safeSpace,
|
||||
crossAxisSpacing: StyleString
|
||||
.safeSpace,
|
||||
maxCrossAxisExtent: Grid.maxRowWidth *
|
||||
2,
|
||||
childAspectRatio:
|
||||
StyleString.aspectRatio * 2.4,
|
||||
mainAxisExtent: 0),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return VideoCardH(
|
||||
videoItem: _memberSearchCtr
|
||||
.archiveList[index]);
|
||||
},
|
||||
childCount: _memberSearchCtr.archiveList
|
||||
.length))
|
||||
: _memberSearchCtr.loadingStatus.value ==
|
||||
'loading'
|
||||
? SliverGrid(
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing:
|
||||
StyleString.cardSpace,
|
||||
crossAxisSpacing:
|
||||
StyleString.safeSpace,
|
||||
maxCrossAxisExtent:
|
||||
Grid.maxRowWidth * 2,
|
||||
childAspectRatio:
|
||||
StyleString.aspectRatio *
|
||||
2.1,
|
||||
mainAxisExtent: 0),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
}, childCount: 10))
|
||||
: HttpError(
|
||||
callback: () => setState(() {}),
|
||||
),
|
||||
));
|
||||
} else {
|
||||
return HttpError(
|
||||
errMsg: data['msg'],
|
||||
callback: () => setState(() {}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return SliverPadding(
|
||||
padding: const EdgeInsets.all(StyleString.safeSpace),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||
childAspectRatio:
|
||||
StyleString.aspectRatio * 2.4,
|
||||
mainAxisExtent: 0),
|
||||
delegate:
|
||||
SliverChildBuilderDelegate((context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
}, childCount: 10)));
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
));
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user