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