96 lines
3.1 KiB
Dart
96 lines
3.1 KiB
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/http_error.dart';
|
|
import 'package:pilipala/common/widgets/video_card_h.dart';
|
|
import 'package:pilipala/pages/hot/controller.dart';
|
|
import 'package:pilipala/pages/home/widgets/app_bar.dart';
|
|
|
|
class HotPage extends StatefulWidget {
|
|
const HotPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<HotPage> createState() => _HotPageState();
|
|
}
|
|
|
|
class _HotPageState extends State<HotPage> with AutomaticKeepAliveClientMixin {
|
|
final HotController _hotController = Get.put(HotController());
|
|
List videoList = [];
|
|
Future? _futureBuilderFuture;
|
|
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_futureBuilderFuture = _hotController.queryHotFeed('init');
|
|
_hotController.scrollController.addListener(
|
|
() {
|
|
if (_hotController.scrollController.position.pixels >=
|
|
_hotController.scrollController.position.maxScrollExtent - 200) {
|
|
if (!_hotController.isLoadingMore) {
|
|
_hotController.isLoadingMore = true;
|
|
_hotController.onLoad();
|
|
}
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return Scaffold(
|
|
body: RefreshIndicator(
|
|
displacement: kToolbarHeight + MediaQuery.of(context).padding.top,
|
|
onRefresh: () async {
|
|
return await _hotController.onRefresh();
|
|
},
|
|
child: CustomScrollView(
|
|
controller: _hotController.scrollController,
|
|
slivers: [
|
|
const HomeAppBar(),
|
|
FutureBuilder(
|
|
future: _futureBuilderFuture,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
Map data = snapshot.data as Map;
|
|
if (data['status']) {
|
|
return Obx(
|
|
() => SliverList(
|
|
delegate: SliverChildBuilderDelegate((context, index) {
|
|
return VideoCardH(
|
|
videoItem: _hotController.videoList[index],
|
|
);
|
|
}, childCount: _hotController.videoList.length),
|
|
),
|
|
);
|
|
} else {
|
|
return HttpError(
|
|
errMsg: data['msg'],
|
|
fn: () => setState(() {}),
|
|
);
|
|
}
|
|
} else {
|
|
// 骨架屏
|
|
return SliverList(
|
|
delegate: SliverChildBuilderDelegate((context, index) {
|
|
return const VideoCardHSkeleton();
|
|
}, childCount: 5),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
SliverToBoxAdapter(
|
|
child: SizedBox(
|
|
height: MediaQuery.of(context).padding.bottom + 10,
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|