flutter_downloader icon indicating copy to clipboard operation
flutter_downloader copied to clipboard

FlutterDownloader.initialize() throw exception on open the downloadScreen again

Open luiey opened this issue 5 years ago • 6 comments

Flutter: 1.12.13+hotfix.8 IDE: VSCode

How to check if the plugin is already initialize? I have read about #154 but I cannot get how to do it.

I have a screen page let's called it downloadScreen.dart. On initState, I will call a Future method to initialize the plugin based from the documentation part

WidgetsFlutterBinding.ensureInitialized(); await FlutterDownloader.initialize(); Note: the plugin must be initialized before using.

If I'm pop the downloadScreen and push back the screen at homeScreen, the run will be exception with FlutterDownloader.initialize() must be called only once!

How to check on initState the plugin has already been initialized?

I'm using VSCode writing for Android device only.

luiey avatar Feb 28 '20 09:02 luiey

You are initializing downloader every time your screen rendered so make a check if downloader already initialized don't do it again.

ffahadMalikk avatar Apr 17 '20 09:04 ffahadMalikk

IMO it's best to initialize your plugins either in main.dart before you even runApp, or in the most outer widged you have. Also for Androids, be sure to use plugin embedding v2, because with v1 this downloaded library bugs out when you don't keep activities.

bakua avatar Apr 17 '20 11:04 bakua

i added await FlutterDownloader.initialize(); in main.dart before runApp() but in release apk i am getting error

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel vn.hunghd/downloader) #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157)

#1 FlutterDownloader.initialize (package:flutter_downloader/src/downloader.dart:36)


in debug apk its working fine... but when i generate release apk and open that in mobile, white screen appear and this error generating in background

anyone have idea about this ?

Bharavi26 avatar Jan 02 '21 10:01 Bharavi26

Any update on this issue?

surveshoeb avatar Feb 10 '21 09:02 surveshoeb

I got a solution by checking count reference for the downloader Object.

1- Initialize the downloader at top level 2- While moving on download screen just check if the downloader alreayd initilize then don't initilize it (use old reference)

It will resolve the issue

ffahadMalikk avatar Feb 10 '21 12:02 ffahadMalikk

i got a solution for this problem, just add this line in manifest

xmlns:tools='http://schemas.android.com/tools'
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools='http://schemas.android.com/tools'
    package="your.package.name">

<queries>

voselo avatar Mar 06 '23 17:03 voselo