mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
refactor: later
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/common/skeleton/video_card_h.dart';
|
||||
@@ -18,13 +19,6 @@ class LaterPage extends StatefulWidget {
|
||||
|
||||
class _LaterPageState extends State<LaterPage> {
|
||||
final LaterController _laterController = Get.put(LaterController());
|
||||
Future? _futureBuilderFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_futureBuilderFuture = _laterController.queryLaterList();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -33,19 +27,14 @@ class _LaterPageState extends State<LaterPage> {
|
||||
titleSpacing: 0,
|
||||
centerTitle: false,
|
||||
title: Obx(
|
||||
() => _laterController.laterList.isNotEmpty
|
||||
? Text(
|
||||
'稍后再看 (${_laterController.laterList.length})',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
)
|
||||
: Text(
|
||||
'稍后再看',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
() => Text(
|
||||
'稍后再看${_laterController.count.value == -1 ? '' : ' (${_laterController.count.value})'}',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
Obx(
|
||||
() => _laterController.laterList.isNotEmpty
|
||||
() => _laterController.count.value != -1
|
||||
? TextButton(
|
||||
onPressed: () => _laterController.toViewDel(context),
|
||||
child: const Text('移除已看'),
|
||||
@@ -53,7 +42,7 @@ class _LaterPageState extends State<LaterPage> {
|
||||
: const SizedBox(),
|
||||
),
|
||||
Obx(
|
||||
() => _laterController.laterList.isNotEmpty
|
||||
() => _laterController.count.value != -1
|
||||
? IconButton(
|
||||
tooltip: '一键清空',
|
||||
onPressed: () => _laterController.toViewClear(context),
|
||||
@@ -73,79 +62,63 @@ class _LaterPageState extends State<LaterPage> {
|
||||
controller: _laterController.scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: StyleString.safeSpace),
|
||||
sliver: FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
return Obx(
|
||||
() => _laterController.laterList.isNotEmpty &&
|
||||
!_laterController.isLoading.value
|
||||
? SliverGrid(
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.safeSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
maxCrossAxisExtent:
|
||||
Grid.maxRowWidth * 2,
|
||||
childAspectRatio:
|
||||
StyleString.aspectRatio * 2.4,
|
||||
mainAxisExtent: 0),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
var videoItem =
|
||||
_laterController.laterList[index];
|
||||
return VideoCardH(
|
||||
videoItem: videoItem,
|
||||
source: 'later',
|
||||
longPress: () =>
|
||||
_laterController.toViewDel(context,
|
||||
aid: videoItem.aid));
|
||||
},
|
||||
childCount:
|
||||
_laterController.laterList.length),
|
||||
)
|
||||
: _laterController.isLoading.value
|
||||
? const SliverToBoxAdapter(
|
||||
child: Center(child: Text('加载中')),
|
||||
)
|
||||
: const NoData(),
|
||||
);
|
||||
} else {
|
||||
return HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => setState(() {
|
||||
_futureBuilderFuture =
|
||||
_laterController.queryLaterList();
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return 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 const VideoCardHSkeleton();
|
||||
}, childCount: 10),
|
||||
);
|
||||
}
|
||||
},
|
||||
)),
|
||||
SliverToBoxAdapter(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).padding.bottom + 10,
|
||||
padding: EdgeInsets.only(
|
||||
left: StyleString.safeSpace,
|
||||
right: StyleString.safeSpace,
|
||||
bottom: MediaQuery.of(context).padding.bottom + 10,
|
||||
),
|
||||
)
|
||||
sliver: Obx(
|
||||
() => _buildBody(_laterController.loadingState.value),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
return loadingState is Success
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: StyleString.safeSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
maxCrossAxisExtent: Grid.maxRowWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.4,
|
||||
mainAxisExtent: 0,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
var videoItem = loadingState.response[index];
|
||||
return VideoCardH(
|
||||
videoItem: videoItem,
|
||||
source: 'later',
|
||||
longPress: () => _laterController.toViewDel(context,
|
||||
aid: videoItem.aid));
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
),
|
||||
)
|
||||
: loadingState is Empty
|
||||
? const NoData()
|
||||
: loadingState is Error
|
||||
? HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
fn: _laterController.onReload,
|
||||
)
|
||||
: 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 const VideoCardHSkeleton();
|
||||
},
|
||||
childCount: 10,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user