Kavishka Rajapakshe
Kavishka Rajapakshe

Reputation: 123

Error: UnimplementedError when Intializing flutter downloader

I've created a app where I can download a file through the server.The file can be of type image,video ,pdf or text.For this I've used flutter_downloader package

class ResourceScreen extends StatefulWidget {

 @override
 _ResourceScreenState createState() => _ResourceScreenState();
}

class _ResourceScreenState extends State<ResourceScreen> {
  ReceivePort _port = ReceivePort();

 @override
 void initState() {
super.initState();

IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
_port.listen((dynamic data) {
  String id = data[0];
  DownloadTaskStatus status = data[1];
  int progress = data[2];
  setState((){ });
});

  FlutterDownloader.registerCallback(downloadCallback);
  }

 @override
 void dispose() {
   IsolateNameServer.removePortNameMapping('downloader_send_port');
   super.dispose();
  }

   static void downloadCallback(String id, DownloadTaskStatus status, int progress) {
   final SendPort send = IsolateNameServer.lookupPortByName('downloader_send_port')!;
    send.send([id, status, progress]);
   }


   void _download(String url) async {
     final status = await Permission.storage.request();

if(status.isGranted) {
  final id = await FlutterDownloader.enqueue(
    url: url,
    savedDir: '/storage/emulated/0/Download/',
    showNotification: true,
    openFileFromNotification: true,
  );
} else {
  print('Permission Denied');
}}

and after creating the UI in the class, I called this method to download

_download(formatURL(requiredList[index].file));

The function works totally fine but when I initialize the flutter downloader in my main,

WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();

I get

Error: UnimplementedError
at Object.throw_ [as throw] (http://localhost:54969/dart_sdk.js:5061:11)
at Function.getCallbackHandle (http://localhost:54969/dart_sdk.js:129478:17)
at initialize (http://localhost:54969/packages/flutter_downloader/src/downloader.dart.lib.js:77:58)
at initialize.next (<anonymous>)
at runBody (http://localhost:54969/dart_sdk.js:38659:34)
at Object._async [as async] (http://localhost:54969/dart_sdk.js:38690:7)
at Function.initialize (http://localhost:54969/packages/flutter_downloader/src/downloader.dart.lib.js:74:20)
at mainCommon (http://localhost:54969/packages/care_giver_app/main_common.dart.lib.js:65:42)
at mainCommon.next (<anonymous>)
at runBody (http://localhost:54969/dart_sdk.js:38659:34)
at Object._async [as async] (http://localhost:54969/dart_sdk.js:38690:7)
at Object.mainCommon (http://localhost:54969/packages/care_giver_app/main_common.dart.lib.js:63:18)
at main (http://localhost:54969/packages/care_giver_app/main_dev.dart.lib.js:16:25)
at main.next (<anonymous>)
at runBody (http://localhost:54969/dart_sdk.js:38659:34)
at Object._async [as async] (http://localhost:54969/dart_sdk.js:38690:7)
at main (http://localhost:54969/packages/care_giver_app/main_dev.dart.lib.js:15:18)
at main (http://localhost:54969/web_entrypoint.dart.lib.js:37:29)
at main.next (<anonymous>)
at http://localhost:54969/dart_sdk.js:38640:33
at _RootZone.runUnary (http://localhost:54969/dart_sdk.js:38511:59)
at _FutureListener.thenAwait.handleValue (http://localhost:54969/dart_sdk.js:33713:29)
at handleValueCallback (http://localhost:54969/dart_sdk.js:34265:49)
at Function._propagateToListeners (http://localhost:54969/dart_sdk.js:34303:17)
at _Future.new.[_completeWithValue] (http://localhost:54969/dart_sdk.js:34151:23)
at http://localhost:54969/dart_sdk.js:33377:46
at _RootZone.runUnary (http://localhost:54969/dart_sdk.js:38511:59)
at _FutureListener.then.handleValue (http://localhost:54969/dart_sdk.js:33713:29)
at handleValueCallback (http://localhost:54969/dart_sdk.js:34265:49)
at Function._propagateToListeners (http://localhost:54969/dart_sdk.js:34303:17)
at _Future.new.[_completeWithValue] (http://localhost:54969/dart_sdk.js:34151:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:54969/dart_sdk.js:34172:35)
at Object._microtaskLoop (http://localhost:54969/dart_sdk.js:38778:13)
at _startMicrotaskLoop (http://localhost:54969/dart_sdk.js:38784:13)
at http://localhost:54969/dart_sdk.js:34519:9

Please help!!!

Upvotes: 1

Views: 2661

Answers (2)

kahan x10
kahan x10

Reputation: 285

Always keep in mind to re-install the app after implementing any feature that depends on or access native operations.

Upvotes: 2

icp
icp

Reputation: 174

configuration needed for android and ios

for android need to add this in your manifest

<provider
android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
android:authorities="${applicationId}.flutter_downloader.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/provider_paths"/>

for iOS enable background mode and add sqlite in frameworks and library from Xcode. for more reference checkout https://pub.dev/packages/flutter_downloader

Upvotes: 1

Related Questions