feat: 稍后再看下拉刷新

This commit is contained in:
guozhigq
2024-10-15 00:17:46 +08:00
parent 3f9b35b56b
commit 63a6c048e6
2 changed files with 66 additions and 59 deletions

View File

@ -22,11 +22,11 @@ class LaterController extends GetxController {
userInfo = userInfoCache.get('userInfoCache'); userInfo = userInfoCache.get('userInfoCache');
} }
Future queryLaterList() async { Future queryLaterList({type = 'init'}) async {
if (userInfo == null) { if (userInfo == null) {
return {'status': false, 'msg': '账号未登录', 'code': -101}; return {'status': false, 'msg': '账号未登录', 'code': -101};
} }
isLoading.value = true; isLoading.value = type == 'init';
var res = await UserHttp.seeYouLater(); var res = await UserHttp.seeYouLater();
if (res['status']) { if (res['status']) {
count = res['data']['count']; count = res['data']['count'];

View File

@ -66,67 +66,74 @@ class _LaterPageState extends State<LaterPage> {
const SizedBox(width: 8), const SizedBox(width: 8),
], ],
), ),
body: CustomScrollView( body: RefreshIndicator(
controller: _laterController.scrollController, onRefresh: () async {
slivers: [ await _laterController.queryLaterList(type: 'onRefresh');
FutureBuilder( },
future: _futureBuilderFuture, child: CustomScrollView(
builder: (context, snapshot) { controller: _laterController.scrollController,
if (snapshot.connectionState == ConnectionState.done) { physics: const AlwaysScrollableScrollPhysics(),
Map? data = snapshot.data; slivers: [
if (data != null && data['status']) { FutureBuilder(
return Obx( future: _futureBuilderFuture,
() => _laterController.laterList.isNotEmpty && builder: (context, snapshot) {
!_laterController.isLoading.value if (snapshot.connectionState == ConnectionState.done) {
? SliverList( Map? data = snapshot.data;
delegate: if (data != null && data['status']) {
SliverChildBuilderDelegate((context, index) { return Obx(
var videoItem = _laterController.laterList[index]; () => _laterController.laterList.isNotEmpty &&
return VideoCardH( !_laterController.isLoading.value
videoItem: videoItem, ? SliverList(
source: 'later', delegate:
onPressedFn: () => _laterController.toViewDel( SliverChildBuilderDelegate((context, index) {
aid: videoItem.aid)); var videoItem =
}, childCount: _laterController.laterList.length), _laterController.laterList[index];
) return VideoCardH(
: _laterController.isLoading.value videoItem: videoItem,
? const SliverToBoxAdapter( source: 'later',
child: Center(child: Text('加载中')), onPressedFn: () => _laterController
) .toViewDel(aid: videoItem.aid));
: const NoData(), }, childCount: _laterController.laterList.length),
); )
: _laterController.isLoading.value
? const SliverToBoxAdapter(
child: Center(child: Text('加载中')),
)
: const NoData(),
);
} else {
return HttpError(
errMsg: data?['msg'] ?? '请求异常',
btnText: data?['code'] == -101 ? '去登录' : null,
fn: () {
if (data?['code'] == -101) {
RoutePush.loginRedirectPush();
} else {
setState(() {
_futureBuilderFuture =
_laterController.queryLaterList();
});
}
},
);
}
} else { } else {
return HttpError( // 骨架屏
errMsg: data?['msg'] ?? '请求异常', return SliverList(
btnText: data?['code'] == -101 ? '去登录' : null, delegate: SliverChildBuilderDelegate((context, index) {
fn: () { return const VideoCardHSkeleton();
if (data?['code'] == -101) { }, childCount: 10),
RoutePush.loginRedirectPush();
} else {
setState(() {
_futureBuilderFuture =
_laterController.queryLaterList();
});
}
},
); );
} }
} else { },
// 骨架屏
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return const VideoCardHSkeleton();
}, childCount: 10),
);
}
},
),
SliverToBoxAdapter(
child: SizedBox(
height: MediaQuery.of(context).padding.bottom + 10,
), ),
) SliverToBoxAdapter(
], child: SizedBox(
height: MediaQuery.of(context).padding.bottom + 10,
),
)
],
),
), ),
floatingActionButton: Obx( floatingActionButton: Obx(
() => _laterController.laterList.isNotEmpty () => _laterController.laterList.isNotEmpty