Hello,
When using the latest version of the Adivery Flutter plugin (4.8.8) on Dart 3, an unhandled exception is thrown in the Flutter framework whenever a MethodChannel event (like onAdLoaded, onAdLoadFailed, etc.) is received from the native side.
This happens because the handle(MethodCall call) methods in both BannerAdEventHandler and NativeAdEventHandler return a boolean true while their return type is declared as Future<dynamic>, but the method itself is not marked as async.
Stacktrace
NoSuchMethodError: Class 'bool' has no instance method 'then'.
Receiver: true
Tried calling: then<dynamic>(Closure: (dynamic) => dynamic)
at BannerAdEventHandler.handle (package:adivery/adivery_ads.dart:159)
at MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:608)
Root Cause
In lib/adivery_ads.dart:
// Missing 'async' keyword here
Future<dynamic> handle(MethodCall call) {
switch (call.method) {
// ...
}
return true as dynamic; // Returns a boolean, but MethodChannel expects a Future
}
Flutter's MethodChannel._handleAsMethodCall tries to call .then() on the returned result. Since true is a bool and not a Future, it throws a NoSuchMethodError which breaks the error handling and app state.
Solution
Add the async keyword to the handle methods in both BannerAdEventHandler and NativeAdEventHandler, or return Future.value(true).
Example Fix:
Future<dynamic> handle(MethodCall call) async {
switch (call.method) {
// ...
}
return true;
}
Please fix this in the next release, as it currently causes apps to crash or silently fail when an ad fails to load. Thank you!
Hello,
When using the latest version of the Adivery Flutter plugin (
4.8.8) on Dart 3, an unhandled exception is thrown in the Flutter framework whenever a MethodChannel event (likeonAdLoaded,onAdLoadFailed, etc.) is received from the native side.This happens because the
handle(MethodCall call)methods in bothBannerAdEventHandlerandNativeAdEventHandlerreturn a booleantruewhile their return type is declared asFuture<dynamic>, but the method itself is not marked asasync.Stacktrace
Root Cause
In
lib/adivery_ads.dart:Flutter's
MethodChannel._handleAsMethodCalltries to call.then()on the returned result. Sincetrueis abooland not aFuture, it throws aNoSuchMethodErrorwhich breaks the error handling and app state.Solution
Add the
asynckeyword to thehandlemethods in bothBannerAdEventHandlerandNativeAdEventHandler, or returnFuture.value(true).Example Fix:
Please fix this in the next release, as it currently causes apps to crash or silently fail when an ad fails to load. Thank you!