Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
flutter_wakelock
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
creativecreatorormaybenot
2019-07-07 11:30:01 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f94731aadd540fbbbc4d05f3e27d42057849a6b8
f94731aa
1 parent
b0326309
0.1.2
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
13 deletions
CHANGELOG.md
README.md
example/lib/main.dart
ios/Classes/WakelockPlugin.m
lib/wakelock.dart
pubspec.yaml
CHANGELOG.md
View file @
f94731a
## 0.1.2
*
Changed
`Wakelock.toggle`
's parameter to a named parameter.
*
Improved iOS implementation.
## 0.1.1+2
*
Made the plugin description more concise.
...
...
README.md
View file @
f94731a
...
...
@@ -30,13 +30,13 @@ import 'package:wakelock/wakelock.dart';
// ...
// The following lines of code toggle the wakelock based on a bool value.
bool
enable
=
true
;
bool
on
=
true
;
// The following statement enables the wakelock.
Wakelock
.
toggle
(
enable
);
Wakelock
.
toggle
(
on:
on
);
enable
=
false
;
on
=
false
;
// The following statement disables the wakelock.
Wakelock
.
toggle
(
enable
);
Wakelock
.
toggle
(
on:
on
);
// If you want to retrieve the current wakelock status,
// you will have to be in an async scope
...
...
example/lib/main.dart
View file @
f94731a
...
...
@@ -26,6 +26,7 @@ class _MyAppState extends State<MyApp> {
// The following code will enable the wakelock on Android or iOS using the wakelock plugin.
setState
(()
{
Wakelock
.
enable
();
// You could also use Wakelock.toggle(on: true);
});
},
),
...
...
@@ -35,6 +36,7 @@ class _MyAppState extends State<MyApp> {
// The following code will disable the wakelock on Android or iOS using the wakelock plugin.
setState
(()
{
Wakelock
.
disable
();
// You could also use Wakelock.toggle(on: false);
});
},
),
...
...
ios/Classes/WakelockPlugin.m
View file @
f94731a
...
...
@@ -12,11 +12,16 @@
-
(
void
)
handleMethodCall
:(
FlutterMethodCall
*
)
call
result
:(
FlutterResult
)
result
{
if
([
@"toggle"
isEqualToString
:
call
.
method
])
{
NSNumber
*
enable
=
call
.
arguments
[
@"enable"
];
[[
UIApplication
sharedApplication
]
setIdleTimerDisabled
:
enable
.
boolValue
];
result
(
nil
);
NSNumber
*
enabled
=
[
NSNumber
numberWithBool
:[[
UIApplication
sharedApplication
]
isIdleTimerDisabled
]];
if
([
enable
isEqualToNumber
:
enabled
])
{
result
(
nil
);
}
else
{
[[
UIApplication
sharedApplication
]
setIdleTimerDisabled
:
enable
.
boolValue
];
result
(
nil
);
}
}
else
if
([
@"isEnabled"
isEqualToString
:
call
.
method
])
{
bool
enabled
=
[[
UIApplication
sharedApplication
]
isIdleTimerDisabled
];
result
([
NSNumber
numberWithBool
:
enabled
]);
result
([
NSNumber
numberWithBool
:[[
UIApplication
sharedApplication
]
isIdleTimerDisabled
]]);
}
else
{
result
(
FlutterMethodNotImplemented
);
}
...
...
lib/wakelock.dart
View file @
f94731a
...
...
@@ -26,12 +26,16 @@ class Wakelock {
/// You can simply use this function to toggle the wakelock using a [bool] value.
/// ```dart
/// bool enable = true;
/// Wakelock.toggle(enable);
/// // This line keeps the screen on.
/// Wakelock.toggle(on: true);
///
/// bool turnOnWakelock = false;
/// // The following line disables the wakelock.
/// Wakelock.toggle(on: turnOnWakelock);
/// ```
/// You can await the [Future] to wait for the operation to complete.
static
Future
<
void
>
toggle
(
bool
enable
)
=>
_channel
.
invokeMethod
(
'toggle'
,
{
'enable'
:
enable
});
static
Future
<
void
>
toggle
({
bool
on
})
=>
_channel
.
invokeMethod
(
'toggle'
,
{
'enable'
:
on
});
/// If you want to retrieve the current wakelock status, you will have to call [Wakelock.isEnabled]
/// and await its result: `bool isEnabled = await Wakelock.isEnabled()`
...
...
pubspec.yaml
View file @
f94731a
name
:
wakelock
description
:
This Flutter plugin allows you to keep Android and iOS devices awake, i.e. prevent them from sleeping by toggling the wakelock of the phone or tablet on or off.
version
:
0.1.
1+
2
version
:
0.1.2
author
:
creativecreatorormaybenot <19204050+creativecreatorormaybenot@users.noreply.github.com>
homepage
:
https://github.com/creativecreatorormaybenot/wakelock
...
...
Please
register
or
login
to post a comment