Skip to content

Commit

Permalink
handle download request
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Jul 26, 2024
1 parent 68d2ca5 commit 2c53760
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
16 changes: 16 additions & 0 deletions lib/screen/detail/preview_detail/preview_detail_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import 'package:autonomy_flutter/screen/interactive_postcard/postcard_detail_sta
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_view_widget.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/custom_route_observer.dart';
import 'package:autonomy_flutter/util/download_helper.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/view/artwork_common_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -141,6 +143,9 @@ class _ArtworkPreviewWidgetState extends State<ArtworkPreviewWidget>
overriddenHtml: state.overriddenHtml,
isMute: widget.isMute,
focusNode: widget.focusNode,
onDownloadStartRequest: assetToken.isFeralfile
? _onDownloadStartRequest
: null,
);
}

Expand Down Expand Up @@ -176,6 +181,17 @@ class _ArtworkPreviewWidgetState extends State<ArtworkPreviewWidget>
},
);

Future<void> _onDownloadStartRequest(InAppWebViewController controller,
DownloadStartRequest downloadStartRequest) async {
final path = downloadStartRequest.url.toString();
log.info('Download request: $path');
if (path.isEmpty || path.startsWith('blob:')) {
/// to do: notify user
return;
}
await DownloadHelper.downloadFile(path);
}

Widget _artworkView(AssetToken assetToken) => GestureDetector(
onTap: () async {
await _renderingWidget?.pauseOrResume();
Expand Down
2 changes: 2 additions & 0 deletions lib/util/file_helper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:typed_data';

import 'package:autonomy_flutter/util/log.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
Expand Down Expand Up @@ -31,6 +32,7 @@ class FileHelper {
}
}
await file.writeAsBytes(data);
log.info('File saved to: ${file.path}');
return file;
}

Expand Down
22 changes: 12 additions & 10 deletions lib/view/artwork_common_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,17 @@ class GalleryThumbnailPlaceholder extends StatelessWidget {
Widget placeholder(BuildContext context) => const LoadingWidget();

INFTRenderingWidget buildRenderingWidget(
BuildContext context,
AssetToken assetToken, {
int? attempt,
String? overriddenHtml,
bool isMute = false,
Function({int? time, InAppWebViewController? webViewController})? onLoaded,
Function({int? time})? onDispose,
FocusNode? focusNode,
Widget? loadingWidget,
}) {
BuildContext context, AssetToken assetToken,
{int? attempt,
String? overriddenHtml,
bool isMute = false,
Function({int? time, InAppWebViewController? webViewController})? onLoaded,
Function({int? time})? onDispose,
FocusNode? focusNode,
Widget? loadingWidget,
Function(InAppWebViewController controller,
DownloadStartRequest downloadStartRequest)?
onDownloadStartRequest}) {
String mimeType = assetToken.getMimeType;
final renderingWidget = typesOfNFTRenderingWidget(mimeType)
..setRenderWidgetBuilder(RenderingWidgetBuilder(
Expand All @@ -439,6 +440,7 @@ INFTRenderingWidget buildRenderingWidget(
skipViewport: assetToken.scrollable ?? false,
isMute: isMute,
focusNode: focusNode,
onDownloadStartRequest: onDownloadStartRequest,
));

return renderingWidget;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1903,8 +1903,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "039391471be2144e8539c2b71847c3e81b3983e0"
resolved-ref: "039391471be2144e8539c2b71847c3e81b3983e0"
ref: "5dcaf26e895b5ae52fbf25b91a867948ccfd7e61"
resolved-ref: "5dcaf26e895b5ae52fbf25b91a867948ccfd7e61"
url: "https://github.com/autonomy-system/nft-rendering.git"
source: git
version: "1.0.9"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dependencies:
nft_rendering:
git:
url: https://github.com/autonomy-system/nft-rendering.git
ref: 039391471be2144e8539c2b71847c3e81b3983e0
ref: 5dcaf26e895b5ae52fbf25b91a867948ccfd7e61
onesignal_flutter: ^3.3.0
open_settings: ^2.0.2
overlay_support: ^2.0.0
Expand Down

0 comments on commit 2c53760

Please sign in to comment.