flutter_downloader
flutter_downloader copied to clipboard
FlutterDownloader.initialize() throw exception on open the downloadScreen again
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.
You are initializing downloader every time your screen rendered so make a check if downloader already initialized don't do it again.
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.
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 ?
Any update on this issue?
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
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>