Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | Package Functions | List of all members
io.flutter.plugin.common.MethodCall Class Reference

Public Member Functions

 MethodCall (@NonNull String method, @Nullable Object arguments)
 
boolean hasArgument (@NonNull String key)
 

Public Attributes

final String method
 
final Object arguments
 

Package Functions

public< T > T arguments ()
 
public< T > T argument (@NonNull String key)
 

Detailed Description

Command object representing a method call on a MethodChannel.

Definition at line 14 of file MethodCall.java.

Constructor & Destructor Documentation

◆ MethodCall()

io.flutter.plugin.common.MethodCall.MethodCall ( @NonNull String  method,
@Nullable Object  arguments 
)
inline

Creates a MethodCall with the specified method name and arguments.

Parameters
methodthe method name String, not null.
argumentsthe arguments, a value supported by the channel's message codec. Possibly, null.

Definition at line 34 of file MethodCall.java.

34 {
35 if (BuildConfig.DEBUG && method == null) {
36 throw new AssertionError("Parameter method must not be null.");
37 }
38 this.method = method;
39 this.arguments = arguments;
40 }

Member Function Documentation

◆ argument()

public< T > T io.flutter.plugin.common.MethodCall.argument ( @NonNull String  key)
inlinepackage

Returns a String-keyed argument of this method call, assuming arguments is a Map or a JSONObject. The static type of the returned result is determined by the call-site.

Parameters
<T>the intended type of the argument.
keythe String key.
Returns
the argument value at the specified key, with static type T, or null, if such an entry is not present.
Exceptions
ClassCastExceptionif arguments can be cast to neither Map nor JSONObject.

Definition at line 68 of file MethodCall.java.

68 {
69 if (arguments == null) {
70 return null;
71 } else if (arguments instanceof Map) {
72 return (T) ((Map<?, ?>) arguments).get(key);
73 } else if (arguments instanceof JSONObject) {
74 return (T) ((JSONObject) arguments).opt(key);
75 } else {
76 throw new ClassCastException();
77 }
78 }
#define T
Definition: precompiler.cc:65

◆ arguments()

public< T > T io.flutter.plugin.common.MethodCall.arguments ( )
inlinepackage

Returns the arguments of this method call with a static type determined by the call-site.

Parameters
<T>the intended type of the arguments.
Returns
the arguments with static type T

Definition at line 50 of file MethodCall.java.

50 {
51 return (T) arguments;
52 }

◆ hasArgument()

boolean io.flutter.plugin.common.MethodCall.hasArgument ( @NonNull String  key)
inline

Returns whether this method call involves a mapping for the given argument key, assuming arguments is a Map or a JSONObject. The value associated with the key, as returned by argument(String), is not considered, and may be null.

Parameters
keythe String key.
Returns
true, if arguments is a Map containing key, or a JSONObject with a mapping for key.
Exceptions
ClassCastExceptionif arguments can be cast to neither Map nor JSONObject.

Definition at line 91 of file MethodCall.java.

91 {
92 if (arguments == null) {
93 return false;
94 } else if (arguments instanceof Map) {
95 return ((Map<?, ?>) arguments).containsKey(key);
96 } else if (arguments instanceof JSONObject) {
97 return ((JSONObject) arguments).has(key);
98 } else {
99 throw new ClassCastException();
100 }
101 }

Member Data Documentation

◆ arguments

final Object io.flutter.plugin.common.MethodCall.arguments

Arguments for the call.

Consider using arguments() for cases where a particular run-time type is expected. Consider using argument(String) when that run-time type is Map or JSONObject.

Definition at line 25 of file MethodCall.java.

◆ method

final String io.flutter.plugin.common.MethodCall.method

The name of the called method.

Definition at line 16 of file MethodCall.java.


The documentation for this class was generated from the following file: