How to Download Blob video from Flutter inAppWebView

36 views Asked by At

I am trying to download a video file from a website which records your video and lets you download them using blob. the websites shows saved to download but nothing happens.

heres my code:

// ignore_for_file: deprecated_member_use

import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:path_provider/path_provider.dart';

class MyWebsite extends StatefulWidget {
  const MyWebsite({super.key});

  @override
  State<MyWebsite> createState() {
    return _MyWebsiteState();
  }
}

class _MyWebsiteState extends State<MyWebsite> {
  late InAppWebViewController inAppWebViewController;

  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text('Optimised Surveillance'),
      ),
      body: Stack(
        children: [
          InAppWebView(
            initialUrlRequest: URLRequest(
              url: WebUri("https://watchtower-ai.vercel.app/"),
            ),
            initialOptions: InAppWebViewGroupOptions(
                crossPlatform: InAppWebViewOptions(
              useOnDownloadStart: true,
            )),
            onWebViewCreated: (InAppWebViewController controller) {
              inAppWebViewController = controller;
            },
            androidOnPermissionRequest: (controller, origin, resources) async {
              return PermissionRequestResponse(
                  resources: resources,
                  action: PermissionRequestResponseAction.GRANT);
            },
            onDownloadStart: (controller, url) async {
              print("onDownloadStart $url");
              final taskId = await FlutterDownloader.enqueue(
                url: url.toString(),
                savedDir: (await getExternalStorageDirectory())!.path,
                showNotification: true,
                openFileFromNotification: true
              );
            },
          ),
        ],
      ),
    );
  }
}

The url is being printed like this one:

I/flutter (14502): onDownloadStart blob:https://watchtower-ai.vercel.app/ae18d63a-88dd-4c5c-a6cb-fd89ad64aeec

VS Code screenshot

Can someone help me please?

0

There are 0 answers