feat: member search dynamic
This commit is contained in:
@ -260,7 +260,8 @@ class Api {
|
|||||||
static const String memberArchive = '/x/space/wbi/arc/search';
|
static const String memberArchive = '/x/space/wbi/arc/search';
|
||||||
|
|
||||||
// 用户动态搜索
|
// 用户动态搜索
|
||||||
static const String memberDynamicSearch = '/x/space/dynamic/search';
|
static const String memberDynamicSearch =
|
||||||
|
'/x/polymer/web-dynamic/v1/feed/space/search';
|
||||||
|
|
||||||
// 用户动态
|
// 用户动态
|
||||||
static const String memberDynamic = '/x/polymer/web-dynamic/v1/feed/space';
|
static const String memberDynamic = '/x/polymer/web-dynamic/v1/feed/space';
|
||||||
|
@ -91,6 +91,11 @@ class MemberHttp {
|
|||||||
String order = 'pubdate',
|
String order = 'pubdate',
|
||||||
bool orderAvoided = true,
|
bool orderAvoided = true,
|
||||||
}) async {
|
}) async {
|
||||||
|
String? wWebid;
|
||||||
|
if ((await getWWebid(mid: mid!))['status']) {
|
||||||
|
wWebid = GlobalDataCache.wWebid;
|
||||||
|
}
|
||||||
|
|
||||||
String dmImgStr = Utils.base64EncodeRandomString(16, 64);
|
String dmImgStr = Utils.base64EncodeRandomString(16, 64);
|
||||||
String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
|
String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
|
||||||
Map params = await WbiSign().makSign({
|
Map params = await WbiSign().makSign({
|
||||||
@ -112,7 +117,8 @@ class MemberHttp {
|
|||||||
'order': 'pubdate',
|
'order': 'pubdate',
|
||||||
'special_type': 'charging',
|
'special_type': 'charging',
|
||||||
}
|
}
|
||||||
: {}
|
: {},
|
||||||
|
...wWebid != null ? {'w_webid': wWebid} : {},
|
||||||
});
|
});
|
||||||
|
|
||||||
var res = await Request().get(
|
var res = await Request().get(
|
||||||
@ -120,6 +126,7 @@ class MemberHttp {
|
|||||||
data: params,
|
data: params,
|
||||||
extra: {'ua': 'pc'},
|
extra: {'ua': 'pc'},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {
|
return {
|
||||||
'status': true,
|
'status': true,
|
||||||
@ -163,13 +170,17 @@ class MemberHttp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 搜索用户动态
|
// 搜索用户动态
|
||||||
static Future memberDynamicSearch({int? pn, int? ps, int? mid}) async {
|
static Future memberDynamicSearch({
|
||||||
var res = await Request().get(Api.memberDynamic, data: {
|
int? pn,
|
||||||
'keyword': '海拔',
|
int? mid,
|
||||||
'mid': mid,
|
String? offset,
|
||||||
'pn': pn,
|
required String keyword,
|
||||||
'ps': ps,
|
}) async {
|
||||||
'platform': 'web'
|
var res = await Request().get(Api.memberDynamicSearch, data: {
|
||||||
|
'host_mid': mid,
|
||||||
|
'page': pn,
|
||||||
|
'offset': offset,
|
||||||
|
'keyword': keyword,
|
||||||
});
|
});
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {
|
return {
|
||||||
|
@ -5,10 +5,12 @@ class DynamicsDataModel {
|
|||||||
this.hasMore,
|
this.hasMore,
|
||||||
this.items,
|
this.items,
|
||||||
this.offset,
|
this.offset,
|
||||||
|
this.total,
|
||||||
});
|
});
|
||||||
bool? hasMore;
|
bool? hasMore;
|
||||||
List<DynamicItemModel>? items;
|
List<DynamicItemModel>? items;
|
||||||
String? offset;
|
String? offset;
|
||||||
|
int? total;
|
||||||
|
|
||||||
DynamicsDataModel.fromJson(Map<String, dynamic> json) {
|
DynamicsDataModel.fromJson(Map<String, dynamic> json) {
|
||||||
hasMore = json['has_more'];
|
hasMore = json['has_more'];
|
||||||
@ -16,6 +18,7 @@ class DynamicsDataModel {
|
|||||||
.map<DynamicItemModel>((e) => DynamicItemModel.fromJson(e))
|
.map<DynamicItemModel>((e) => DynamicItemModel.fromJson(e))
|
||||||
.toList();
|
.toList();
|
||||||
offset = json['offset'];
|
offset = json['offset'];
|
||||||
|
total = json['total'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
132
lib/pages/member_search/archive.dart
Normal file
132
lib/pages/member_search/archive.dart
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/common/skeleton/video_card_h.dart';
|
||||||
|
import 'package:pilipala/common/widgets/http_error.dart';
|
||||||
|
import 'package:pilipala/common/widgets/no_data.dart';
|
||||||
|
import 'package:pilipala/common/widgets/video_card_h.dart';
|
||||||
|
import 'controller.dart';
|
||||||
|
|
||||||
|
class SearchArchivePage extends StatefulWidget {
|
||||||
|
const SearchArchivePage({
|
||||||
|
super.key,
|
||||||
|
required this.searchKeyWord,
|
||||||
|
required this.controller,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String searchKeyWord;
|
||||||
|
final MemberSearchController controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SearchArchivePage> createState() => _SearchArchivePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SearchArchivePageState extends State<SearchArchivePage>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
|
late Future _futureBuilderFuture;
|
||||||
|
ScrollController scrollController = ScrollController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_futureBuilderFuture = widget.controller.searchArchives();
|
||||||
|
scrollController.addListener(
|
||||||
|
() {
|
||||||
|
if (scrollController.position.pixels >=
|
||||||
|
scrollController.position.maxScrollExtent - 300) {
|
||||||
|
EasyThrottle.throttle('search_archive', const Duration(seconds: 1),
|
||||||
|
() {
|
||||||
|
widget.controller.onLoad();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
widget.controller.searchKeyWord.listen((p0) {
|
||||||
|
if (context.mounted) {
|
||||||
|
setState(() {
|
||||||
|
_futureBuilderFuture = widget.controller.searchArchives();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
scrollController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 6),
|
||||||
|
child: FutureBuilder(
|
||||||
|
future: _futureBuilderFuture,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
|
Map? data = snapshot.data;
|
||||||
|
if (data != null && data['status']) {
|
||||||
|
return Obx(
|
||||||
|
() => widget.controller.archiveList.isNotEmpty
|
||||||
|
? ListView.builder(
|
||||||
|
controller: scrollController,
|
||||||
|
itemCount: widget.controller.archiveList.length + 1,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index == widget.controller.archiveList.length) {
|
||||||
|
return Container(
|
||||||
|
height: MediaQuery.paddingOf(context).bottom + 60,
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
bottom: MediaQuery.paddingOf(context).bottom),
|
||||||
|
child: Center(
|
||||||
|
child: Obx(
|
||||||
|
() => Text(
|
||||||
|
widget.controller.loadingArchiveText.value,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.outline,
|
||||||
|
fontSize: 13),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return VideoCardH(
|
||||||
|
videoItem:
|
||||||
|
widget.controller.archiveList[index]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: const CustomScrollView(
|
||||||
|
slivers: <Widget>[
|
||||||
|
NoData(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return HttpError(
|
||||||
|
errMsg: data?['msg'] ?? '请求异常',
|
||||||
|
fn: () => setState(() {
|
||||||
|
_futureBuilderFuture = widget.controller.searchArchives();
|
||||||
|
}),
|
||||||
|
isInSliver: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: 10,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return const VideoCardHSkeleton();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,91 +1,147 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/http/member.dart';
|
import 'package:pilipala/http/member.dart';
|
||||||
|
import 'package:pilipala/models/dynamics/result.dart';
|
||||||
import 'package:pilipala/models/member/archive.dart';
|
import 'package:pilipala/models/member/archive.dart';
|
||||||
|
|
||||||
class MemberSearchController extends GetxController {
|
class MemberSearchController extends GetxController
|
||||||
|
with GetTickerProviderStateMixin {
|
||||||
final ScrollController scrollController = ScrollController();
|
final ScrollController scrollController = ScrollController();
|
||||||
Rx<TextEditingController> controller = TextEditingController().obs;
|
TextEditingController textController = TextEditingController();
|
||||||
final FocusNode searchFocusNode = FocusNode();
|
final FocusNode searchFocusNode = FocusNode();
|
||||||
RxString searchKeyWord = ''.obs;
|
RxString searchKeyWord = ''.obs;
|
||||||
String hintText = '搜索';
|
|
||||||
RxString loadingStatus = 'init'.obs;
|
|
||||||
RxString loadingText = '加载中...'.obs;
|
|
||||||
bool hasRequest = false;
|
|
||||||
late int mid;
|
late int mid;
|
||||||
RxString uname = ''.obs;
|
RxString uname = ''.obs;
|
||||||
int archivePn = 1;
|
|
||||||
int archiveCount = 0;
|
|
||||||
RxList<VListItemModel> archiveList = <VListItemModel>[].obs;
|
|
||||||
int dynamic_pn = 1;
|
|
||||||
RxList<VListItemModel> dynamicList = <VListItemModel>[].obs;
|
|
||||||
|
|
||||||
int ps = 30;
|
// 投稿相关
|
||||||
|
final int ps = 30;
|
||||||
|
int archivePn = 1;
|
||||||
|
int _archiveCount = 0;
|
||||||
|
RxString loadingArchiveText = '加载中...'.obs;
|
||||||
|
RxList<VListItemModel> archiveList = <VListItemModel>[].obs;
|
||||||
|
|
||||||
|
// 动态相关
|
||||||
|
String dynamicOffset = '';
|
||||||
|
int dynamicPn = 1;
|
||||||
|
int _dynamicCount = 0;
|
||||||
|
bool dynamicHasMore = true;
|
||||||
|
RxString loadingDynamicText = '加载中...'.obs;
|
||||||
|
RxList<DynamicItemModel> dynamicList = <DynamicItemModel>[].obs;
|
||||||
|
|
||||||
|
late TabController tabController;
|
||||||
|
RxList<String> tabs = <String>['视频', '动态'].obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
mid = int.parse(Get.parameters['mid']!);
|
mid = int.parse(Get.parameters['mid']!);
|
||||||
uname.value = Get.parameters['uname']!;
|
uname.value = Get.parameters['uname']!;
|
||||||
|
tabController = TabController(length: tabs.length, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空搜索
|
// 清空搜索
|
||||||
void onClear() {
|
void onClear() {
|
||||||
if (searchKeyWord.value.isNotEmpty && controller.value.text != '') {
|
if (textController.text.isNotEmpty) {
|
||||||
controller.value.clear();
|
textController.clear();
|
||||||
searchKeyWord.value = '';
|
searchKeyWord.value = '';
|
||||||
|
tabController.index = 0;
|
||||||
|
reset();
|
||||||
} else {
|
} else {
|
||||||
Get.back();
|
Get.back();
|
||||||
}
|
}
|
||||||
loadingStatus.value = 'init';
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChange(value) {
|
|
||||||
searchKeyWord.value = value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 提交搜索内容
|
// 提交搜索内容
|
||||||
void submit() {
|
void submit() {
|
||||||
loadingStatus.value = 'loading';
|
if (searchKeyWord.value != textController.text) {
|
||||||
if (hasRequest) {
|
reset();
|
||||||
archivePn = 1;
|
searchKeyWord.value = textController.text;
|
||||||
searchArchives();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索视频
|
// 搜索视频
|
||||||
Future searchArchives({type = 'init'}) async {
|
Future searchArchives({type = 'init'}) async {
|
||||||
if (type == 'onLoad' && loadingText.value == '没有更多了') {
|
if (type == 'onLoad' && loadingArchiveText.value == '没有更多了') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var res = await MemberHttp.memberArchive(
|
var res = await MemberHttp.memberArchive(
|
||||||
mid: mid,
|
mid: mid,
|
||||||
pn: archivePn,
|
pn: archivePn,
|
||||||
keyword: controller.value.text,
|
keyword: textController.text,
|
||||||
order: 'pubdate',
|
order: 'pubdate',
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
if (type == 'init' || archivePn == 1) {
|
if (type == 'init' || archivePn == 1) {
|
||||||
archiveList.value = res['data'].list.vlist;
|
archiveList.value = res['data'].list.vlist;
|
||||||
|
_archiveCount = res['data'].page['count'];
|
||||||
|
setCount();
|
||||||
} else {
|
} else {
|
||||||
archiveList.addAll(res['data'].list.vlist);
|
archiveList.addAll(res['data'].list.vlist);
|
||||||
}
|
}
|
||||||
archiveCount = res['data'].page['count'];
|
if (archiveList.length == _archiveCount) {
|
||||||
if (archiveList.length == archiveCount) {
|
loadingArchiveText.value = '没有更多了';
|
||||||
loadingText.value = '没有更多了';
|
|
||||||
}
|
}
|
||||||
archivePn += 1;
|
archivePn += 1;
|
||||||
hasRequest = true;
|
|
||||||
}
|
}
|
||||||
loadingStatus.value = 'finish';
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索动态
|
// 搜索动态
|
||||||
Future searchDynamic() async {}
|
Future searchDynamic({type = 'init'}) async {
|
||||||
|
if (!dynamicHasMore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var res = await MemberHttp.memberDynamicSearch(
|
||||||
|
pn: dynamicPn,
|
||||||
|
mid: mid,
|
||||||
|
offset: dynamicOffset,
|
||||||
|
keyword: textController.text,
|
||||||
|
);
|
||||||
|
if (res['status']) {
|
||||||
|
dynamicOffset = res['data'].offset;
|
||||||
|
dynamicHasMore = res['data'].hasMore;
|
||||||
|
if (type == 'init') {
|
||||||
|
dynamicList.value = res['data'].items;
|
||||||
|
_dynamicCount = res['data'].total;
|
||||||
|
setCount();
|
||||||
|
} else {
|
||||||
|
dynamicList.addAll(res['data'].items);
|
||||||
|
}
|
||||||
|
if (!dynamicHasMore) {
|
||||||
|
loadingDynamicText.value = '没有更多了';
|
||||||
|
}
|
||||||
|
dynamicPn += 1;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
if (tabController.index == 0) {
|
||||||
searchArchives(type: 'onLoad');
|
searchArchives(type: 'onLoad');
|
||||||
|
} else {
|
||||||
|
searchDynamic(type: 'onLoad');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置状态
|
||||||
|
void reset() {
|
||||||
|
archiveList.clear();
|
||||||
|
dynamicList.clear();
|
||||||
|
archivePn = 1;
|
||||||
|
dynamicPn = 1;
|
||||||
|
dynamicOffset = '';
|
||||||
|
dynamicHasMore = true;
|
||||||
|
_archiveCount = 0;
|
||||||
|
_dynamicCount = 0;
|
||||||
|
loadingArchiveText.value = '加载中...';
|
||||||
|
loadingDynamicText.value = '加载中...';
|
||||||
|
}
|
||||||
|
|
||||||
|
setCount() {
|
||||||
|
tabs.value = [
|
||||||
|
"视频${_archiveCount > 0 ? '($_archiveCount)' : ''}",
|
||||||
|
"动态${_dynamicCount > 0 ? '($_dynamicCount)' : ''}"
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
140
lib/pages/member_search/dynamic.dart
Normal file
140
lib/pages/member_search/dynamic.dart
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/common/skeleton/dynamic_card.dart';
|
||||||
|
import 'package:pilipala/common/widgets/http_error.dart';
|
||||||
|
import 'package:pilipala/common/widgets/no_data.dart';
|
||||||
|
import 'package:pilipala/models/dynamics/result.dart';
|
||||||
|
import 'package:pilipala/pages/dynamics/widgets/dynamic_panel.dart';
|
||||||
|
|
||||||
|
import 'controller.dart';
|
||||||
|
|
||||||
|
class SearchDynamicPage extends StatefulWidget {
|
||||||
|
const SearchDynamicPage({
|
||||||
|
super.key,
|
||||||
|
required this.searchKeyWord,
|
||||||
|
required this.controller,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String searchKeyWord;
|
||||||
|
final MemberSearchController controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SearchDynamicPage> createState() => _SearchDynamicPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SearchDynamicPageState extends State<SearchDynamicPage>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
|
|
||||||
|
late Future _futureBuilderFuture;
|
||||||
|
ScrollController scrollController = ScrollController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_futureBuilderFuture = widget.controller.searchDynamic();
|
||||||
|
scrollController.addListener(
|
||||||
|
() {
|
||||||
|
if (scrollController.position.pixels >=
|
||||||
|
scrollController.position.maxScrollExtent - 300) {
|
||||||
|
EasyThrottle.throttle('search_dynamic', const Duration(seconds: 1),
|
||||||
|
() {
|
||||||
|
widget.controller.onLoad();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
widget.controller.searchKeyWord.listen((p0) {
|
||||||
|
if (context.mounted) {
|
||||||
|
setState(() {
|
||||||
|
_futureBuilderFuture = widget.controller.searchDynamic();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
scrollController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 6),
|
||||||
|
child: CustomScrollView(
|
||||||
|
controller: scrollController,
|
||||||
|
slivers: [
|
||||||
|
FutureBuilder(
|
||||||
|
future: _futureBuilderFuture,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
|
Map? data = snapshot.data;
|
||||||
|
if (data != null && data['status']) {
|
||||||
|
RxList<DynamicItemModel> list = widget.controller.dynamicList;
|
||||||
|
return Obx(
|
||||||
|
() => list.isNotEmpty
|
||||||
|
? SliverList(
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(context, index) {
|
||||||
|
bool isLastItem = index == list.length;
|
||||||
|
double bottom =
|
||||||
|
MediaQuery.paddingOf(context).bottom;
|
||||||
|
if (isLastItem) {
|
||||||
|
return Container(
|
||||||
|
height: bottom + 60,
|
||||||
|
padding: EdgeInsets.only(bottom: bottom),
|
||||||
|
child: Center(
|
||||||
|
child: Obx(
|
||||||
|
() => Text(
|
||||||
|
widget.controller.loadingDynamicText
|
||||||
|
.value,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.outline,
|
||||||
|
fontSize: 13),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return DynamicPanel(item: list[index]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
childCount: list.length + 1,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const NoData(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return HttpError(
|
||||||
|
errMsg: data?['msg'] ?? '请求异常',
|
||||||
|
fn: () => setState(() {
|
||||||
|
_futureBuilderFuture = widget.controller.searchDynamic();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return skeleton();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget skeleton() {
|
||||||
|
return SliverList(
|
||||||
|
delegate: SliverChildBuilderDelegate((context, index) {
|
||||||
|
return const DynamicCardSkeleton();
|
||||||
|
}, childCount: 5),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,9 @@
|
|||||||
import 'package:easy_debounce/easy_throttle.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/skeleton/video_card_h.dart';
|
import 'archive.dart';
|
||||||
import 'package:pilipala/common/widgets/http_error.dart';
|
|
||||||
import 'package:pilipala/common/widgets/no_data.dart';
|
|
||||||
import 'package:pilipala/common/widgets/video_card_h.dart';
|
|
||||||
|
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
|
import 'dynamic.dart';
|
||||||
|
|
||||||
class MemberSearchPage extends StatefulWidget {
|
class MemberSearchPage extends StatefulWidget {
|
||||||
const MemberSearchPage({super.key});
|
const MemberSearchPage({super.key});
|
||||||
@ -20,30 +16,6 @@ class _MemberSearchPageState extends State<MemberSearchPage>
|
|||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
final MemberSearchController _memberSearchCtr =
|
final MemberSearchController _memberSearchCtr =
|
||||||
Get.put(MemberSearchController());
|
Get.put(MemberSearchController());
|
||||||
late ScrollController scrollController;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
scrollController = _memberSearchCtr.scrollController;
|
|
||||||
scrollController.addListener(
|
|
||||||
() {
|
|
||||||
if (scrollController.position.pixels >=
|
|
||||||
scrollController.position.maxScrollExtent - 300) {
|
|
||||||
EasyThrottle.throttle('history', const Duration(seconds: 1), () {
|
|
||||||
_memberSearchCtr.onLoad();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// _tabController = TabController(length: 2, vsync: this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
// _tabController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -52,18 +24,62 @@ class _MemberSearchPageState extends State<MemberSearchPage>
|
|||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => _memberSearchCtr.submit(),
|
onPressed: () => _memberSearchCtr.submit(),
|
||||||
icon: const Icon(CupertinoIcons.search, size: 22)),
|
icon: const Icon(CupertinoIcons.search, size: 22),
|
||||||
|
),
|
||||||
const SizedBox(width: 10)
|
const SizedBox(width: 10)
|
||||||
],
|
],
|
||||||
title: Obx(
|
title: searchTextField(),
|
||||||
() => TextField(
|
),
|
||||||
|
body: Obx(
|
||||||
|
() => _memberSearchCtr.searchKeyWord.value.isEmpty
|
||||||
|
? SizedBox(
|
||||||
|
height: 300,
|
||||||
|
child: Center(
|
||||||
|
child: Text('搜索「${_memberSearchCtr.uname.value}」的动态、视频'),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Column(
|
||||||
|
children: [
|
||||||
|
TabBar(
|
||||||
|
controller: _memberSearchCtr.tabController,
|
||||||
|
dividerColor: Colors.transparent,
|
||||||
|
splashBorderRadius: BorderRadius.circular(8),
|
||||||
|
indicatorSize: TabBarIndicatorSize.label,
|
||||||
|
tabs: _memberSearchCtr.tabs.map(
|
||||||
|
(element) {
|
||||||
|
return Tab(text: element);
|
||||||
|
},
|
||||||
|
).toList(),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: TabBarView(
|
||||||
|
controller: _memberSearchCtr.tabController,
|
||||||
|
children: [
|
||||||
|
SearchArchivePage(
|
||||||
|
searchKeyWord: _memberSearchCtr.textController.text,
|
||||||
|
controller: _memberSearchCtr,
|
||||||
|
),
|
||||||
|
SearchDynamicPage(
|
||||||
|
searchKeyWord: _memberSearchCtr.textController.text,
|
||||||
|
controller: _memberSearchCtr,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget searchTextField() {
|
||||||
|
return TextField(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
focusNode: _memberSearchCtr.searchFocusNode,
|
focusNode: _memberSearchCtr.searchFocusNode,
|
||||||
controller: _memberSearchCtr.controller.value,
|
controller: _memberSearchCtr.textController,
|
||||||
textInputAction: TextInputAction.search,
|
textInputAction: TextInputAction.search,
|
||||||
onChanged: (value) => _memberSearchCtr.onChange(value),
|
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: _memberSearchCtr.hintText,
|
hintText: '搜索',
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
@ -71,121 +87,10 @@ class _MemberSearchPageState extends State<MemberSearchPage>
|
|||||||
size: 22,
|
size: 22,
|
||||||
color: Theme.of(context).colorScheme.outline,
|
color: Theme.of(context).colorScheme.outline,
|
||||||
),
|
),
|
||||||
onPressed: () => _memberSearchCtr.onClear(),
|
onPressed: _memberSearchCtr.onClear,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onSubmitted: (String value) => _memberSearchCtr.submit(),
|
onSubmitted: (String value) => _memberSearchCtr.submit(),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
body: Obx(
|
|
||||||
() => Column(
|
|
||||||
children: _memberSearchCtr.loadingStatus.value == 'init'
|
|
||||||
? [
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Text('搜索「${_memberSearchCtr.uname.value}」的动态、视频'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
// TabBar(
|
|
||||||
// controller: _tabController,
|
|
||||||
// tabs: const [
|
|
||||||
// Tab(text: "视频"),
|
|
||||||
// Tab(text: "动态"),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
Expanded(
|
|
||||||
child:
|
|
||||||
// TabBarView(
|
|
||||||
// controller: _tabController,
|
|
||||||
// children: [
|
|
||||||
FutureBuilder(
|
|
||||||
future: _memberSearchCtr.searchArchives(),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
|
||||||
Map data = snapshot.data as Map;
|
|
||||||
if (data['status']) {
|
|
||||||
return Obx(
|
|
||||||
() => _memberSearchCtr.archiveList.isNotEmpty
|
|
||||||
? ListView.builder(
|
|
||||||
controller: scrollController,
|
|
||||||
itemCount:
|
|
||||||
_memberSearchCtr.archiveList.length +
|
|
||||||
1,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index ==
|
|
||||||
_memberSearchCtr
|
|
||||||
.archiveList.length) {
|
|
||||||
return Container(
|
|
||||||
height: MediaQuery.of(context)
|
|
||||||
.padding
|
|
||||||
.bottom +
|
|
||||||
60,
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
bottom: MediaQuery.of(context)
|
|
||||||
.padding
|
|
||||||
.bottom),
|
|
||||||
child: Center(
|
|
||||||
child: Obx(
|
|
||||||
() => Text(
|
|
||||||
_memberSearchCtr
|
|
||||||
.loadingText.value,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.colorScheme
|
|
||||||
.outline,
|
|
||||||
fontSize: 13),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return VideoCardH(
|
|
||||||
videoItem: _memberSearchCtr
|
|
||||||
.archiveList[index]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: _memberSearchCtr.loadingStatus.value ==
|
|
||||||
'loading'
|
|
||||||
? ListView.builder(
|
|
||||||
itemCount: 10,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return const VideoCardHSkeleton();
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: const CustomScrollView(
|
|
||||||
slivers: <Widget>[
|
|
||||||
NoData(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return HttpError(
|
|
||||||
errMsg: data['msg'],
|
|
||||||
fn: () => setState(() {}),
|
|
||||||
isInSliver: false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 骨架屏
|
|
||||||
return ListView.builder(
|
|
||||||
itemCount: 10,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return const VideoCardHSkeleton();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user