fluttercommunity / flutter_downloader

Flutter Downloader - A plugin for creating and managing download tasks.
https://pub.dev/packages/flutter_downloader
BSD 3-Clause "New" or "Revised" License
919 stars 517 forks source link

'callbackHandle != null': callback must be a top-level or a static function #215

Closed BedRockGx closed 4 years ago

BedRockGx commented 4 years ago

APP flash back!!!

Unhandled Exception: 'package:flutter_downloader/src/downloader.dart': Failed assertion: line 388 pos 12: 'callbackHandle != null': callback must be a top-level or a static function

josecaseiro commented 4 years ago

Same error for me. I think the documentation ins't clear

hnvn commented 4 years ago

Have a look at example codes

lijing89 commented 4 years ago

看看示例代码

AndroidManifest.xml => <application android:name=".MyApplication" android:label="kuaichuan" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher"> <activity android:name=".MainActivity"

add MyApplication.java 屏幕快照 2020-01-12 下午10 08 48

MyApplication.java =>

package xxx.xxxxxx;

import io.flutter.app.FlutterApplication; import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugins.GeneratedPluginRegistrant; import vn.hunghd.flutterdownloader.FlutterDownloaderPlugin;

public class MyApplication extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback { @Override public void registerWith(PluginRegistry registry) { GeneratedPluginRegistrant.registerWith(registry); // FlutterDownloaderPlugin.registerWith(registry.registrarFor("vn.hunghd.flutterdownloader.FlutterDownloaderPlugin")); } }

but it not work,always is this question.

E/flutter (22756): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: 'package:flutter_downloader/src/downloader.dart': Failed assertion: line 388 pos 12: 'callbackHandle != null': callback must be a top-level or a static function E/flutter (22756): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:40:39) E/flutter (22756): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5) E/flutter (22756): #2 FlutterDownloader.registerCallback (package:flutter_downloader/src/downloader.dart:388:12) E/flutter (22756): #3 _FPIndexPageState.executeDownload (package:fast_pass/app/pages/home/fp_index_page.dart:628:23) E/flutter (22756): E/flutter (22756): #4 _FPIndexPageState.checkPermission (package:fast_pass/app/pages/home/fp_index_page.dart:784:7) E/flutter (22756): E/flutter (22756): #5 _FPIndexPageState._launch (package:fast_pass/app/pages/home/fp_index_page.dart:556:9) E/flutter (22756): E/flutter (22756): #6 _FPIndexPageState._showNewVersionAppDialog.. (package:fast_pass/app/pages/home/fp_index_page.dart:536:19) E/flutter (22756): #7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14) E/flutter (22756): #8 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:711:32) E/flutter (22756): #9 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter (22756): #10 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11) E/flutter (22756): #11 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7) E/flutter (22756): #12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9) E/flutter (22756): #13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13) E/flutter (22756): #14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11) E/flutter (22756): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) E/flutter (22756): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter (22756): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter (22756): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter (22756): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) E/flutter (22756): #20 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter (22756): #21 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter (22756): #22 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7) E/flutter (22756): #23 _invoke1 (dart:ui/hooks.dart:250:10) E/flutter (22756): #24 _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5) E/flutter (22756): D/HwCustConnectivityManagerImpl(22756): isBlockNetworkRequestByNonAis, INVALID_SUBSCRIPTION_ID D/ConnectivityManager(22756): requestNetwork and the calling app is: net.kuaichuan D/AndroidRuntime(22756): Shutting down VM W/net.kuaichuan(22756): Accessing hidden method Lcom/msic/qarth/PatchStore;->createDisableExceptionQarthFile(Ljava/lang/Throwable;)Z (blacklist, JNI) E/net.kuaichuan(22756): [qarth_debug:] get PatchStore::createDisableExceptionQarthFile method fail. E/AndroidRuntime(22756): FATAL EXCEPTION: main E/AndroidRuntime(22756): Process: net.kuaichuan, PID: 22756 E/AndroidRuntime(22756): java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.app.Activity.getExternalFilesDir(java.lang.String)' on a null object reference E/AndroidRuntime(22756): at io.flutter.plugins.imagepickersaver.ImagePickerSaverPlugin.registerWith(ImagePickerSaverPlugin.java:31) E/AndroidRuntime(22756): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:41) E/AndroidRuntime(22756): at net.kuaichuan.MyApplication.registerWith(MyApplication.java:11) E/AndroidRuntime(22756): at vn.hunghd.flutterdownloader.DownloadWorker.startBackgroundIsolate(DownloadWorker.java:124) E/AndroidRuntime(22756): at vn.hunghd.flutterdownloader.DownloadWorker.access$000(DownloadWorker.java:59) E/AndroidRuntime(22756): at vn.hunghd.flutterdownloader.DownloadWorker$1.run(DownloadWorker.java:97) E/AndroidRuntime(22756): at android.os.Handler.handleCallback(Handler.java:907) E/AndroidRuntime(22756): at android.os.Handler.dispatchMessage(Handler.java:105) E/AndroidRuntime(22756): at android.os.Looper.loop(Looper.java:216) E/AndroidRuntime(22756): at android.app.ActivityThread.main(ActivityThread.java:7586) E/AndroidRuntime(22756): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(22756): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) E/AndroidRuntime(22756): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) W/net.kuaichuan(22756): Accessing hidden method Landroid/telephony/TelephonyManager;->getSimCount()I (light greylist, reflection) W/net.kuaichuan(22756): Accessing hidden method Landroid/telephony/TelephonyManager;->getSimSerialNumber(I)Ljava/lang/String; (light greylist, reflection) W/net.kuaichuan(22756): Accessing hidden method Landroid/telephony/TelephonyManager;->getSubscriberId(I)Ljava/lang/String; (light greylist, reflection) W/net.kuaichuan(22756): Accessing hidden method Landroid/telephony/SubscriptionManager;->getSubId(I)[I (light greylist, reflection) E/libc (22756): Access denied finding property "vendor.cellular.ril.imsi" D/NetworkSecurityConfig(22756): No Network Security Config specified, using platform default I/Process (22756): Sending signal. PID: 22756 SIG: 9 Lost connection to device.

why?

hnvn commented 4 years ago

Have a look at this document

sahil-ingeniousmindslab commented 1 year ago

APP flash back!!!

Unhandled Exception: 'package:flutter_downloader/src/downloader.dart': Failed assertion: line 388 pos 12: 'callbackHandle != null': callback must be a top-level or a static function

==> Solucation

Future initLocalNotifications() async { const iOS = DarwinInitializationSettings(); const android = AndroidInitializationSettings('@drawable/ic_launcher'); const settings = InitializationSettings(android: android, iOS: iOS); await _localNotifications.initialize( settings, onDidReceiveNotificationResponse: (playload) { var message = RemoteMessage.fromMap(jsonDecode(playload.payload!)); handleMessage(message); }, );

final platform = _localNotifications.resolvePlatformSpecificImplementation<
    AndroidFlutterLocalNotificationsPlugin>();
await platform?.createNotificationChannel(_andriodChannel);

}

sahil-viradiya commented 1 year ago

APP flash back!!!

Unhandled Exception: 'package:flutter_downloader/src/downloader.dart': Failed assertion: line 388 pos 12: 'callbackHandle != null': callback must be a top-level or a static function

==> Solucation

Future initLocalNotifications() async { const iOS = DarwinInitializationSettings(); const android = AndroidInitializationSettings('@drawable/ic_launcher'); const settings = InitializationSettings(android: android, iOS: iOS); await _localNotifications.initialize( settings, onDidReceiveNotificationResponse: (playload) { var message = RemoteMessage.fromMap(jsonDecode(playload.payload!)); handleMessage(message); }, );

final platform = _localNotifications.resolvePlatformSpecificImplementation<
    AndroidFlutterLocalNotificationsPlugin>();
await platform?.createNotificationChannel(_andriodChannel);

}