import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import '../../api/video_api.dart';
|
import '../../model/video/home_type_model.dart';
|
import '../../model/video/video_model.dart';
|
import '../../ui/search/search.dart';
|
import '../../ui/widget/video_item.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../widget/button.dart';
|
|
import '../../ui/widget/nav.dart';
|
import '../widget/refresh_listview.dart';
|
|
class VideoListPage extends StatefulWidget {
|
final String kw;
|
|
VideoListPage({Key? key, required this.title, required this.kw})
|
: super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_VideoListPageState createState() => _VideoListPageState();
|
}
|
|
class _VideoListPageState extends State<VideoListPage>
|
with SingleTickerProviderStateMixin {
|
int page = 1;
|
List<VideoInfoModel> videoList = [];
|
int column = 2;
|
bool hasNextPage = true;
|
|
final MyRefreshController _refreshController = MyRefreshController();
|
|
@override
|
void initState() {
|
super.initState();
|
getVideoList(1);
|
}
|
|
void getVideoList(int _page) async {
|
page = _page;
|
Map<String, dynamic>? result =
|
await VideoApiUtil.getSearchSpecialVideoList(context, widget.kw, _page);
|
_refreshController.refreshCompleted(resetFooterState: true);
|
//请求失败了
|
if (result == null) {
|
if (page > 1) {
|
page = page - 1;
|
}
|
if (videoList.isEmpty) {
|
_refreshController.apiError!();
|
}
|
return;
|
}
|
if (result["IsPost"] == "true") {
|
List<dynamic> list = result["Data"]["list"];
|
hasNextPage = result["Data"]["hasNextPage"];
|
column = result["Data"]["column"];
|
List<VideoInfoModel> tempList = [];
|
for (var element in list) {
|
tempList.add(VideoInfoModel.fromJson(element));
|
}
|
setState(() {
|
if (_page == 1) {
|
videoList = tempList;
|
} else {
|
if (tempList.isNotEmpty) {
|
videoList.addAll(tempList);
|
}
|
}
|
});
|
|
if (!hasNextPage) {
|
_refreshController.loadNoData();
|
} else {
|
if (_page > 1) {
|
_refreshController.loadComplete();
|
}
|
}
|
|
if (videoList.isEmpty) {
|
_refreshController.dataEmpty!();
|
} else {
|
//正常的状态
|
_refreshController.dataNormal!();
|
}
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Column(
|
children: [
|
TopNavBar(
|
title: "",
|
leftText: widget.title,
|
rightIcon: const Icon(
|
Icons.search,
|
size: 40,
|
color: ColorConstant.theme,
|
),
|
rightClick: () {
|
NavigatorUtil.navigateToNextPage(
|
context, SearchPage(title: ""), (data) {});
|
},
|
),
|
Container(
|
height: DimenUtil.getOnePixel(context),
|
color: const Color(0xFFDBDBDB),
|
),
|
Expanded(
|
child: RefreshListView(
|
content: GridView.builder(
|
padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
|
itemCount: videoList.length,
|
itemBuilder: (BuildContext context, int index) {
|
if (column == 2) {
|
return VideoListUIUtil.getVideoItemColumn_2(
|
MediaQuery.of(context).size.width - 10 * 2,
|
HomeVideoModel(video: videoList[index]),
|
context);
|
} else {
|
return VideoListUIUtil.getVideoItemColumn_3(
|
MediaQuery.of(context).size.width - 10 * 2,
|
HomeVideoModel(video: videoList[index]),
|
context);
|
}
|
},
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
//横轴元素个数
|
crossAxisCount: column,
|
//纵轴间距
|
mainAxisSpacing: 10.0,
|
//横轴间距
|
crossAxisSpacing: 10.0,
|
//子组件宽高长度比例
|
childAspectRatio: column == 2 ? 1.25 : 0.55),
|
),
|
refreshController: _refreshController,
|
refresh: () {
|
getVideoList(1);
|
},
|
loadMore: () {
|
getVideoList(page + 1);
|
},
|
)),
|
],
|
));
|
}
|
}
|