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