mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-22 03:37:30 +08:00
fix: class to dart3 record
This commit is contained in:
@@ -222,18 +222,12 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
|
|||||||
error: (error, trace) => Text("$error"),
|
error: (error, trace) => Text("$error"),
|
||||||
loading: () => const MyProgressIndicator());
|
loading: () => const MyProgressIndicator());
|
||||||
} else {
|
} else {
|
||||||
var torrents = ref.watch(
|
return Consumer(
|
||||||
mediaTorrentsDataProvider(TorrentQuery(mediaId: widget.id))
|
builder: (context, ref, child) {
|
||||||
.future);
|
var torrents = ref.watch(mediaTorrentsDataProvider(
|
||||||
return FutureBuilder(
|
(mediaId: widget.id, seasonNumber: 0, episodeNumber: 0)));
|
||||||
future: torrents,
|
return torrents.when(
|
||||||
builder: (context, snapshot) {
|
data: (v) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
// 请求失败,显示错误
|
|
||||||
return Text("Error: ${snapshot.error}");
|
|
||||||
} else {
|
|
||||||
final v = snapshot.data!;
|
|
||||||
if (v.isEmpty) {
|
if (v.isEmpty) {
|
||||||
return const Center(
|
return const Center(
|
||||||
child: Text("无可用资源"),
|
child: Text("无可用资源"),
|
||||||
@@ -260,9 +254,11 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
|
|||||||
icon: const Icon(Icons.download),
|
icon: const Icon(Icons.download),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ref
|
ref
|
||||||
.read(mediaTorrentsDataProvider(
|
.read(mediaTorrentsDataProvider((
|
||||||
TorrentQuery(mediaId: widget.id))
|
mediaId: widget.id,
|
||||||
.notifier)
|
seasonNumber: 0,
|
||||||
|
episodeNumber: 0
|
||||||
|
)).notifier)
|
||||||
.download(torrent)
|
.download(torrent)
|
||||||
.then((v) => Utils.showSnakeBar(
|
.then((v) => Utils.showSnakeBar(
|
||||||
"开始下载:${torrent.name}"))
|
"开始下载:${torrent.name}"))
|
||||||
@@ -273,11 +269,11 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
|
|||||||
]);
|
]);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
} else {
|
error: (error, trace) => Text("$error"),
|
||||||
return MyProgressIndicator();
|
loading: () => const MyProgressIndicator());
|
||||||
}
|
},
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -131,29 +131,35 @@ var mediaTorrentsDataProvider = AsyncNotifierProvider.autoDispose
|
|||||||
.family<MediaTorrentResource, List<TorrentResource>, TorrentQuery>(
|
.family<MediaTorrentResource, List<TorrentResource>, TorrentQuery>(
|
||||||
MediaTorrentResource.new);
|
MediaTorrentResource.new);
|
||||||
|
|
||||||
class TorrentQuery {
|
// class TorrentQuery {
|
||||||
final String mediaId;
|
// final String mediaId;
|
||||||
final int seasonNumber;
|
// final int seasonNumber;
|
||||||
final int episodeNumber;
|
// final int episodeNumber;
|
||||||
TorrentQuery(
|
// TorrentQuery(
|
||||||
{required this.mediaId, this.seasonNumber = 0, this.episodeNumber = 0});
|
// {required this.mediaId, this.seasonNumber = 0, this.episodeNumber = 0});
|
||||||
Map<String, dynamic> toJson() {
|
// Map<String, dynamic> toJson() {
|
||||||
final Map<String, dynamic> data = <String, dynamic>{};
|
// final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
data["id"] = int.parse(mediaId);
|
// data["id"] = int.parse(mediaId);
|
||||||
data["season"] = seasonNumber;
|
// data["season"] = seasonNumber;
|
||||||
data["episode"] = episodeNumber;
|
// data["episode"] = episodeNumber;
|
||||||
return data;
|
// return data;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
typedef TorrentQuery =({String mediaId, int seasonNumber, int episodeNumber});
|
||||||
|
|
||||||
class MediaTorrentResource extends AutoDisposeFamilyAsyncNotifier<
|
class MediaTorrentResource extends AutoDisposeFamilyAsyncNotifier<
|
||||||
List<TorrentResource>, TorrentQuery> {
|
List<TorrentResource>, TorrentQuery> {
|
||||||
TorrentQuery? query;
|
|
||||||
@override
|
@override
|
||||||
FutureOr<List<TorrentResource>> build(TorrentQuery arg) async {
|
FutureOr<List<TorrentResource>> build(TorrentQuery arg) async {
|
||||||
query = arg;
|
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
var resp = await dio.post(APIs.availableTorrentsUrl, data: arg.toJson());
|
var resp = await dio.post(APIs.availableTorrentsUrl, data: {
|
||||||
|
"id": int.parse(arg.mediaId),
|
||||||
|
"season": arg.seasonNumber,
|
||||||
|
"episode": arg.episodeNumber
|
||||||
|
});
|
||||||
var rsp = ServerResponse.fromJson(resp.data);
|
var rsp = ServerResponse.fromJson(resp.data);
|
||||||
if (rsp.code != 0) {
|
if (rsp.code != 0) {
|
||||||
throw rsp.message;
|
throw rsp.message;
|
||||||
@@ -163,7 +169,11 @@ class MediaTorrentResource extends AutoDisposeFamilyAsyncNotifier<
|
|||||||
|
|
||||||
Future<void> download(TorrentResource res) async {
|
Future<void> download(TorrentResource res) async {
|
||||||
final data = res.toJson();
|
final data = res.toJson();
|
||||||
data.addAll(query!.toJson());
|
data.addAll({
|
||||||
|
"id": int.parse(arg.mediaId),
|
||||||
|
"season": arg.seasonNumber,
|
||||||
|
"episode": arg.episodeNumber
|
||||||
|
});
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
var resp = await dio.post(APIs.downloadTorrentUrl, data: data);
|
var resp = await dio.post(APIs.downloadTorrentUrl, data: data);
|
||||||
var rsp = ServerResponse.fromJson(resp.data);
|
var rsp = ServerResponse.fromJson(resp.data);
|
||||||
|
|||||||
@@ -244,36 +244,22 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showAvailableTorrents(String id, int season, int episode) {
|
Future<void> showAvailableTorrents(String id, int season, int episode) {
|
||||||
final torrents = ref.watch(mediaTorrentsDataProvider(TorrentQuery(
|
|
||||||
mediaId: id, seasonNumber: season, episodeNumber: episode))
|
|
||||||
.future);
|
|
||||||
|
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
return Consumer(builder: (context, ref, _) {
|
||||||
|
final torrents = ref.watch(mediaTorrentsDataProvider(
|
||||||
|
(mediaId: id, seasonNumber: season, episodeNumber: episode)));
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text("资源"),
|
//title: Text("资源"),
|
||||||
content: FutureBuilder(
|
content: SelectionArea(
|
||||||
future: torrents,
|
child: SizedBox(width: 800, height: 400,child: torrents.when(
|
||||||
builder: (context, snapshot) {
|
data: (v) {
|
||||||
return SelectionArea(
|
|
||||||
child: Container(
|
|
||||||
constraints:
|
|
||||||
BoxConstraints(maxHeight: 400, maxWidth: 1000),
|
|
||||||
child: () {
|
|
||||||
if (snapshot.connectionState ==
|
|
||||||
ConnectionState.done) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
// 请求失败,显示错误
|
|
||||||
return Text("Error: ${snapshot.error}");
|
|
||||||
} else {
|
|
||||||
// 请求成功,显示数据
|
|
||||||
final v = snapshot.data;
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: DataTable(
|
child: DataTable(
|
||||||
dataTextStyle:
|
dataTextStyle: TextStyle(fontSize: 12, height: 0),
|
||||||
TextStyle(fontSize: 14, height: 0),
|
|
||||||
columns: const [
|
columns: const [
|
||||||
DataColumn(label: Text("名称")),
|
DataColumn(label: Text("名称")),
|
||||||
DataColumn(label: Text("大小")),
|
DataColumn(label: Text("大小")),
|
||||||
@@ -281,46 +267,42 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
DataColumn(label: Text("peers")),
|
DataColumn(label: Text("peers")),
|
||||||
DataColumn(label: Text("操作"))
|
DataColumn(label: Text("操作"))
|
||||||
],
|
],
|
||||||
rows: List.generate(v!.length, (i) {
|
rows: List.generate(v.length, (i) {
|
||||||
final torrent = v[i];
|
final torrent = v[i];
|
||||||
return DataRow(cells: [
|
return DataRow(cells: [
|
||||||
DataCell(Text("${torrent.name}")),
|
DataCell(Text("${torrent.name}")),
|
||||||
DataCell(Text(
|
DataCell(Text(
|
||||||
"${torrent.size?.readableFileSize()}")),
|
"${torrent.size?.readableFileSize()}")),
|
||||||
DataCell(
|
DataCell(Text("${torrent.seeders}")),
|
||||||
Text("${torrent.seeders}")),
|
|
||||||
DataCell(Text("${torrent.peers}")),
|
DataCell(Text("${torrent.peers}")),
|
||||||
DataCell(IconButton(
|
DataCell(IconButton(
|
||||||
icon: const Icon(Icons.download),
|
icon: const Icon(Icons.download),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ref
|
await ref
|
||||||
.read(mediaTorrentsDataProvider(
|
.read(mediaTorrentsDataProvider((
|
||||||
TorrentQuery(
|
|
||||||
mediaId: id,
|
mediaId: id,
|
||||||
seasonNumber:
|
seasonNumber: season,
|
||||||
season,
|
episodeNumber: episode
|
||||||
episodeNumber:
|
)).notifier)
|
||||||
episode))
|
|
||||||
.notifier)
|
|
||||||
.download(torrent)
|
.download(torrent)
|
||||||
.then((v) {
|
.then((v) {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
Utils.showSnakeBar(
|
Utils.showSnakeBar(
|
||||||
"开始下载:${torrent.name}");
|
"开始下载:${torrent.name}");
|
||||||
}).onError((error, trace) =>
|
}).onError((error, trace) =>
|
||||||
Utils.showSnakeBar(
|
Utils.showSnakeBar("下载失败:$error"));
|
||||||
"下载失败:$error"));
|
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
]);
|
]);
|
||||||
})));
|
})));
|
||||||
}
|
},
|
||||||
} else {
|
error: (err, trace) {
|
||||||
// 请求未结束,显示loading
|
return Text("$err");
|
||||||
return MyProgressIndicator();
|
},
|
||||||
}
|
loading: () => const MyProgressIndicator()),
|
||||||
}()));
|
),) );
|
||||||
}));
|
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user