admin
2022-03-31 02f1c9fd2c594323f772f8e8f0f2187a285c1749
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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);
              },
            )),
          ],
        ));
  }
}