Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
945cfc3e
Commit
945cfc3e
authored
Apr 18, 2017
by
Mikkel Nygaard Ravn
Committed by
GitHub
Apr 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make naming consistent across channel APIs (#9270)
parent
752d6096
Changes
23
Show whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
150 additions
and
151 deletions
+150
-151
engine.version
bin/internal/engine.version
+1
-1
MainActivity.java
...roid/app/src/main/java/com/example/view/MainActivity.java
+7
-9
MainViewController.m
examples/flutter_view/ios/Runner/MainViewController.m
+7
-7
main.dart
examples/flutter_view/lib/main.dart
+2
-2
MainActivity.java
...c/main/java/com/example/platformchannel/MainActivity.java
+12
-12
AppDelegate.m
examples/platform_channel/ios/Runner/AppDelegate.m
+10
-10
main.dart
examples/platform_channel/lib/main.dart
+4
-4
AppDelegate.swift
examples/platform_channel_swift/ios/Runner/AppDelegate.swift
+14
-15
main.dart
examples/platform_channel_swift/lib/main.dart
+4
-4
asset_bundle.dart
packages/flutter/lib/src/services/asset_bundle.dart
+1
-1
binding.dart
packages/flutter/lib/src/services/binding.dart
+2
-2
platform_channel.dart
packages/flutter/lib/src/services/platform_channel.dart
+28
-28
platform_messages.dart
packages/flutter/lib/src/services/platform_messages.dart
+15
-15
system_channels.dart
packages/flutter/lib/src/services/system_channels.dart
+12
-12
service_extensions_test.dart
...ages/flutter/test/foundation/service_extensions_test.dart
+2
-2
platform_channel_test.dart
packages/flutter/test/services/platform_channel_test.dart
+10
-10
platform_messages_test.dart
packages/flutter/test/services/platform_messages_test.dart
+4
-4
system_chrome_test.dart
packages/flutter/test/services/system_chrome_test.dart
+1
-1
binding_test.dart
packages/flutter/test/widgets/binding_test.dart
+1
-1
raw_keyboard_listener_test.dart
...ages/flutter/test/widgets/raw_keyboard_listener_test.dart
+1
-1
test_text_input.dart
packages/flutter_test/lib/src/test_text_input.dart
+1
-1
pluginClass.java.tmpl
...in/java/com/yourcompany/projectName/pluginClass.java.tmpl
+7
-7
pluginClass.m.tmpl
...ools/templates/plugin/ios.tmpl/Classes/pluginClass.m.tmpl
+4
-2
No files found.
bin/internal/engine.version
View file @
945cfc3e
c24a0e51750570f271f860bbffbe082aab4ea72f
2a4434a058d0243447483101160c833029cb3654
examples/flutter_view/android/app/src/main/java/com/example/view/MainActivity.java
View file @
945cfc3e
...
...
@@ -6,9 +6,9 @@ import android.support.design.widget.FloatingActionButton;
import
android.support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.widget.TextView
;
import
io.flutter.plugin.common.
Flutter
MessageChannel
;
import
io.flutter.plugin.common.
Flutter
MessageChannel.MessageHandler
;
import
io.flutter.plugin.common.
Flutter
MessageChannel.Reply
;
import
io.flutter.plugin.common.
Basic
MessageChannel
;
import
io.flutter.plugin.common.
Basic
MessageChannel.MessageHandler
;
import
io.flutter.plugin.common.
Basic
MessageChannel.Reply
;
import
io.flutter.plugin.common.StringCodec
;
import
io.flutter.view.FlutterMain
;
import
io.flutter.view.FlutterView
;
...
...
@@ -20,7 +20,7 @@ public class MainActivity extends AppCompatActivity {
private
static
final
String
CHANNEL
=
"increment"
;
private
static
final
String
EMPTY_MESSAGE
=
""
;
private
static
final
String
PING
=
"ping"
;
private
Flutter
MessageChannel
messageChannel
;
private
Basic
MessageChannel
messageChannel
;
private
String
[]
getArgsFromIntent
(
Intent
intent
)
{
// Before adding more entries to this list, consider that arbitrary
...
...
@@ -57,15 +57,13 @@ public class MainActivity extends AppCompatActivity {
flutterView
=
(
FlutterView
)
findViewById
(
R
.
id
.
flutter_view
);
flutterView
.
runFromBundle
(
FlutterMain
.
findAppBundlePath
(
getApplicationContext
()),
null
);
messageChannel
=
new
FlutterMessageChannel
<
String
>(
flutterView
,
CHANNEL
,
StringCodec
.
INSTANCE
);
messageChannel
=
new
BasicMessageChannel
<>(
flutterView
,
CHANNEL
,
StringCodec
.
INSTANCE
);
messageChannel
.
setMessageHandler
(
new
MessageHandler
<
String
>()
{
@Override
public
void
onMessage
(
String
s
,
Reply
<
String
>
reply
)
{
onFlutterIncrement
();
reply
.
send
(
EMPTY_MESSAGE
);
reply
.
reply
(
EMPTY_MESSAGE
);
}
});
...
...
examples/flutter_view/ios/Runner/MainViewController.m
View file @
945cfc3e
...
...
@@ -12,7 +12,7 @@
@property
(
nonatomic
)
NativeViewController
*
nativeViewController
;
@property
(
nonatomic
)
FlutterViewController
*
flutterViewController
;
@property
(
nonatomic
)
FlutterMessageChannel
*
messageChannel
;
@property
(
nonatomic
)
Flutter
Basic
MessageChannel
*
messageChannel
;
@end
static
NSString
*
const
emptyString
=
@""
;
...
...
@@ -35,20 +35,20 @@ static NSString* const channel = @"increment";
if
([
segue
.
identifier
isEqualToString
:
@"FlutterViewControllerSegue"
])
{
self
.
flutterViewController
=
segue
.
destinationViewController
;
self
.
messageChannel
=
[
FlutterMessageChannel
messageChannelWithName
:
channel
self
.
messageChannel
=
[
Flutter
Basic
MessageChannel
messageChannelWithName
:
channel
binaryMessenger
:
self
.
flutterViewController
codec
:
[
FlutterStringCodec
sharedInstance
]];
MainViewController
*
__weak
weakSelf
=
self
;
[
self
.
messageChannel
setMessageHandler
:
^
(
id
message
,
FlutterReply
Handler
replyHandler
)
{
[
self
.
messageChannel
setMessageHandler
:
^
(
id
message
,
FlutterReply
reply
)
{
[
weakSelf
.
nativeViewController
didReceiveIncrement
];
reply
Handler
(
emptyString
);
reply
(
emptyString
);
}];
}
}
-
(
void
)
didTapIncrementButton
{
[
self
.
messageChannel
sendMessage
:
ping
replyHandler
:
nil
];
[
self
.
messageChannel
sendMessage
:
ping
];
}
@end
examples/flutter_view/lib/main.dart
View file @
945cfc3e
...
...
@@ -29,8 +29,8 @@ class _MyHomePageState extends State<MyHomePage> {
static
const
String
_channel
=
"increment"
;
static
const
String
_pong
=
"pong"
;
static
const
String
_emptyMessage
=
""
;
static
const
Platform
MessageChannel
<
String
>
platform
=
const
Platform
MessageChannel
<
String
>(
_channel
,
const
StringCodec
());
static
const
Basic
MessageChannel
<
String
>
platform
=
const
Basic
MessageChannel
<
String
>(
_channel
,
const
StringCodec
());
int
_counter
=
0
;
...
...
examples/platform_channel/android/app/src/main/java/com/example/platformchannel/MainActivity.java
View file @
945cfc3e
...
...
@@ -15,12 +15,12 @@ import android.os.Build.VERSION_CODES;
import
android.os.Bundle
;
import
io.flutter.app.FlutterActivity
;
import
io.flutter.plugin.common.
Flutter
EventChannel
;
import
io.flutter.plugin.common.
Flutter
EventChannel.EventSink
;
import
io.flutter.plugin.common.
Flutter
EventChannel.StreamHandler
;
import
io.flutter.plugin.common.
Flutter
MethodChannel
;
import
io.flutter.plugin.common.
Flutter
MethodChannel.MethodCallHandler
;
import
io.flutter.plugin.common.
FlutterMethodChannel.Response
;
import
io.flutter.plugin.common.EventChannel
;
import
io.flutter.plugin.common.EventChannel.EventSink
;
import
io.flutter.plugin.common.EventChannel.StreamHandler
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
;
import
io.flutter.plugin.common.
MethodChannel.Result
;
import
io.flutter.plugin.common.MethodCall
;
public
class
MainActivity
extends
FlutterActivity
{
...
...
@@ -31,7 +31,7 @@ public class MainActivity extends FlutterActivity {
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
new
Flutter
EventChannel
(
getFlutterView
(),
CHARGING_CHANNEL
).
setStreamHandler
(
new
EventChannel
(
getFlutterView
(),
CHARGING_CHANNEL
).
setStreamHandler
(
new
StreamHandler
()
{
private
BroadcastReceiver
chargingStateChangeReceiver
;
@Override
...
...
@@ -49,20 +49,20 @@ public class MainActivity extends FlutterActivity {
}
);
new
Flutter
MethodChannel
(
getFlutterView
(),
BATTERY_CHANNEL
).
setMethodCallHandler
(
new
MethodChannel
(
getFlutterView
(),
BATTERY_CHANNEL
).
setMethodCallHandler
(
new
MethodCallHandler
()
{
@Override
public
void
onMethodCall
(
MethodCall
call
,
Res
ponse
response
)
{
public
void
onMethodCall
(
MethodCall
call
,
Res
ult
result
)
{
if
(
call
.
method
.
equals
(
"getBatteryLevel"
))
{
int
batteryLevel
=
getBatteryLevel
();
if
(
batteryLevel
!=
-
1
)
{
res
ponse
.
success
(
batteryLevel
);
res
ult
.
success
(
batteryLevel
);
}
else
{
res
ponse
.
error
(
"UNAVAILABLE"
,
"Battery level not available."
,
null
);
res
ult
.
error
(
"UNAVAILABLE"
,
"Battery level not available."
,
null
);
}
}
else
{
res
ponse
.
notImplemented
();
res
ult
.
notImplemented
();
}
}
}
...
...
examples/platform_channel/ios/Runner/AppDelegate.m
View file @
945cfc3e
...
...
@@ -7,7 +7,7 @@
@implementation
AppDelegate
{
FlutterEvent
Receiver
_eventReceiver
;
FlutterEvent
Sink
_eventSink
;
}
-
(
BOOL
)
application
:
(
UIApplication
*
)
application
...
...
@@ -19,7 +19,7 @@
methodChannelWithName
:
@"samples.flutter.io/battery"
binaryMessenger
:
controller
];
[
batteryChannel
setMethodCallHandler
:
^
(
FlutterMethodCall
*
call
,
FlutterResult
Receiver
result
)
{
FlutterResult
result
)
{
if
([
@"getBatteryLevel"
isEqualToString
:
call
.
method
])
{
int
batteryLevel
=
[
self
getBatteryLevel
];
if
(
batteryLevel
==
-
1
)
{
...
...
@@ -52,8 +52,8 @@
}
-
(
FlutterError
*
)
onListenWithArguments
:
(
id
)
arguments
eventReceiver
:
(
FlutterEventReceiver
)
eventReceiver
{
_event
Receiver
=
eventReceiver
;
eventSink
:
(
FlutterEventSink
)
eventSink
{
_event
Sink
=
eventSink
;
[[
UIDevice
currentDevice
]
setBatteryMonitoringEnabled
:
YES
];
[
self
sendBatteryStateEvent
];
[[
NSNotificationCenter
defaultCenter
]
...
...
@@ -74,13 +74,13 @@
switch
(
state
)
{
case
UIDeviceBatteryStateFull
:
case
UIDeviceBatteryStateCharging
:
_event
Receiver
(
@"charging"
);
_event
Sink
(
@"charging"
);
break
;
case
UIDeviceBatteryStateUnplugged
:
_event
Receiver
(
@"discharging"
);
_event
Sink
(
@"discharging"
);
break
;
default
:
_event
Receiver
([
FlutterError
errorWithCode
:
@"UNAVAILABLE"
_event
Sink
([
FlutterError
errorWithCode
:
@"UNAVAILABLE"
message
:
@"Charging status unavailable"
details
:
nil
]);
break
;
...
...
@@ -89,7 +89,7 @@
-
(
FlutterError
*
)
onCancelWithArguments
:
(
id
)
arguments
{
[[
NSNotificationCenter
defaultCenter
]
removeObserver
:
self
];
_event
Receiver
=
nil
;
_event
Sink
=
nil
;
return
nil
;
}
...
...
examples/platform_channel/lib/main.dart
View file @
945cfc3e
...
...
@@ -13,10 +13,10 @@ class PlatformChannel extends StatefulWidget {
}
class
_PlatformChannelState
extends
State
<
PlatformChannel
>
{
static
const
Platform
MethodChannel
methodChannel
=
const
Platform
MethodChannel
(
'samples.flutter.io/battery'
);
static
const
Platform
EventChannel
eventChannel
=
const
Platform
EventChannel
(
'samples.flutter.io/charging'
);
static
const
MethodChannel
methodChannel
=
const
MethodChannel
(
'samples.flutter.io/battery'
);
static
const
EventChannel
eventChannel
=
const
EventChannel
(
'samples.flutter.io/charging'
);
String
_batteryLevel
=
'Battery level: unknown.'
;
String
_chargingStatus
=
'Battery status: unknown.'
;
...
...
examples/platform_channel_swift/ios/Runner/AppDelegate.swift
View file @
945cfc3e
...
...
@@ -7,7 +7,7 @@ import Flutter
@UIApplicationMain
@objc
class
AppDelegate
:
FlutterAppDelegate
,
FlutterStreamHandler
{
private
var
event
Receiver
:
FlutterEventReceiver
?;
private
var
event
Sink
:
FlutterEventSink
?;
override
func
application
(
_
application
:
UIApplication
,
...
...
@@ -16,14 +16,13 @@ import Flutter
let
batteryChannel
=
FlutterMethodChannel
.
init
(
name
:
"samples.flutter.io/battery"
,
binaryMessenger
:
controller
);
batteryChannel
.
setMethodCallHandler
({
(
call
:
FlutterMethodCall
,
result
:
FlutterResult
Receiver
)
->
Void
in
(
call
:
FlutterMethodCall
,
result
:
FlutterResult
)
->
Void
in
if
(
"getBatteryLevel"
==
call
.
method
)
{
self
.
receiveBatteryLevel
(
result
:
result
);
}
else
{
result
(
FlutterMethodNotImplemented
);
}
}
);
});
let
chargingChannel
=
FlutterEventChannel
.
init
(
name
:
"samples.flutter.io/charging"
,
binaryMessenger
:
controller
);
...
...
@@ -31,7 +30,7 @@ import Flutter
return
true
}
private
func
receiveBatteryLevel
(
result
:
FlutterResult
Receiver
)
{
private
func
receiveBatteryLevel
(
result
:
FlutterResult
)
{
let
device
=
UIDevice
.
current
;
device
.
isBatteryMonitoringEnabled
=
true
;
if
(
device
.
batteryState
==
UIDeviceBatteryState
.
unknown
)
{
...
...
@@ -44,8 +43,8 @@ import Flutter
}
public
func
onListen
(
withArguments
arguments
:
Any
?,
event
Receiver
:
@escaping
FlutterEventReceiver
)
->
FlutterError
?
{
self
.
event
Receiver
=
eventReceiver
;
event
Sink
:
@escaping
FlutterEventSink
)
->
FlutterError
?
{
self
.
event
Sink
=
eventSink
;
UIDevice
.
current
.
isBatteryMonitoringEnabled
=
true
;
self
.
sendBatteryStateEvent
();
NotificationCenter
.
default
.
addObserver
(
...
...
@@ -61,23 +60,23 @@ import Flutter
}
private
func
sendBatteryStateEvent
()
{
if
(
event
Receiver
==
nil
)
{
if
(
event
Sink
==
nil
)
{
return
;
}
let
state
=
UIDevice
.
current
.
batteryState
;
switch
state
{
case
UIDeviceBatteryState
.
full
:
event
Receiver
!
(
"charging"
);
event
Sink
!
(
"charging"
);
break
;
case
UIDeviceBatteryState
.
charging
:
event
Receiver
!
(
"charging"
);
event
Sink
!
(
"charging"
);
break
;
case
UIDeviceBatteryState
.
unplugged
:
event
Receiver
!
(
"discharging"
);
event
Sink
!
(
"discharging"
);
break
;
default
:
event
Receiver
!
(
FlutterError
.
init
(
code
:
"UNAVAILABLE"
,
event
Sink
!
(
FlutterError
.
init
(
code
:
"UNAVAILABLE"
,
message
:
"Charging status unavailable"
,
details
:
nil
));
break
;
...
...
@@ -86,7 +85,7 @@ import Flutter
public
func
onCancel
(
withArguments
arguments
:
Any
?)
->
FlutterError
?
{
NotificationCenter
.
default
.
removeObserver
(
self
);
event
Receiver
=
nil
;
event
Sink
=
nil
;
return
nil
;
}
}
examples/platform_channel_swift/lib/main.dart
View file @
945cfc3e
...
...
@@ -13,10 +13,10 @@ class PlatformChannel extends StatefulWidget {
}
class
_PlatformChannelState
extends
State
<
PlatformChannel
>
{
static
const
Platform
MethodChannel
methodChannel
=
const
Platform
MethodChannel
(
'samples.flutter.io/battery'
);
static
const
Platform
EventChannel
eventChannel
=
const
Platform
EventChannel
(
'samples.flutter.io/charging'
);
static
const
MethodChannel
methodChannel
=
const
MethodChannel
(
'samples.flutter.io/battery'
);
static
const
EventChannel
eventChannel
=
const
EventChannel
(
'samples.flutter.io/charging'
);
String
_batteryLevel
=
'Battery level: unknown.'
;
String
_chargingStatus
=
'Battery status: unknown.'
;
...
...
packages/flutter/lib/src/services/asset_bundle.dart
View file @
945cfc3e
...
...
@@ -216,7 +216,7 @@ class PlatformAssetBundle extends CachingAssetBundle {
Future
<
ByteData
>
load
(
String
key
)
async
{
final
Uint8List
encoded
=
UTF8
.
encoder
.
convert
(
key
);
final
ByteData
asset
=
await
PlatformMessages
.
sendBinary
(
'flutter/assets'
,
encoded
.
buffer
.
asByteData
());
await
BinaryMessages
.
send
(
'flutter/assets'
,
encoded
.
buffer
.
asByteData
());
if
(
asset
==
null
)
throw
new
FlutterError
(
'Unable to load asset:
$key
'
);
return
asset
;
...
...
packages/flutter/lib/src/services/binding.dart
View file @
945cfc3e
...
...
@@ -11,7 +11,7 @@ import 'asset_bundle.dart';
import
'image_cache.dart'
;
import
'platform_messages.dart'
;
/// Listens for platform messages and directs them to [
Platform
Messages].
/// Listens for platform messages and directs them to [
Binary
Messages].
///
/// The ServicesBinding also registers a [LicenseEntryCollector] that exposes
/// the licenses found in the `LICENSE` file stored at the root of the asset
...
...
@@ -21,7 +21,7 @@ abstract class ServicesBinding extends BindingBase {
void
initInstances
()
{
super
.
initInstances
();
ui
.
window
..
onPlatformMessage
=
Platform
Messages
.
handlePlatformMessage
;
..
onPlatformMessage
=
Binary
Messages
.
handlePlatformMessage
;
LicenseRegistry
.
addLicense
(
_addLicenses
);
}
...
...
packages/flutter/lib/src/services/platform_channel.dart
View file @
945cfc3e
...
...
@@ -27,11 +27,11 @@ import 'platform_messages.dart';
/// time.
///
/// See: <https://flutter.io/platform-channels/>
class
Platform
MessageChannel
<
T
>
{
/// Creates a [
Platform
MessageChannel] with the specified [name] and [codec].
class
Basic
MessageChannel
<
T
>
{
/// Creates a [
Basic
MessageChannel] with the specified [name] and [codec].
///
/// Neither [name] nor [codec] may be `null`.
const
Platform
MessageChannel
(
this
.
name
,
this
.
codec
);
const
Basic
MessageChannel
(
this
.
name
,
this
.
codec
);
/// The logical channel on which communication happens, not `null`.
final
String
name
;
...
...
@@ -45,7 +45,7 @@ class PlatformMessageChannel<T> {
/// or to a [FormatException], if encoding or decoding fails.
Future
<
T
>
send
(
T
message
)
async
{
return
codec
.
decodeMessage
(
await
PlatformMessages
.
sendBinary
(
name
,
codec
.
encodeMessage
(
message
))
await
BinaryMessages
.
send
(
name
,
codec
.
encodeMessage
(
message
))
);
}
...
...
@@ -60,9 +60,9 @@ class PlatformMessageChannel<T> {
/// plugins as a response.
void
setMessageHandler
(
Future
<
T
>
handler
(
T
message
))
{
if
(
handler
==
null
)
{
PlatformMessages
.
setBinary
MessageHandler
(
name
,
null
);
BinaryMessages
.
set
MessageHandler
(
name
,
null
);
}
else
{
PlatformMessages
.
setBinary
MessageHandler
(
name
,
(
ByteData
message
)
async
{
BinaryMessages
.
set
MessageHandler
(
name
,
(
ByteData
message
)
async
{
return
codec
.
encodeMessage
(
await
handler
(
codec
.
decodeMessage
(
message
)));
});
}
...
...
@@ -80,9 +80,9 @@ class PlatformMessageChannel<T> {
/// sent to platform plugins.
void
setMockMessageHandler
(
Future
<
T
>
handler
(
T
message
))
{
if
(
handler
==
null
)
{
PlatformMessages
.
setMockBinary
MessageHandler
(
name
,
null
);
BinaryMessages
.
setMock
MessageHandler
(
name
,
null
);
}
else
{
PlatformMessages
.
setMockBinary
MessageHandler
(
name
,
(
ByteData
message
)
async
{
BinaryMessages
.
setMock
MessageHandler
(
name
,
(
ByteData
message
)
async
{
return
codec
.
encodeMessage
(
await
handler
(
codec
.
decodeMessage
(
message
)));
});
}
...
...
@@ -103,14 +103,14 @@ class PlatformMessageChannel<T> {
/// with may interfere with this channel's communication.
///
/// See: <https://flutter.io/platform-channels/>
class
Platform
MethodChannel
{
/// Creates a [
Platform
MethodChannel] with the specified [name].
class
MethodChannel
{
/// Creates a [MethodChannel] with the specified [name].
///
/// The [codec] used will be [StandardMethodCodec], unless otherwise
/// specified.
///
/// Neither [name] nor [codec] may be `null`.
const
Platform
MethodChannel
(
this
.
name
,
[
this
.
codec
=
const
StandardMethodCodec
()]);
const
MethodChannel
(
this
.
name
,
[
this
.
codec
=
const
StandardMethodCodec
()]);
/// The logical channel on which communication happens, not `null`.
final
String
name
;
...
...
@@ -128,7 +128,7 @@ class PlatformMethodChannel {
/// * a [MissingPluginException], if the method has not been implemented.
Future
<
dynamic
>
invokeMethod
(
String
method
,
[
dynamic
arguments
])
async
{
assert
(
method
!=
null
);
final
dynamic
result
=
await
PlatformMessages
.
sendBinary
(
final
dynamic
result
=
await
BinaryMessages
.
send
(
name
,
codec
.
encodeMethodCall
(
new
MethodCall
(
method
,
arguments
)),
);
...
...
@@ -152,9 +152,9 @@ class PlatformMethodChannel {
/// similarly to what happens if no method call handler has been set.
void
setMethodCallHandler
(
Future
<
dynamic
>
handler
(
MethodCall
call
))
{
if
(
handler
==
null
)
{
PlatformMessages
.
setBinary
MessageHandler
(
name
,
null
);
BinaryMessages
.
set
MessageHandler
(
name
,
null
);
}
else
{
PlatformMessages
.
setBinary
MessageHandler
(
BinaryMessages
.
set
MessageHandler
(
name
,
(
ByteData
message
)
async
{
final
MethodCall
call
=
codec
.
decodeMethodCall
(
message
);
...
...
@@ -187,9 +187,9 @@ class PlatformMethodChannel {
/// not sent to platform plugins.
void
setMockMethodCallHandler
(
Future
<
dynamic
>
handler
(
MethodCall
call
))
{
if
(
handler
==
null
)
{
PlatformMessages
.
setMockBinary
MessageHandler
(
name
,
null
);
BinaryMessages
.
setMock
MessageHandler
(
name
,
null
);
}
else
{
PlatformMessages
.
setMockBinary
MessageHandler
(
BinaryMessages
.
setMock
MessageHandler
(
name
,
(
ByteData
message
)
async
{
final
MethodCall
call
=
codec
.
decodeMethodCall
(
message
);
...
...
@@ -208,13 +208,13 @@ class PlatformMethodChannel {
}
}
/// A [
Platform
MethodChannel] that ignores missing platform plugins.
/// A [MethodChannel] that ignores missing platform plugins.
///
/// When [invokeMethod] fails to find the platform plugin, it returns null
/// instead of throwing an exception.
class
Optional
PlatformMethodChannel
extends
Platform
MethodChannel
{
/// Creates a [
Platform
MethodChannel] that ignores missing platform plugins.
const
Optional
Platform
MethodChannel
(
String
name
,
[
MethodCodec
codec
=
const
StandardMethodCodec
()])
class
Optional
MethodChannel
extends
MethodChannel
{
/// Creates a [MethodChannel] that ignores missing platform plugins.
const
OptionalMethodChannel
(
String
name
,
[
MethodCodec
codec
=
const
StandardMethodCodec
()])
:
super
(
name
,
codec
);
@override
...
...
@@ -240,14 +240,14 @@ class OptionalPlatformMethodChannel extends PlatformMethodChannel {
/// with may interfere with this channel's communication.
///
/// See: <https://flutter.io/platform-channels/>
class
Platform
EventChannel
{
/// Creates a [
Platform
EventChannel] with the specified [name].
class
EventChannel
{
/// Creates a [EventChannel] with the specified [name].
///
/// The [codec] used will be [StandardMethodCodec], unless otherwise
/// specified.
///
/// Neither [name] nor [codec] may be `null`.
const
Platform
EventChannel
(
this
.
name
,
[
this
.
codec
=
const
StandardMethodCodec
()]);
const
EventChannel
(
this
.
name
,
[
this
.
codec
=
const
StandardMethodCodec
()]);
/// The logical channel on which communication happens, not `null`.
final
String
name
;
...
...
@@ -272,7 +272,7 @@ class PlatformEventChannel {
/// Notes for platform plugin implementers:
///
/// Plugins must expose methods named `listen` and `cancel` suitable for
/// invocations by [
Platform
MethodChannel.invokeMethod]. Both methods are
/// invocations by [MethodChannel.invokeMethod]. Both methods are
/// invoked with the specified [arguments].
///
/// Following the semantics of broadcast streams, `listen` will be called as
...
...
@@ -281,11 +281,11 @@ class PlatformEventChannel {
/// indefinitely. Platform plugins should consume no stream-related resources
/// while listener count is zero.
Stream
<
dynamic
>
receiveBroadcastStream
([
dynamic
arguments
])
{
final
PlatformMethodChannel
methodChannel
=
new
Platform
MethodChannel
(
name
,
codec
);
final
MethodChannel
methodChannel
=
new
MethodChannel
(
name
,
codec
);
StreamController
<
dynamic
>
controller
;
controller
=
new
StreamController
<
dynamic
>.
broadcast
(
onListen:
()
async
{
PlatformMessages
.
setBinary
MessageHandler
(
BinaryMessages
.
set
MessageHandler
(
name
,
(
ByteData
reply
)
async
{
if
(
reply
==
null
)
{
controller
.
close
();
...
...
@@ -301,11 +301,11 @@ class PlatformEventChannel {
try
{
await
methodChannel
.
invokeMethod
(
'listen'
,
arguments
);
}
catch
(
e
)
{
PlatformMessages
.
setBinary
MessageHandler
(
name
,
null
);
BinaryMessages
.
set
MessageHandler
(
name
,
null
);
controller
.
addError
(
e
);
}
},
onCancel:
()
async
{
PlatformMessages
.
setBinary
MessageHandler
(
name
,
null
);
BinaryMessages
.
set
MessageHandler
(
name
,
null
);
try
{
await
methodChannel
.
invokeMethod
(
'cancel'
,
arguments
);
}
catch
(
exception
,
stack
)
{
...
...
packages/flutter/lib/src/services/platform_messages.dart
View file @
945cfc3e
...
...
@@ -8,29 +8,29 @@ import 'dart:ui' as ui;
import
'package:flutter/foundation.dart'
;
typedef
Future
<
ByteData
>
_
Platform
MessageHandler
(
ByteData
message
);
typedef
Future
<
ByteData
>
_MessageHandler
(
ByteData
message
);
/// Sends binary messages to and receives binary messages from platform plugins.
///
/// See also:
///
/// * [
Platform
MessageChannel], which provides messaging services similar to
///
PlatformMessages
, but with pluggable message codecs in support of sending
/// * [
Basic
MessageChannel], which provides messaging services similar to
///
[BinaryMessages]
, but with pluggable message codecs in support of sending
/// strings or semi-structured messages.
/// * [
Platform
MethodChannel], which provides higher-level platform
/// * [MethodChannel], which provides higher-level platform
/// communication such as method invocations and event streams.
///
/// See: <https://flutter.io/platform-channels/>
class
Platform
Messages
{
Platform
Messages
.
_
();
class
Binary
Messages
{
Binary
Messages
.
_
();
// Handlers for incoming messages from platform plugins.
static
final
Map
<
String
,
_
Platform
MessageHandler
>
_handlers
=
<
String
,
_
Platform
MessageHandler
>{};
static
final
Map
<
String
,
_MessageHandler
>
_handlers
=
<
String
,
_MessageHandler
>{};
// Mock handlers that intercept and respond to outgoing messages.
static
final
Map
<
String
,
_
Platform
MessageHandler
>
_mockHandlers
=
<
String
,
_
Platform
MessageHandler
>{};
static
final
Map
<
String
,
_MessageHandler
>
_mockHandlers
=
<
String
,
_MessageHandler
>{};
static
Future
<
ByteData
>
_sendPlatformMessage
(
String
channel
,
ByteData
message
)
{
final
Completer
<
ByteData
>
completer
=
new
Completer
<
ByteData
>();
...
...
@@ -59,7 +59,7 @@ class PlatformMessages {
String
channel
,
ByteData
data
,
ui
.
PlatformMessageResponseCallback
callback
)
async
{
ByteData
response
;
try
{
final
_
Platform
MessageHandler
handler
=
_handlers
[
channel
];
final
_MessageHandler
handler
=
_handlers
[
channel
];
if
(
handler
!=
null
)
response
=
await
handler
(
data
);
}
catch
(
exception
,
stack
)
{
...
...
@@ -78,8 +78,8 @@ class PlatformMessages {
///
/// Returns a [Future] which completes to the received response, undecoded, in
/// binary form.
static
Future
<
ByteData
>
send
Binary
(
String
channel
,
ByteData
message
)
{
final
_
Platform
MessageHandler
handler
=
_mockHandlers
[
channel
];
static
Future
<
ByteData
>
send
(
String
channel
,
ByteData
message
)
{
final
_MessageHandler
handler
=
_mockHandlers
[
channel
];
if
(
handler
!=
null
)
return
handler
(
message
);
return
_sendPlatformMessage
(
channel
,
message
);
...
...
@@ -93,7 +93,7 @@ class PlatformMessages {
/// argument.
///
/// The handler's return value, if non-null, is sent as a response, unencoded.
static
void
set
Binary
MessageHandler
(
String
channel
,
Future
<
ByteData
>
handler
(
ByteData
message
))
{
static
void
setMessageHandler
(
String
channel
,
Future
<
ByteData
>
handler
(
ByteData
message
))
{
if
(
handler
==
null
)
_handlers
.
remove
(
channel
);
else
...
...
@@ -111,7 +111,7 @@ class PlatformMessages {
///
/// This is intended for testing. Messages intercepted in this manner are not
/// sent to platform plugins.
static
void
setMock
Binary
MessageHandler
(
String
channel
,
Future
<
ByteData
>
handler
(
ByteData
message
))
{
static
void
setMockMessageHandler
(
String
channel
,
Future
<
ByteData
>
handler
(
ByteData
message
))
{
if
(
handler
==
null
)
_mockHandlers
.
remove
(
channel
);
else
...
...
packages/flutter/lib/src/services/system_channels.dart
View file @
945cfc3e
...
...
@@ -9,42 +9,42 @@ import 'platform_channel.dart';
class
SystemChannels
{
SystemChannels
.
_
();
/// A JSON [
Platform
MethodChannel] for navigation.
static
const
PlatformMethodChannel
navigation
=
const
Platform
MethodChannel
(
/// A JSON [MethodChannel] for navigation.
static
const
MethodChannel
navigation
=
const
MethodChannel
(
'flutter/navigation'
,
const
JSONMethodCodec
(),
);
/// A JSON [
Platform
MethodChannel] for invoking miscellaneous platform methods.
/// A JSON [MethodChannel] for invoking miscellaneous platform methods.
///
/// Ignores missing plugins.
static
const
PlatformMethodChannel
platform
=
const
OptionalPlatform
MethodChannel
(
static
const
MethodChannel
platform
=
const
Optional
MethodChannel
(
'flutter/platform'
,
const
JSONMethodCodec
(),
);
/// A JSON [
Platform
MethodChannel] for handling text input.
/// A JSON [MethodChannel] for handling text input.
///
/// Ignores missing plugins.
static
const
PlatformMethodChannel
textInput
=
const
OptionalPlatform
MethodChannel
(
static
const
MethodChannel
textInput
=
const
Optional
MethodChannel
(
'flutter/textinput'
,
const
JSONMethodCodec
(),
);
/// A JSON [
Platform
MessageChannel] for key events.
static
const
PlatformMessageChannel
<
dynamic
>
keyEvent
=
const
Platform
MessageChannel
<
dynamic
>(
/// A JSON [
Basic
MessageChannel] for key events.
static
const
BasicMessageChannel
<
dynamic
>
keyEvent
=
const
Basic
MessageChannel
<
dynamic
>(
'flutter/keyevent'
,
const
JSONMessageCodec
(),
);
/// A string [
Platform
MessageChannel] for lifecycle events.
static
const
PlatformMessageChannel
<
String
>
lifecycle
=
const
Platform
MessageChannel
<
String
>(
/// A string [
Basic
MessageChannel] for lifecycle events.
static
const
BasicMessageChannel
<
String
>
lifecycle
=
const
Basic
MessageChannel
<
String
>(
'flutter/lifecycle'
,
const
StringCodec
(),
);
/// A JSON [
Platform
MessageChannel] for system events.
static
const
PlatformMessageChannel
<
dynamic
>
system
=
const
Platform
MessageChannel
<
dynamic
>(
/// A JSON [
Basic
MessageChannel] for system events.
static
const
BasicMessageChannel
<
dynamic
>
system
=
const
Basic
MessageChannel
<
dynamic
>(
'flutter/system'
,
const
JSONMessageCodec
(),
);
...
...
packages/flutter/test/foundation/service_extensions_test.dart
View file @
945cfc3e
...
...
@@ -195,7 +195,7 @@ void main() {
bool
completed
;
completed
=
false
;
PlatformMessages
.
setMockBinary
MessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
async
{
BinaryMessages
.
setMock
MessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
async
{
expect
(
UTF8
.
decode
(
message
.
buffer
.
asUint8List
()),
'test'
);
completed
=
true
;
return
new
ByteData
(
5
);
// 0x0000000000
...
...
@@ -214,7 +214,7 @@ void main() {
data
=
await
rootBundle
.
loadStructuredData
<
bool
>(
'test'
,
(
String
value
)
async
{
expect
(
value
,
'
\
x00
\
x00
\
x00
\
x00
\
x00'
);
return
false
;
});
expect
(
data
,
isFalse
);
expect
(
completed
,
isTrue
);
PlatformMessages
.
setMockBinary
MessageHandler
(
'flutter/assets'
,
null
);
BinaryMessages
.
setMock
MessageHandler
(
'flutter/assets'
,
null
);
});
test
(
'Service extensions - exit'
,
()
async
{
...
...
packages/flutter/test/services/platform_channel_test.dart
View file @
945cfc3e
...
...
@@ -11,9 +11,9 @@ import 'package:test/test.dart';
void
main
(
)
{
group
(
'PlatformMessageChannel'
,
()
{
const
MessageCodec
<
String
>
string
=
const
StringCodec
();
const
PlatformMessageChannel
<
String
>
channel
=
const
Platform
MessageChannel
<
String
>(
'ch'
,
string
);
const
BasicMessageChannel
<
String
>
channel
=
const
Basic
MessageChannel
<
String
>(
'ch'
,
string
);
test
(
'can send string message and get reply'
,
()
async
{
PlatformMessages
.
setMockBinary
MessageHandler
(
BinaryMessages
.
setMock
MessageHandler
(
'ch'
,
(
ByteData
message
)
async
=>
string
.
encodeMessage
(
string
.
decodeMessage
(
message
)
+
' world'
),
);
...
...
@@ -23,7 +23,7 @@ void main() {
test
(
'can receive string message and send reply'
,
()
async
{
channel
.
setMessageHandler
((
String
message
)
async
=>
message
+
' world'
);
String
reply
;
await
Platform
Messages
.
handlePlatformMessage
(
await
Binary
Messages
.
handlePlatformMessage
(
'ch'
,
const
StringCodec
().
encodeMessage
(
'hello'
),
(
ByteData
replyBinary
)
{
...
...
@@ -37,9 +37,9 @@ void main() {
group
(
'PlatformMethodChannel'
,
()
{
const
MessageCodec
<
dynamic
>
jsonMessage
=
const
JSONMessageCodec
();
const
MethodCodec
jsonMethod
=
const
JSONMethodCodec
();
const
PlatformMethodChannel
channel
=
const
Platform
MethodChannel
(
'ch7'
,
jsonMethod
);
const
MethodChannel
channel
=
const
MethodChannel
(
'ch7'
,
jsonMethod
);
test
(
'can invoke method and get result'
,
()
async
{
PlatformMessages
.
setMockBinary
MessageHandler
(
BinaryMessages
.
setMock
MessageHandler
(
'ch7'
,
(
ByteData
message
)
async
{
final
Map
<
dynamic
,
dynamic
>
methodCall
=
jsonMessage
.
decodeMessage
(
message
);
...
...
@@ -53,7 +53,7 @@ void main() {
expect
(
result
,
equals
(
'hello world'
));
});
test
(
'can invoke method and get error'
,
()
async
{
PlatformMessages
.
setMockBinary
MessageHandler
(
BinaryMessages
.
setMock
MessageHandler
(
'ch7'
,
(
ByteData
message
)
async
{
return
jsonMessage
.
encodeMessage
(<
dynamic
>[
...
...
@@ -75,7 +75,7 @@ void main() {
}
});
test
(
'can invoke unimplemented method'
,
()
async
{
PlatformMessages
.
setMockBinary
MessageHandler
(
BinaryMessages
.
setMock
MessageHandler
(
'ch7'
,
(
ByteData
message
)
async
=>
null
,
);
...
...
@@ -93,17 +93,17 @@ void main() {
group
(
'PlatformEventChannel'
,
()
{
const
MessageCodec
<
dynamic
>
jsonMessage
=
const
JSONMessageCodec
();
const
MethodCodec
jsonMethod
=
const
JSONMethodCodec
();
const
PlatformEventChannel
channel
=
const
Platform
EventChannel
(
'ch'
,
jsonMethod
);
const
EventChannel
channel
=
const
EventChannel
(
'ch'
,
jsonMethod
);
test
(
'can receive event stream'
,
()
async
{
void
emitEvent
(
dynamic
event
)
{
Platform
Messages
.
handlePlatformMessage
(
Binary
Messages
.
handlePlatformMessage
(
'ch'
,
event
,
(
ByteData
reply
)
{},
);
}
bool
cancelled
=
false
;
PlatformMessages
.
setMockBinary
MessageHandler
(
BinaryMessages
.
setMock
MessageHandler
(
'ch'
,
(
ByteData
message
)
async
{
final
Map
<
dynamic
,
dynamic
>
methodCall
=
jsonMessage
.
decodeMessage
(
message
);
...
...
packages/flutter/test/services/platform_messages_test.dart
View file @
945cfc3e
...
...
@@ -11,17 +11,17 @@ void main() {
test
(
'Mock binary message handler control test'
,
()
async
{
final
List
<
ByteData
>
log
=
<
ByteData
>[];
PlatformMessages
.
setMockBinary
MessageHandler
(
'test1'
,
(
ByteData
message
)
async
{
BinaryMessages
.
setMock
MessageHandler
(
'test1'
,
(
ByteData
message
)
async
{
log
.
add
(
message
);
});
final
ByteData
message
=
new
ByteData
(
2
)..
setUint16
(
0
,
0xABCD
);
await
PlatformMessages
.
sendBinary
(
'test1'
,
message
);
await
BinaryMessages
.
send
(
'test1'
,
message
);
expect
(
log
,
equals
(<
ByteData
>[
message
]));
log
.
clear
();
PlatformMessages
.
setMockBinary
MessageHandler
(
'test1'
,
null
);
await
PlatformMessages
.
sendBinary
(
'test1'
,
message
);
BinaryMessages
.
setMock
MessageHandler
(
'test1'
,
null
);
await
BinaryMessages
.
send
(
'test1'
,
message
);
expect
(
log
,
isEmpty
);
});
}
packages/flutter/test/services/system_chrome_test.dart
View file @
945cfc3e
...
...
@@ -59,7 +59,7 @@ void main() {
test
(
'setApplicationSwitcherDescription missing plugin'
,
()
async
{
final
List
<
ByteData
>
log
=
<
ByteData
>[];
PlatformMessages
.
setMockBinary
MessageHandler
(
'flutter/platform'
,
(
ByteData
message
)
{
BinaryMessages
.
setMock
MessageHandler
(
'flutter/platform'
,
(
ByteData
message
)
{
log
.
add
(
message
);
return
null
;
});
...
...
packages/flutter/test/widgets/binding_test.dart
View file @
945cfc3e
...
...
@@ -39,7 +39,7 @@ void main() {
WidgetsBinding
.
instance
.
addObserver
(
observer
);
final
ByteData
message
=
const
JSONMessageCodec
().
encodeMessage
(
<
String
,
dynamic
>{
'type'
:
'memoryPressure'
});
await
Platform
Messages
.
handlePlatformMessage
(
'flutter/system'
,
message
,
(
_
)
{});
await
Binary
Messages
.
handlePlatformMessage
(
'flutter/system'
,
message
,
(
_
)
{});
expect
(
observer
.
sawMemoryPressure
,
true
);
WidgetsBinding
.
instance
.
removeObserver
(
observer
);
});
...
...
packages/flutter/test/widgets/raw_keyboard_listener_test.dart
View file @
945cfc3e
...
...
@@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart';
import
'package:flutter_test/flutter_test.dart'
;
void
sendFakeKeyEvent
(
Map
<
String
,
dynamic
>
data
)
{
Platform
Messages
.
handlePlatformMessage
(
Binary
Messages
.
handlePlatformMessage
(
SystemChannels
.
keyEvent
.
name
,
SystemChannels
.
keyEvent
.
codec
.
encodeMessage
(
data
),
(
_
)
{});
...
...
packages/flutter_test/lib/src/test_text_input.dart
View file @
945cfc3e
...
...
@@ -41,7 +41,7 @@ class TestTextInput {
void
updateEditingValue
(
TextEditingValue
value
)
{
expect
(
_client
,
isNonZero
);
Platform
Messages
.
handlePlatformMessage
(
Binary
Messages
.
handlePlatformMessage
(
SystemChannels
.
textInput
.
name
,
SystemChannels
.
textInput
.
codec
.
encodeMethodCall
(
new
MethodCall
(
...
...
packages/flutter_tools/templates/plugin/android.tmpl/src/main/java/com/yourcompany/projectName/pluginClass.java.tmpl
View file @
945cfc3e
package
{{
androidIdentifier
}};
import
io
.
flutter
.
app
.
FlutterActivity
;
import
io
.
flutter
.
plugin
.
common
.
Flutter
MethodChannel
;
import
io
.
flutter
.
plugin
.
common
.
Flutter
MethodChannel
.
MethodCallHandler
;
import
io
.
flutter
.
plugin
.
common
.
FlutterMethodChannel
.
Response
;
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
;
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
.
MethodCallHandler
;
import
io
.
flutter
.
plugin
.
common
.
MethodChannel
.
Result
;
import
io
.
flutter
.
plugin
.
common
.
MethodCall
;
/**
...
...
@@ -18,15 +18,15 @@ public class {{pluginClass}} implements MethodCallHandler {
private
{{
pluginClass
}}(
FlutterActivity
activity
)
{
this
.
activity
=
activity
;
new
Flutter
MethodChannel
(
activity
.
getFlutterView
(),
"{{projectName}}"
).
setMethodCallHandler
(
this
);
new
MethodChannel
(
activity
.
getFlutterView
(),
"{{projectName}}"
).
setMethodCallHandler
(
this
);
}
@
Override
public
void
onMethodCall
(
MethodCall
call
,
Res
ponse
response
)
{
public
void
onMethodCall
(
MethodCall
call
,
Res
ult
result
)
{
if
(
call
.
method
.
equals
(
"getPlatformVersion"
))
{
res
ponse
.
success
(
"Android "
+
android
.
os
.
Build
.
VERSION
.
RELEASE
);
res
ult
.
success
(
"Android "
+
android
.
os
.
Build
.
VERSION
.
RELEASE
);
}
else
{
res
ponse
.
notImplemented
();
res
ult
.
notImplemented
();
}
}
}
packages/flutter_tools/templates/plugin/ios.tmpl/Classes/pluginClass.m.tmpl
View file @
945cfc3e
...
...
@@ -10,10 +10,12 @@
methodChannelWithName:@"{{projectName}}"
binaryMessenger:controller];
[channel setMethodCallHandler:^(FlutterMethodCall *call,
FlutterResult
Receiver
result) {
FlutterResult result) {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice]
systemVersion]]);
} else {
result(FlutterMethodNotImplemented);
}
}];
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment