opt: merge fav,follow,history search

This commit is contained in:
bggRGjQaUbCoE
2024-09-13 18:01:06 +08:00
parent b7d115c3ae
commit c78c688002
16 changed files with 160 additions and 472 deletions

View File

@@ -1,5 +1,9 @@
import 'package:PiliPalaX/common/constants.dart';
import 'package:PiliPalaX/common/widgets/http_error.dart';
import 'package:PiliPalaX/http/loading_state.dart';
import 'package:PiliPalaX/pages/follow/widgets/follow_item.dart';
import 'package:PiliPalaX/pages/history/widgets/item.dart';
import 'package:PiliPalaX/utils/grid.dart';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
@@ -8,6 +12,8 @@ import 'package:PiliPalaX/pages/fav_detail/widget/fav_video_card.dart';
import 'controller.dart';
enum SearchType { fav, follow, history }
class FavSearchPage extends StatefulWidget {
const FavSearchPage({super.key});
@@ -17,12 +23,10 @@ class FavSearchPage extends StatefulWidget {
class _FavSearchPageState extends State<FavSearchPage> {
final FavSearchController _favSearchCtr = Get.put(FavSearchController());
late int searchType;
@override
void initState() {
super.initState();
searchType = int.parse(Get.parameters['searchType']!);
_favSearchCtr.scrollController.addListener(
() {
if (_favSearchCtr.scrollController.position.pixels >=
@@ -89,29 +93,65 @@ class _FavSearchPageState extends State<FavSearchPage> {
),
],
)
: ListView.builder(
controller: _favSearchCtr.scrollController,
itemCount: loadingState.response.length + 1,
itemBuilder: (context, index) {
if (index == loadingState.response.length) {
return Container(
height: MediaQuery.of(context).padding.bottom + 60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
),
);
} else {
return FavVideoCardH(
videoItem: loadingState.response[index],
searchType: searchType,
callFn: () => searchType != 1
? _favSearchCtr
.onCancelFav(loadingState.response[index].id!)
: {},
);
}
},
)
: _favSearchCtr.searchType == SearchType.fav
? ListView.builder(
controller: _favSearchCtr.scrollController,
itemCount: loadingState.response.length + 1,
itemBuilder: (context, index) {
if (index == loadingState.response.length) {
return Container(
height: MediaQuery.of(context).padding.bottom + 60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom,
),
);
} else {
return FavVideoCardH(
videoItem: loadingState.response[index],
searchType: _favSearchCtr.type,
callFn: () => _favSearchCtr.type != 1
? _favSearchCtr
.onCancelFav(loadingState.response[index].id!)
: {},
);
}
},
)
: _favSearchCtr.searchType == SearchType.follow
? ListView.builder(
controller: _favSearchCtr.scrollController,
itemCount: loadingState.response.length,
itemBuilder: ((context, index) {
return FollowItem(
item: loadingState.response[index],
);
}),
)
: CustomScrollView(
physics: const AlwaysScrollableScrollPhysics(),
controller: _favSearchCtr.scrollController,
slivers: [
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 HistoryItem(
videoItem: loadingState.response[index],
ctr: _favSearchCtr,
onChoose: null,
onUpdateMultiple: () => null,
);
},
childCount: loadingState.response.length,
),
),
],
)
: loadingState is Error
? CustomScrollView(
slivers: <Widget>[