Skip to content

Commit

Permalink
DEV UPDATE:Fix video count from 1 add loading animate
Browse files Browse the repository at this point in the history
  • Loading branch information
misakajimmy committed Jan 24, 2023
1 parent 72790b4 commit 127ce3c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 48 deletions.
Binary file added assets/mi/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/mo/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/un/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/wan/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/zao/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 20 additions & 17 deletions lib/common/Api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}));
Expand All @@ -31,40 +31,43 @@ class Api {
}

Future<Videos> 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<Videos>.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<Videos>.fromJson(r.data, (json) => Videos.fromJson(json));
if (videoRes.data != null) {
tmpVideos = videoRes.data!;
}
}
} catch (e) {
print(e);
}

return tmpVideos;
}

Future<Version> 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 = ''
..download_url = {}
..updated_at = '';
if (r.statusCode == 200) {
var versionRes =
IResponse<Version>.fromJson(r.data, (json) => Version.fromJson(json));
IResponse<Version>.fromJson(r.data, (json) => Version.fromJson(json));
if (versionRes.data != null) {
tmpVersion = versionRes.data!;
}
Expand Down
106 changes: 76 additions & 30 deletions lib/routes/video/videoList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,7 +29,7 @@ class _VideoListState extends State<VideoList> {
RefreshController(initialRefresh: true);
late final bool? origin;

int _page = -1;
int _page = 0;
MemberEnum? _memberFilter;
VideosRequestOrder _order = VideosRequestOrder.view;

Expand Down Expand Up @@ -56,16 +59,22 @@ class _VideoListState extends State<VideoList> {
: 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();
}
Expand Down Expand Up @@ -168,32 +177,69 @@ class _VideoListState extends State<VideoList> {
),
),
);
return Scrollbar(
child: NotificationListener<ScrollNotification>(
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<ScrollNotification>(
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<ThemeModel>(context)
.themeMember]
?.color ??
'#FFFFFF'),
Color.fromRGBO(255, 255, 255, 0),
],
radius: 0.6,
),
),
child: Image(
image: AssetImage(
'assets/${Provider.of<ThemeModel>(context).assets}/loading.gif'),
fit: BoxFit.cover,
),
))
: Container()
],
);
}
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 127ce3c

Please sign in to comment.