fluttercommunity / fluttercommunity/flutter_downloader
Loop request
- Dominant language
- Kotlin
- Stars
- 940
- Forks
- 561
- Avg merge
- 1h 18m
- Merged PRs (30d)
- 1
Description
I'm a newbie in flutter. I have an issue and I don't know what I wrong, please help me!
With this page https://taiebooktruyen.com/. I can download success files in browser of device, but an issue occur when I download in my app:
1/ Success for the first download (ex: file A)
2/ Loop request forever from the second download with other files (ex: file A, B, C...)
Note: I download well on other pages.
this is log loop:
`D/DownloadWorker( 8298): Open connection to https://doc-10-6o-docs.googleusercontent.com/docs/securesc/ebfnu9o3vn9n3dhugonr8e71kqvrj630/c1s8937hulj5mopf45dc56kuqiik6nrv/1633098675000/01053825269901642775/13171638854300081809Z/1rPC7lejRnOhUI7BVZP9lax_d581skLmv?nonce=bpnmh4ke86md0&user=*&hash=t14s9ie6ln5gb2vnf7168ra7idv35h57
D/DownloadWorker( 8298): Headers = {"DownloadSession": "1633098721179"}
D/DownloadWorker( 8298): Response with redirection code
D/DownloadWorker( 8298): Location = https://docs.google.com/nonceSigner?nonce=2hk248mscdhe6&continue=https://doc-10-6o-docs.googleusercontent.com/docs/securesc/ebfnu9o3vn9n3dhugonr8e71kqvrj630/c1s8937hulj5mopf45dc56kuqiik6nrv/1633098675000/01053825269901642775/13171638854300081809Z/1rPC7lejRnOhUI7BVZP9lax_d581skLmv?nonce%3Dbpnmh4ke86md0%26user%3D*%26hash%3Dt14s9ie6ln5gb2vnf7168ra7idv35h57&hash=cksddcpih59jcr0rgeaaseq2eg4rgvqn
D/DownloadWorker( 8298): New url: https://docs.google.com/nonceSigner?nonce=2hk248mscdhe6&continue=https://doc-10-6o-docs.googleusercontent.com/docs/securesc/ebfnu9o3vn9n3dhugonr8e71kqvrj630/c1s8937hulj5mopf45dc56kuqiik6nrv/1633098675000/01053825269901642775/13171638854300081809Z/1rPC7lejRnOhUI7BVZP9lax_d581skLmv?nonce%3Dbpnmh4ke86md0%26user%3D*%26hash%3Dt14s9ie6ln5gb2vnf7168ra7idv35h57&hash=cksddcpih59jcr0rgeaaseq2eg4rgvqn
D/DownloadWorker( 8298): Open connection to https://docs.google.com/nonceSigner?nonce=2hk248mscdhe6&continue=https://doc-10-6o-docs.googleusercontent.com/docs/securesc/ebfnu9o3vn9n3dhugonr8e71kqvrj630/c1s8937hulj5mopf45dc56kuqiik6nrv/1633098675000/01053825269901642775/13171638854300081809Z/1rPC7lejRnOhUI7BVZP9lax_d581skLmv?nonce%3Dbpnmh4ke86md0%26user%3D*%26hash%3Dt14s9ie6ln5gb2vnf7168ra7idv35h57&hash=cksddcpih59jcr0rgeaaseq2eg4rgvqn
D/DownloadWorker( 8298): Headers = {"DownloadSession": "1633098721179"}
D/DownloadWorker( 8298): Response with redirection code
D/DownloadWorker( 8298): Location = https://doc-10-6o-docs.googleusercontent.com/docs/securesc/ebfnu9o3vn9n3dhugonr8e71kqvrj630/c1s8937hulj5mopf45dc56kuqiik6nrv/1633098675000/01053825269901642775/13171638854300081809Z/1rPC7lejRnOhUI7BVZP9lax_d581skLmv?nonce=2hk248mscdhe6&user=*&hash=fcai8djiiju0eah4chj8l74s2qv0c54o
D/DownloadWorker( 8298): New url: https://doc-10-6o-docs.googleusercontent.com/docs/securesc/ebfnu9o3vn9n3dhugonr8e71kqvrj630/c1s8937hulj5mopf45dc56kuqiik6nrv/1633098675000/01053825269901642775/13171638854300081809Z/1rPC7lejRnOhUI7BVZP9lax_d581skLmv?nonce=2hk248mscdhe6&user=*&hash=fcai8djiiju0eah4chj8l74s2qv0c54o`
this is my code:
`import 'dart:async';
import 'dart:isolate';
import 'dart:ui';
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';
import 'package:permission_handler/permission_handler.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();
await Permission.storage.request();
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State {
late InAppWebViewController webView;
ReceivePort _port = ReceivePort();
@override
void initState() {
super.initState();
_downloadListener();
}
@override
void dispose() {
IsolateNameServer.removePortNameMapping('downloader_send_port');
super.dispose();
}
_downloadListener() async {
IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
_port.listen((dynamic data) async {
print("data: " + data.toString());
});
FlutterDownloader.registerCallback(downloadCallback);
}
static Future downloadCallback(String id, DownloadTaskStatus status, int progress) async {
final SendPort? send = IsolateNameServer.lookupPortByName('downloader_send_port');
send?.send([id, status, progress]);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('InAppWebView Example'),
),
body: Container(
child: Column(children: [
Expanded(
child: InAppWebView(
initialUrlRequest: URLRequest(url: Uri.parse("https://taiebooktruyen.com/")),
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useOnDownloadStart: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (controller, url) {
},
onLoadStop: (controller, url) {
},
onDownloadStart: (controller, url) async {
print("onDownloadStart $url");
final taskId = await FlutterDownloader.enqueue(
url: url.toString(),
headers: {"DownloadSession": DateTime.now().millisecondsSinceEpoch.toString()},
savedDir: (await getExternalStorageDirectory())!.path,
showNotification: true, // show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
},
))
])),
),
);
}
}`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the second-download case at https://taiebooktruyen.com/ and trace the onDownloadStart handler through FlutterDownloader.enqueue in the supplied example. Compare the first and later requests, especially the DownloadSession header and repeated redirects shown in the log. Done means successive downloads complete without looping while downloads from other pages continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100