Skip to content

Commit

Permalink
Web page download file
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Jan 16, 2024
1 parent 42d0178 commit 968fdce
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
53 changes: 45 additions & 8 deletions lib/pages/web/web.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:alist_flutter/generated_api.dart';
import 'package:android_intent_plus/android_intent.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';

Expand Down Expand Up @@ -58,24 +60,56 @@ class _WebScreenState extends State<WebScreen> {
return NavigationActionPolicy.ALLOW;
}
Get.showSnackbar(GetSnackBar(
message:
"shouldOverrideUrlLoading ${navigationAction.request.url}",
message: "是否跳转到其他应用?",
duration: const Duration(seconds: 3),
mainButton: TextButton(
onPressed: () {},
onPressed: () {
final intent = AndroidIntent(
action: "action_view",
data: navigationAction.request.url!.toString());

intent.launchChooser("选择应用");
},
child: const Text('前往'),
)));

return NavigationActionPolicy.CANCEL;
},
onDownloadStartRequest: (controller, url) async {
Get.showSnackbar(GetSnackBar(
message: "是否下载文件? ${url.contentDisposition}",
duration: const Duration(seconds: 3),
mainButton: TextButton(
onPressed: () {},
title: "是否下载文件?",
message: url.suggestedFilename ??
url.contentDisposition ??
url.toString(),
duration: const Duration(seconds: 3),
mainButton: Column(children: [
TextButton(
onPressed: () {
final intent = AndroidIntent(
action: "action_view", data: url.url.toString());
intent.launchChooser("选择应用");
},
child: const Text('选择应用下载'),
),
TextButton(
onPressed: () {
final intent = AndroidIntent(
action: "action_view", data: url.url.toString());
intent.launch();
},
child: const Text('下载'),
)));
),
]),
onTap: (_) {
Clipboard.setData(
ClipboardData(text: url.url.toString()));
Get.closeCurrentSnackbar();
Get.showSnackbar(const GetSnackBar(
message: "下载链接已复制到剪贴板",
duration: Duration(seconds: 1),
));
},
));
},
onLoadStop:
(InAppWebViewController controller, Uri? url) async {
Expand Down Expand Up @@ -117,6 +151,9 @@ class _WebScreenState extends State<WebScreen> {
if (_webViewController != null) {
_webViewController!.reload();
}
_webViewController!.loadUrl(
urlRequest:
URLRequest(url: WebUri("http://coolapk.com")));
},
),
],
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.2.0"
android_intent_plus:
dependency: "direct main"
description:
name: android_intent_plus
sha256: e1c62bb41c90e15083b7fb84dc327fe90396cc9c1445b55ff1082144fabfb4d9
url: "https://pub.dev"
source: hosted
version: "4.0.3"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -264,6 +272,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "16.0.0"
platform:
dependency: transitive
description:
name: platform
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
version: "3.1.4"
plugin_platform_interface:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
get: ^4.6.6
pigeon: ^16.0.0
flutter_inappwebview: ^6.0.0
android_intent_plus: ^4.0.3


dev_dependencies:
Expand Down

0 comments on commit 968fdce

Please sign in to comment.