I am trying to use flutter_downloader for downloads within InAppWebView. I am trying to use onDownloadStartRequest function of InAppWebViewController to access flutter_downloader download task function, _requestDownload from another file. But I'm getting this error
The method '_requestDownload' isn't defined for the type '_WebViewTabState'. (Documentation) Try correcting the name to the name of an existing method, or defining a method named '_requestDownload'.
How can I use global key to access that method from _WebViewTabState?
webview_tab.dart where I'am trying to access _requestDownload function:
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: _buildWebView(),
);
}
InAppWebView _buildWebView() {
var browserModel = Provider.of<BrowserModel>(context, listen: true);
var settings = browserModel.getSettings();
var currentWebViewModel = Provider.of<WebViewModel>(context, listen: true);
if (Util.isAndroid()) {
InAppWebViewController.setWebContentsDebuggingEnabled(
settings.debuggingEnabled);
}
//----Other code---
return InAppWebView(
key: webViewTabStateKey,
initialUrlRequest: URLRequest(url: widget.webViewModel.url),
initialSettings: initialSettings,
onWebViewCreated: (controller) async {//--code}
onDownloadStartRequest: (controller, downloadStartRequest) async {
await _requestDownload(TaskInfo()); //ERROR HERE
},
),
}
downloads_page.dart where _requestDownload() function is defined.
class _DownloadsPageState extends State<DownloadsPage> {
List<TaskInfo>? _tasks;
late List<ItemHolder> _items;
late bool _showContent;
late bool _permissionReady;
late bool _saveInPublicStorage;
late String _localPath;
final ReceivePort _port = ReceivePort();
//Isolate Code
//Download Request
Future<void> _requestDownload(TaskInfo task) async {
var hasStoragePermission = await Permission.storage.isGranted;
if (!hasStoragePermission) {
final status = await Permission.storage.request();
hasStoragePermission = status.isGranted;
}
if (hasStoragePermission) {
task.taskId = await FlutterDownloader.enqueue(
url: task.link!,
headers: {'auth': 'test_for_sql_encoding'},
savedDir: _localPath,
saveInPublicStorage: _saveInPublicStorage,
);
}
}
@override
Widget build(BuildContext context) {
}
}