mod: 样式、dio异常处理
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/common/skeleton/video_card_v.dart';
|
||||
import 'package:pilipala/common/widgets/http_error.dart';
|
||||
import 'package:pilipala/common/widgets/video_card_v.dart';
|
||||
import './controller.dart';
|
||||
import 'package:pilipala/common/constants.dart';
|
||||
@ -16,6 +17,7 @@ class HomePage extends StatefulWidget {
|
||||
class _HomePageState extends State<HomePage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
final HomeController _homeController = Get.put(HomeController());
|
||||
Future? _futureBuilderFuture;
|
||||
List videoList = [];
|
||||
|
||||
@override
|
||||
@ -24,6 +26,7 @@ class _HomePageState extends State<HomePage>
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_futureBuilderFuture = _homeController.queryRcmdFeed('init');
|
||||
_homeController.videoList.listen((value) {
|
||||
videoList = value;
|
||||
setState(() {});
|
||||
@ -69,26 +72,25 @@ class _HomePageState extends State<HomePage>
|
||||
? EdgeInsets.zero
|
||||
: const EdgeInsets.fromLTRB(
|
||||
StyleString.cardSpace, 0, StyleString.cardSpace, 8),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
// 行间距
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
// 列间距
|
||||
crossAxisSpacing: StyleString.cardSpace,
|
||||
// 列数
|
||||
crossAxisCount: _homeController.crossAxisCount,
|
||||
mainAxisExtent: MediaQuery.of(context).size.width /
|
||||
_homeController.crossAxisCount /
|
||||
StyleString.aspectRatio +
|
||||
70),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return videoList.isNotEmpty
|
||||
? VideoCardV(videoItem: videoList[index])
|
||||
: const VideoCardVSkeleton();
|
||||
},
|
||||
childCount: videoList.isNotEmpty ? videoList.length : 10,
|
||||
),
|
||||
sliver: FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
return Obx(() => contentGrid(
|
||||
_homeController, _homeController.videoList));
|
||||
} else {
|
||||
return HttpError(
|
||||
errMsg: data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return contentGrid(_homeController, []);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const LoadingMore()
|
||||
@ -98,6 +100,31 @@ class _HomePageState extends State<HomePage>
|
||||
// ),
|
||||
);
|
||||
}
|
||||
|
||||
Widget contentGrid(ctr, videoList) {
|
||||
return SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
// 行间距
|
||||
mainAxisSpacing: StyleString.cardSpace,
|
||||
// 列间距
|
||||
crossAxisSpacing: StyleString.cardSpace,
|
||||
// 列数
|
||||
crossAxisCount: ctr.crossAxisCount,
|
||||
mainAxisExtent: MediaQuery.of(context).size.width /
|
||||
ctr.crossAxisCount /
|
||||
StyleString.aspectRatio +
|
||||
70,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(BuildContext context, int index) {
|
||||
return videoList!.isNotEmpty
|
||||
? VideoCardV(videoItem: videoList![index])
|
||||
: const VideoCardVSkeleton();
|
||||
},
|
||||
childCount: videoList!.isNotEmpty ? videoList!.length : 10,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
|
||||
|
Reference in New Issue
Block a user