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
f3717d70
Unverified
Commit
f3717d70
authored
Jul 06, 2022
by
stuartmorgan
Committed by
GitHub
Jul 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable Windows platform_channel test (#106973)
parent
5ca39a20
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
9 deletions
+25
-9
.ci.yaml
.ci.yaml
+0
-1
main.dart
examples/platform_channel/lib/main.dart
+6
-2
button_tap_test.dart
examples/platform_channel/test_driver/button_tap_test.dart
+5
-1
flutter_window.cpp
examples/platform_channel/windows/runner/flutter_window.cpp
+14
-5
No files found.
.ci.yaml
View file @
f3717d70
...
...
@@ -3994,7 +3994,6 @@ targets:
["devicelab", "hostonly"]
task_name: platform_channel_sample_test_windows
scheduler
:
luci
bringup
:
true
-
name
:
Windows plugin_dependencies_test
recipe
:
devicelab/devicelab_drone
...
...
examples/platform_channel/lib/main.dart
View file @
f3717d70
...
...
@@ -28,9 +28,13 @@ class _PlatformChannelState extends State<PlatformChannel> {
try
{
final
int
?
result
=
await
methodChannel
.
invokeMethod
(
'getBatteryLevel'
);
batteryLevel
=
'Battery level:
$result
%.'
;
}
on
PlatformException
{
}
on
PlatformException
catch
(
e
)
{
if
(
e
.
code
==
'NO_BATTERY'
)
{
batteryLevel
=
'No battery.'
;
}
else
{
batteryLevel
=
'Failed to get battery level.'
;
}
}
setState
(()
{
_batteryLevel
=
batteryLevel
;
});
...
...
examples/platform_channel/test_driver/button_tap_test.dart
View file @
f3717d70
...
...
@@ -31,7 +31,11 @@ void main() {
batteryLevel
=
await
driver
.
getText
(
batteryLevelLabel
);
}
expect
(
batteryLevel
.
contains
(
'%'
),
isTrue
);
// Allow either a battery percentage or "No battery" since it will vary
// by device; either indicates that a known response came from the host
// implementation.
expect
(
batteryLevel
.
contains
(
'%'
)
||
batteryLevel
.
contains
(
'No battery'
),
isTrue
);
});
});
}
examples/platform_channel/windows/runner/flutter_window.cpp
View file @
f3717d70
...
...
@@ -16,10 +16,17 @@
#include "flutter/generated_plugin_registrant.h"
static
constexpr
int
kBatteryError
=
-
1
;
static
constexpr
int
kNoBattery
=
-
2
;
static
int
GetBatteryLevel
()
{
SYSTEM_POWER_STATUS
status
;
if
(
GetSystemPowerStatus
(
&
status
)
==
0
||
status
.
BatteryLifePercent
==
255
)
{
return
-
1
;
if
(
GetSystemPowerStatus
(
&
status
)
==
0
)
{
return
kBatteryError
;
}
else
if
(
status
.
BatteryFlag
==
128
)
{
return
kNoBattery
;
}
else
if
(
status
.
BatteryLifePercent
==
255
)
{
return
kBatteryError
;
}
return
status
.
BatteryLifePercent
;
}
...
...
@@ -59,10 +66,12 @@ bool FlutterWindow::OnCreate() {
if
(
call
.
method_name
()
==
"getBatteryLevel"
)
{
int
battery_level
=
GetBatteryLevel
();
if
(
battery_level
!=
-
1
)
{
result
->
Success
(
battery_level
);
}
else
{
if
(
battery_level
==
kBatteryError
)
{
result
->
Error
(
"UNAVAILABLE"
,
"Battery level not available."
);
}
else
if
(
battery_level
==
kNoBattery
)
{
result
->
Error
(
"NO_BATTERY"
,
"Device does not have a battery."
);
}
else
{
result
->
Success
(
battery_level
);
}
}
else
{
result
->
NotImplemented
();
...
...
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