Merge branch 'design' into alpha

This commit is contained in:
guozhigq
2023-10-14 21:34:01 +08:00
8 changed files with 224 additions and 10 deletions

View File

@ -44,6 +44,14 @@ class _FavPageState extends State<FavPage> {
'我的收藏',
style: Theme.of(context).textTheme.titleMedium,
),
actions: [
IconButton(
onPressed: () => Get.toNamed(
'/favSearch?searchType=1&mediaId=${_favController.favFolderData.value.list!.first.id}'),
icon: const Icon(Icons.search_outlined),
),
const SizedBox(width: 6),
],
),
body: FutureBuilder(
future: _futureBuilderFuture,

View File

@ -92,13 +92,18 @@ class _FavDetailPageState extends State<FavDetailPage> {
);
},
),
// actions: [
// IconButton(
// onPressed: () {},
// icon: const Icon(Icons.more_vert),
// ),
// const SizedBox(width: 4)
// ],
actions: [
IconButton(
onPressed: () => Get.toNamed(
'/favSearch?searchType=0&mediaId=${Get.parameters['mediaId']!}'),
icon: const Icon(Icons.search_outlined),
),
// IconButton(
// onPressed: () {},
// icon: const Icon(Icons.more_vert),
// ),
const SizedBox(width: 6),
],
flexibleSpace: FlexibleSpaceBar(
background: Container(
decoration: BoxDecoration(

View File

@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/user.dart';
import 'package:pilipala/models/user/fav_detail.dart';
class FavSearchController extends GetxController {
final ScrollController scrollController = ScrollController();
Rx<TextEditingController> controller = TextEditingController().obs;
final FocusNode searchFocusNode = FocusNode();
RxString searchKeyWord = ''.obs; // 搜索词
String hintText = '请输入已收藏视频名称'; // 默认
RxBool loadingStatus = false.obs; // 加载状态
RxString loadingText = '加载中...'.obs; // 加载提示
bool hasMore = false;
late int searchType;
late int mediaId;
int currentPage = 1; // 当前页
int count = 0; // 总数
RxList<FavDetailItemData> favList = <FavDetailItemData>[].obs;
@override
void onInit() {
super.onInit();
searchType = int.parse(Get.parameters['searchType']!);
mediaId = int.parse(Get.parameters['mediaId']!);
}
// 清空搜索
void onClear() {
if (searchKeyWord.value.isNotEmpty && controller.value.text != '') {
controller.value.clear();
searchKeyWord.value = '';
} else {
Get.back();
}
}
void onChange(value) {
searchKeyWord.value = value;
}
// 提交搜索内容
void submit() {
loadingStatus.value = true;
currentPage = 1;
searchFav();
}
// 搜索收藏夹视频
Future searchFav({type = 'init'}) async {
var res = await await UserHttp.userFavFolderDetail(
pn: currentPage,
ps: 20,
mediaId: mediaId,
keyword: searchKeyWord.value,
type: searchType,
);
if (res['status']) {
if (currentPage == 1 && type == 'init') {
favList.value = res['data'].medias;
} else if (type == 'onLoad') {
favList.addAll(res['data'].medias);
}
hasMore = res['data'].hasMore;
}
currentPage += 1;
loadingStatus.value = false;
}
onLoad() {
if (!hasMore) return;
searchFav(type: 'onLoad');
}
}

View File

@ -0,0 +1,4 @@
library fav_search;
export './controller.dart';
export './view.dart';

View File

@ -0,0 +1,116 @@
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/no_data.dart';
import 'package:pilipala/pages/favDetail/widget/fav_video_card.dart';
import 'controller.dart';
class FavSearchPage extends StatefulWidget {
final int? sourceType;
final int? mediaId;
const FavSearchPage({super.key, this.sourceType, this.mediaId});
@override
State<FavSearchPage> createState() => _FavSearchPageState();
}
class _FavSearchPageState extends State<FavSearchPage> {
final FavSearchController _favSearchCtr = Get.put(FavSearchController());
late ScrollController scrollController;
@override
void initState() {
super.initState();
scrollController = _favSearchCtr.scrollController;
scrollController.addListener(
() {
if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent - 300) {
EasyThrottle.throttle('fav', const Duration(seconds: 1), () {
_favSearchCtr.onLoad();
});
}
},
);
}
@override
void dispose() {
scrollController.removeListener(() {});
scrollController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0,
actions: [
IconButton(
onPressed: () => _favSearchCtr.submit(),
icon: const Icon(Icons.search_outlined, size: 22)),
const SizedBox(width: 10)
],
title: Obx(
() => TextField(
autofocus: true,
focusNode: _favSearchCtr.searchFocusNode,
controller: _favSearchCtr.controller.value,
textInputAction: TextInputAction.search,
onChanged: (value) => _favSearchCtr.onChange(value),
decoration: InputDecoration(
hintText: _favSearchCtr.hintText,
border: InputBorder.none,
suffixIcon: IconButton(
icon: Icon(
Icons.clear,
size: 22,
color: Theme.of(context).colorScheme.outline,
),
onPressed: () => _favSearchCtr.onClear(),
),
),
onSubmitted: (String value) => _favSearchCtr.submit(),
),
),
),
body: Obx(
() => _favSearchCtr.loadingStatus.value && _favSearchCtr.favList.isEmpty
? ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return const VideoCardHSkeleton();
},
)
: _favSearchCtr.favList.isNotEmpty
? ListView.builder(
controller: scrollController,
itemCount: _favSearchCtr.favList.length + 1,
itemBuilder: (context, index) {
if (index == _favSearchCtr.favList.length) {
return Container(
height: MediaQuery.of(context).padding.bottom + 60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom),
);
} else {
return FavVideoCardH(
videoItem: _favSearchCtr.favList[index],
callFn: () => null,
);
}
},
)
: const CustomScrollView(
slivers: <Widget>[
NoData(),
],
),
),
);
}
}