diff --git a/assets/mi/loading.gif b/assets/mi/loading.gif new file mode 100644 index 0000000..921dfcf Binary files /dev/null and b/assets/mi/loading.gif differ diff --git a/assets/mo/loading.gif b/assets/mo/loading.gif new file mode 100644 index 0000000..60b7d02 Binary files /dev/null and b/assets/mo/loading.gif differ diff --git a/assets/un/loading.gif b/assets/un/loading.gif new file mode 100644 index 0000000..a026416 Binary files /dev/null and b/assets/un/loading.gif differ diff --git a/assets/wan/loading.gif b/assets/wan/loading.gif new file mode 100644 index 0000000..f3c3ab3 Binary files /dev/null and b/assets/wan/loading.gif differ diff --git a/assets/zao/loading.gif b/assets/zao/loading.gif new file mode 100644 index 0000000..b6d25bb Binary files /dev/null and b/assets/zao/loading.gif differ diff --git a/lib/common/Api.dart b/lib/common/Api.dart index 551870f..1b49c0a 100644 --- a/lib/common/Api.dart +++ b/lib/common/Api.dart @@ -18,7 +18,7 @@ class Api { // Options _options; static Dio dio = - Dio(BaseOptions(baseUrl: 'https://api.eoe.best/eoefans-api/v1', headers: { + Dio(BaseOptions(baseUrl: 'https://api.eoe.best/eoefans-api/v1', headers: { 'ocp-apim-subscription-key': key, 'Content-Type': 'application/json', })); @@ -31,32 +31,35 @@ class Api { } Future videos(VideosRequest params) async { - var paramsData = ({...params.toJson(), 'subscription-key': key}); - paramsData.removeWhere((key, value) => value == null); - print(paramsData); - var r = await dio.get('/video-interface/advanced-search', - queryParameters: paramsData); var tmpVideos = Videos() ..page = 0 ..numResults = 0 ..result = []; - if (r.statusCode == 200) { - var videoRes = - IResponse.fromJson(r.data, (json) => Videos.fromJson(json)); - print(videoRes.data?.page); - print(videoRes.data?.numResults); - if (videoRes.data != null) { - tmpVideos = videoRes.data!; + + try { + var paramsData = ({...params.toJson(), 'subscription-key': key}); + paramsData.removeWhere((key, value) => value == null); + var r = await dio.get('/video-interface/advanced-search', + queryParameters: paramsData); + + if (r.statusCode == 200) { + var videoRes = + IResponse.fromJson(r.data, (json) => Videos.fromJson(json)); + if (videoRes.data != null) { + tmpVideos = videoRes.data!; + } } + } catch (e) { + print(e); } + return tmpVideos; } Future version() async { - var paramsData = ({ 'subscription-key': key}); + var paramsData = ({'subscription-key': key}); paramsData.removeWhere((key, value) => value == null); - var r = await dio.get('/tools/version', - queryParameters: paramsData); + var r = await dio.get('/tools/version', queryParameters: paramsData); var tmpVersion = Version() ..version = '' ..version_message = '' @@ -64,7 +67,7 @@ class Api { ..updated_at = ''; if (r.statusCode == 200) { var versionRes = - IResponse.fromJson(r.data, (json) => Version.fromJson(json)); + IResponse.fromJson(r.data, (json) => Version.fromJson(json)); if (versionRes.data != null) { tmpVersion = versionRes.data!; } diff --git a/lib/routes/video/videoList.dart b/lib/routes/video/videoList.dart index 1fd3325..0b1d143 100644 --- a/lib/routes/video/videoList.dart +++ b/lib/routes/video/videoList.dart @@ -8,8 +8,11 @@ import 'package:eoe_fans/routes/video/videoListItem.dart'; import 'package:eoe_fans/routes/video/videoMemberFilter.dart'; import 'package:eoe_fans/common/Global.dart'; import 'package:eoe_fans/routes/video/videoSwiper.dart'; +import 'package:eoe_fans/states/ProfileChangeNotifier.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:flutter/material.dart'; +import 'package:hexcolor/hexcolor.dart'; +import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; class VideoList extends StatefulWidget { @@ -26,7 +29,7 @@ class _VideoListState extends State { RefreshController(initialRefresh: true); late final bool? origin; - int _page = -1; + int _page = 0; MemberEnum? _memberFilter; VideosRequestOrder _order = VideosRequestOrder.view; @@ -56,16 +59,22 @@ class _VideoListState extends State { : origin! ? VideosCopyright.Original : VideosCopyright.Reproduced); - setState(() { - videoList = [...videoList, ...videos.result]; - _loading = false; - }); + if (videos.result.length != 0) { + setState(() { + videoList = [...videoList, ...videos.result]; + _loading = false; + }); + } else { + await Future.delayed(Duration(seconds: 5), () { + _getVideos(); + }); + } } _reloadVideos({int? page}) async { setState(() { videoList = []; - _page = page ?? -1; + _page = page ?? 0; }); await _getVideos(); } @@ -168,32 +177,69 @@ class _VideoListState extends State { ), ), ); - return Scrollbar( - child: NotificationListener( - onNotification: (ScrollNotification notification) { - // double progress = notification.metrics.pixels / - // notification.metrics.maxScrollExtent; - // print("${(progress * 100).toInt()}%"); - // print(notification.metrics.maxScrollExtent - notification.metrics.pixels); - //重新构建 - setState(() { - if (notification.metrics.maxScrollExtent - notification.metrics.pixels < 1000 && !_loading) { - _getVideos(); - } - }); - // print("BottomEdge: ${notification.metrics.extentAfter == 0}"); - return false; - //return true; //放开此行注释后,进度条将失效 - }, - child: SingleChildScrollView( - child: StaggeredGrid.count( - crossAxisCount: 4, - mainAxisSpacing: 0, - crossAxisSpacing: 0, - children: videos, + return Stack( + alignment: Alignment.topCenter, + children: [ + Scrollbar( + child: NotificationListener( + onNotification: (ScrollNotification notification) { + // double progress = notification.metrics.pixels / + // notification.metrics.maxScrollExtent; + // print("${(progress * 100).toInt()}%"); + // print(notification.metrics.maxScrollExtent - notification.metrics.pixels); + //重新构建 + setState(() { + if (notification.metrics.maxScrollExtent - + notification.metrics.pixels < + 1200 && + !_loading) { + _getVideos(); + } + }); + // print("BottomEdge: ${notification.metrics.extentAfter == 0}"); + return false; + //return true; //放开此行注释后,进度条将失效 + }, + child: SingleChildScrollView( + child: StaggeredGrid.count( + crossAxisCount: 4, + mainAxisSpacing: 0, + crossAxisSpacing: 0, + children: videos, + ), + ), ), ), - ), + _loading + ? Positioned( + top: 16, + child: Container( + width: 64, + height: 64, + padding: EdgeInsets.all(4), + decoration: BoxDecoration( + //设置四周圆角 角度 这里的角度应该为 父Container height 的一半 + borderRadius: const BorderRadius.all(Radius.circular(32.0)), + gradient: RadialGradient( + colors: [ + HexColor(Global + .members[Provider.of(context) + .themeMember] + ?.color ?? + '#FFFFFF'), + Color.fromRGBO(255, 255, 255, 0), + ], + radius: 0.6, + ), + ), + child: Image( + image: AssetImage( + 'assets/${Provider.of(context).assets}/loading.gif'), + fit: BoxFit.cover, + ), + )) + : Container() + ], ); } } diff --git a/pubspec.yaml b/pubspec.yaml index d9d6bb9..30aba24 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.3.0+1 +version: 1.3.1+1 environment: sdk: '>=2.18.6 <3.0.0' @@ -85,6 +85,7 @@ flutter: - assets/zao/ - assets/head/ - assets/open/ + - assets/loading/ # To add assets to your application, add an assets section, like this: # assets: # - images/a_dot_burr.jpeg