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
3e6a2c76
Commit
3e6a2c76
authored
Mar 30, 2017
by
Sarah Zakarias
Committed by
GitHub
Mar 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup platform_channel (#9099)
parent
f34f8a31
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
10 deletions
+19
-10
MainActivity.java
...c/main/java/com/example/platformchannel/MainActivity.java
+2
-2
AppDelegate.m
examples/platform_channel/ios/Runner/AppDelegate.m
+16
-7
main.dart
examples/platform_channel/lib/main.dart
+1
-1
No files found.
examples/platform_channel/android/app/src/main/java/com/example/platformchannel/MainActivity.java
View file @
3e6a2c76
// Copyright 201
6
The Chromium Authors. All rights reserved.
// Copyright 201
7
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.
...
...
@@ -19,7 +19,7 @@ import io.flutter.plugin.common.FlutterMethodChannel.Response;
import
io.flutter.plugin.common.MethodCall
;
public
class
MainActivity
extends
FlutterActivity
{
private
static
final
String
CHANNEL
=
"battery"
;
private
static
final
String
CHANNEL
=
"
samples.flutter.io/
battery"
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
examples/platform_channel/ios/Runner/AppDelegate.m
View file @
3e6a2c76
// Copyright 201
6
The Chromium Authors. All rights reserved.
// Copyright 201
7
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 "AppDelegate.h"
#import <Flutter/Flutter.h>
@implementation
AppDelegate
...
...
@@ -12,19 +11,18 @@
FlutterViewController
*
controller
=
(
FlutterViewController
*
)
self
.
window
.
rootViewController
;
FlutterMethodChannel
*
batteryChannel
=
[
FlutterMethodChannel
methodChannelWithName
:
@"battery"
methodChannelWithName
:
@"
samples.flutter.io/
battery"
binaryMessenger
:
controller
];
[
batteryChannel
setMethodCallHandler
:
^
(
FlutterMethodCall
*
call
,
FlutterResultReceiver
result
)
{
if
([
@"getBatteryLevel"
isEqualToString
:
call
.
method
])
{
UIDevice
*
device
=
UIDevice
.
currentDevice
;
device
.
batteryMonitoringEnabled
=
YES
;
if
(
device
.
batteryState
==
UIDeviceBatteryStateUnknown
)
{
int
batteryLevel
=
[
self
getBatteryLevel
];
if
(
batteryLevel
==
-
1
)
{
result
([
FlutterError
errorWithCode
:
@"UNAVAILABLE"
message
:
@"Battery info unavailable"
details:
nil
]);
}
else
{
result
(
@
(
(
int
)(
device
.
batteryLevel
*
100
)
));
result
(
@
(
batteryLevel
));
}
}
else
{
result
(
FlutterMethodNotImplemented
);
...
...
@@ -32,4 +30,15 @@
}];
return
YES
;
}
-
(
int
)
getBatteryLevel
{
UIDevice
*
device
=
UIDevice
.
currentDevice
;
device
.
batteryMonitoringEnabled
=
YES
;
if
(
device
.
batteryState
==
UIDeviceBatteryStateUnknown
)
{
return
-
1
;
}
else
{
return
((
int
)(
device
.
batteryLevel
*
100
));
}
}
@end
examples/platform_channel/lib/main.dart
View file @
3e6a2c76
...
...
@@ -13,7 +13,7 @@ class PlatformChannel extends StatefulWidget {
}
class
_PlatformChannelState
extends
State
<
PlatformChannel
>
{
static
const
PlatformMethodChannel
platform
=
const
PlatformMethodChannel
(
'battery'
);
static
const
PlatformMethodChannel
platform
=
const
PlatformMethodChannel
(
'
samples.flutter.io/
battery'
);
String
_batteryLevel
=
''
;
Future
<
Null
>
_getBatteryLevel
()
async
{
...
...
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