Skip to content

Commit

Permalink
Return null instead of throwing if an instance method is passed to Pl…
Browse files Browse the repository at this point in the history
…uginUtilities.getCallbackHandle (flutter#6260)
  • Loading branch information
jason-simmons authored Sep 19, 2018
1 parent 2e8e96f commit 60c5bb8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/ui/plugins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class PluginUtilities {
// This class is only a namespace, and should not be instantiated or
// extended directly.
factory PluginUtilities._() => null;

static Map<Function, CallbackHandle> _forwardCache =
<Function, CallbackHandle>{};
static Map<CallbackHandle, Function> _backwardCache =
Expand All @@ -49,8 +49,10 @@ abstract class PluginUtilities {
/// null is returned.
static CallbackHandle getCallbackHandle(Function callback) {
assert(callback != null, "'callback' must not be null.");
return _forwardCache.putIfAbsent(callback,
() => new CallbackHandle.fromRawHandle(_getCallbackHandle(callback)));
return _forwardCache.putIfAbsent(callback, () {
final int handle = _getCallbackHandle(callback);
return handle != null ? new CallbackHandle.fromRawHandle(handle) : null;
});
}

/// Get a tear-off of a named top-level or static callback represented by a
Expand Down

0 comments on commit 60c5bb8

Please sign in to comment.