mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
refactor: live
This commit is contained in:
@@ -1,57 +1,20 @@
|
||||
import 'package:PiliPalaX/utils/extension.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/pages/common/common_controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:PiliPalaX/http/live.dart';
|
||||
import 'package:PiliPalaX/models/live/item.dart';
|
||||
import 'package:PiliPalaX/utils/storage.dart';
|
||||
|
||||
class LiveController extends GetxController {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
class LiveController extends CommonController {
|
||||
int count = 12;
|
||||
int _currentPage = 1;
|
||||
RxInt crossAxisCount = 2.obs;
|
||||
RxList<LiveItemModel> liveList = <LiveItemModel>[].obs;
|
||||
bool flag = false;
|
||||
List<OverlayEntry?> popupDialog = <OverlayEntry?>[];
|
||||
Box setting = GStorage.setting;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
// 获取推荐
|
||||
Future queryLiveList(type) async {
|
||||
// if (type == 'init') {
|
||||
// _currentPage = 1;
|
||||
// }
|
||||
var res = await LiveHttp.liveList(
|
||||
pn: _currentPage,
|
||||
);
|
||||
if (res['status']) {
|
||||
if (type == 'init') {
|
||||
liveList.value = res['data'];
|
||||
} else if (type == 'onLoad') {
|
||||
liveList.addAll(res['data']);
|
||||
}
|
||||
_currentPage += 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// 下拉刷新
|
||||
Future onRefresh() async {
|
||||
queryLiveList('init');
|
||||
}
|
||||
|
||||
// 上拉加载
|
||||
Future onLoad() async {
|
||||
queryLiveList('onLoad');
|
||||
}
|
||||
|
||||
// 返回顶部并刷新
|
||||
void animateToTop() {
|
||||
scrollController.animToTop();
|
||||
}
|
||||
@override
|
||||
Future<LoadingState> customGetData() => LiveHttp.liveList(
|
||||
pn: currentPage,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user