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
c4a86788
Commit
c4a86788
authored
Oct 12, 2016
by
Adam Barth
Committed by
Jason Simmons
Oct 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an ergonomic wrapper for platform messages (#6281)
This wrapper will eventually replace HostMessages.
parent
6777766d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
services.dart
packages/flutter/lib/services.dart
+1
-0
platform_messages.dart
packages/flutter/lib/src/services/platform_messages.dart
+44
-0
No files found.
packages/flutter/lib/services.dart
View file @
c4a86788
...
...
@@ -27,6 +27,7 @@ export 'src/services/image_resolution.dart';
export
'src/services/image_stream.dart'
;
export
'src/services/keyboard.dart'
;
export
'src/services/path_provider.dart'
;
export
'src/services/platform_messages.dart'
;
export
'src/services/shell.dart'
;
export
'src/services/system_chrome.dart'
;
export
'src/services/system_sound.dart'
;
...
...
packages/flutter/lib/src/services/platform_messages.dart
0 → 100644
View file @
c4a86788
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:typed_data'
;
import
'dart:ui'
as
ui
;
String
_decodeUTF8
(
ByteData
data
)
{
return
data
!=
null
?
UTF8
.
decoder
.
convert
(
data
.
buffer
.
asUint8List
())
:
null
;
}
dynamic
_decodeJSON
(
String
message
)
{
return
message
!=
null
?
JSON
.
decode
(
message
)
:
null
;
}
void
_sendString
(
String
name
,
String
message
,
void
callback
(
String
reply
))
{
Uint8List
encoded
=
UTF8
.
encoder
.
convert
(
message
);
ui
.
window
.
sendPlatformMesssage
(
name
,
encoded
.
buffer
.
asByteData
(),
(
ByteData
reply
)
{
callback
(
_decodeUTF8
(
reply
));
});
}
/// Sends messages to the hosting application.
class
PlatformMessages
{
/// Send a string message to the host application.
static
Future
<
String
>
sendString
(
String
name
,
String
message
)
{
Completer
<
String
>
completer
=
new
Completer
<
String
>();
_sendString
(
name
,
message
,
(
String
reply
)
{
completer
.
complete
(
reply
);
});
return
completer
.
future
;
}
/// Sends a JSON-encoded message to the host application and JSON-decodes the response.
static
Future
<
dynamic
>
sendJSON
(
String
name
,
dynamic
json
)
{
Completer
<
dynamic
>
completer
=
new
Completer
<
dynamic
>();
_sendString
(
name
,
JSON
.
encode
(
json
),
(
String
reply
)
{
completer
.
complete
(
_decodeJSON
(
reply
));
});
return
completer
.
future
;
}
}
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