Skip to content

Commit

Permalink
DEV UPDTAE:Test picture page
Browse files Browse the repository at this point in the history
  • Loading branch information
misakajimmy committed Jan 26, 2023
1 parent 662db36 commit b28fa96
Show file tree
Hide file tree
Showing 21 changed files with 564 additions and 23 deletions.
5 changes: 5 additions & 0 deletions Jsons/dynamic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dynamic_id": 755129313256275991,
"pictures": "$[]picture",
"sent_at": 1674655644
}
6 changes: 6 additions & 0 deletions Jsons/picture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"img_height": 736,
"img_size": 142.8000030517578,
"img_width": 728,
"img_src": "https://i0.hdslb.com/bfs/new_dyn/bcae4133696af428e6a0cc06efa11a37402993775.jpg"
}
5 changes: 5 additions & 0 deletions Jsons/pictures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"page": 1,
"total": 1,
"result": "$[]dynamic"
}
52 changes: 50 additions & 2 deletions lib/common/Api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:eoe_fans/models/pictures.dart';
import 'package:eoe_fans/models/picturesRequest.dart';
import 'package:eoe_fans/models/version.dart';
import 'package:eoe_fans/models/videos.dart';
import 'package:eoe_fans/models/iResponse.dart';
Expand All @@ -9,6 +9,7 @@ import 'package:flutter/cupertino.dart';

import 'Global.dart';


class Api {
Api([this.context]);

Expand Down Expand Up @@ -56,6 +57,53 @@ class Api {
return tmpVideos;
}

Future<Pictures> picturesRecommend(PicturesRequest params) async {
var tmpPictures = Pictures()
..page=0
..total=0
..result=[];
try {
var paramsData = ({...params.toJson(), 'subscription-key': key});
paramsData.removeWhere((key, value) => value == null);
var r = await dio.get('/pic/recommend',
queryParameters: paramsData);

if (r.statusCode == 200) {
var picturesRes =
IResponse<Pictures>.fromJson(r.data, (json) => Pictures.fromJson(json));
if (picturesRes.data != null) {
tmpPictures = picturesRes.data!;
}
}
} catch(e) {
print(e);
}
return tmpPictures;
}

Future<Pictures> picturesLatest(PicturesRequest params) async {
var tmpPictures = Pictures()
..page=0
..total=0
..result=[];
try {
var paramsData = ({...params.toJson(), 'subscription-key': key});
paramsData.removeWhere((key, value) => value == null);
var r = await dio.get('/pic/latest',
queryParameters: paramsData);

if (r.statusCode == 200) {
var picturesRes =
IResponse<Pictures>.fromJson(r.data, (json) => Pictures.fromJson(json));
if (picturesRes.data != null) {
tmpPictures = picturesRes.data!;
}
}
} catch(e) {
print(e);
}
return tmpPictures;
}
Future<Version> version() async {
var paramsData = ({'subscription-key': key});
paramsData.removeWhere((key, value) => value == null);
Expand Down
15 changes: 15 additions & 0 deletions lib/models/dynamic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:json_annotation/json_annotation.dart';
import "picture.dart";
part 'dynamic.g.dart';

@JsonSerializable()
class Dynamic {
Dynamic();

late num dynamic_id;
late List<Picture> pictures;
late num sent_at;

factory Dynamic.fromJson(Map<String,dynamic> json) => _$DynamicFromJson(json);
Map<String, dynamic> toJson() => _$DynamicToJson(this);
}
20 changes: 20 additions & 0 deletions lib/models/dynamic.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/models/index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export 'cacheConfig.dart' ;
export 'dynamic.dart' ;
export 'picture.dart' ;
export 'pictures.dart' ;
export 'version.dart' ;
export 'video.dart' ;
export 'videos.dart' ;
16 changes: 16 additions & 0 deletions lib/models/picture.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:json_annotation/json_annotation.dart';

part 'picture.g.dart';

@JsonSerializable()
class Picture {
Picture();

late num img_height;
late num img_size;
late num img_width;
late String img_src;

factory Picture.fromJson(Map<String,dynamic> json) => _$PictureFromJson(json);
Map<String, dynamic> toJson() => _$PictureToJson(this);
}
20 changes: 20 additions & 0 deletions lib/models/picture.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions lib/models/pictures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:json_annotation/json_annotation.dart';
import "dynamic.dart";

part 'pictures.g.dart';

enum PicturePageType {
latest,
recommend,
}

@JsonSerializable()
class Pictures {
Pictures();

late num page;
late num total;
late List<Dynamic> result;

factory Pictures.fromJson(Map<String, dynamic> json) =>
_$PicturesFromJson(json);

Map<String, dynamic> toJson() => _$PicturesToJson(this);
}
20 changes: 20 additions & 0 deletions lib/models/pictures.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions lib/models/picturesRequest.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:json_annotation/json_annotation.dart';

part 'picturesRequest.g.dart';

enum PicturesTopic {
@JsonValue(29067608)
zao(id: 29067608, label: 'zao'),
@JsonValue(29069147)
mi(id: 29069147, label: 'mi'),
@JsonValue(28953983)
wan(id: 28953983, label: 'wan'),
@JsonValue(28948378)
mo(id: 28948378, label: 'mo'),
@JsonValue(28950030)
un(id: 28950030, label: 'un'),
@JsonValue(29156150)
eoe(id: 29156150, label: 'eoe'),
@JsonValue(0)
all(id: 0, label: 'all');

final int id;
final String label;

const PicturesTopic({
required this.id,
required this.label,
});

/// 解析从后台传来的值
static PicturesTopic parse(int i) {
return PicturesTopic.values[i];
}
}

@JsonSerializable()
class PicturesRequest {
PicturesRequest();

late PicturesTopic topic_id;
late num page;

factory PicturesRequest.fromJson(Map<String, dynamic> json) =>
_$PicturesRequestFromJson(json);

Map<String, dynamic> toJson() => _$PicturesRequestToJson(this);
}
28 changes: 28 additions & 0 deletions lib/models/picturesRequest.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions lib/routes/mainPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class MainPage extends StatefulWidget {
class _MainPageState extends State<MainPage> {
int _selectedIndex = 0;

final List<Widget> _bodyList = [
const VideoPage(),
const PicturePage(),
const MusicPage(),
];

Future<AppUpgradeInfo?> _checkAppInfo() async {
var r = await Api().version();

Expand Down Expand Up @@ -52,6 +46,12 @@ class _MainPageState extends State<MainPage> {

@override
Widget build(BuildContext context) {
List<Widget> _bodyList = [
_selectedIndex == 0 ? const VideoPage() : Container(),
_selectedIndex == 1 ? const PicturePage() : Container(),
_selectedIndex == 2 ? const MusicPage() : Container(),
];

return Scaffold(
body: Stack(
children: [
Expand All @@ -66,9 +66,11 @@ class _MainPageState extends State<MainPage> {
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/${Provider.of<ThemeModel>(context).assets}/tail_bg.png'),
fit: BoxFit.fill),
image: AssetImage(
'assets/${Provider.of<ThemeModel>(context).assets}/tail_bg.png',
),
fit: BoxFit.fill,
),
color: Colors.transparent),
child: BottomNavigationBar(
elevation: 0,
Expand Down
Loading

0 comments on commit b28fa96

Please sign in to comment.