feat(flutter): 接入分类记录收藏与下载授权
This commit is contained in:
1 parent
00280ca0da
commit
cc4d7c5a9d
52 files changed
+4440
-171
No files matched your search
@@ -0,0 +1,29 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../data/services/download_controller.dart';
|
||||
import 'auth_gate.dart';
|
||||
|
||||
/// 详情页与播放页共用的下载授权入口。
|
||||
///
|
||||
/// 未登录先走登录闸;业务拒绝时直接展示后端 message。
|
||||
Future<void> requestEpisodeDownload(
|
||||
BuildContext context,
|
||||
String episodeId,
|
||||
) async {
|
||||
if (!await ensureSignedIn(context)) return;
|
||||
if (!context.mounted) return;
|
||||
final result = await context.read<DownloadController>().grant(episodeId);
|
||||
if (!context.mounted) return;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final hasBackendMessage = result.message?.trim().isNotEmpty ?? false;
|
||||
final message = result.ok
|
||||
? l10n.downloadGranted
|
||||
: hasBackendMessage
|
||||
? result.message!
|
||||
: l10n.downloadGrantFailed;
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
Reference in new issue
Block a user