Skip to content

Commit

Permalink
add flash with duration sample
Browse files Browse the repository at this point in the history
  • Loading branch information
clovisnicolas committed May 11, 2018
1 parent 1373b9b commit 8b10a8d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart"
}
]
}
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class _MyAppState extends State<MyApp> {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('Device has flash: $_hasFlash\n Flash is on: $_isOn'),
new Slider(value: _intensity, onChanged: _isOn ? _intensityChanged : null)
new Slider(value: _intensity, onChanged: _isOn ? _intensityChanged : null),
new RaisedButton(onPressed: () async => await Lamp.flash(new Duration(seconds: 2)), child: new Text("Flash for 2 seconds"))
]),
),
floatingActionButton: new FloatingActionButton(
Expand Down
2 changes: 1 addition & 1 deletion lib/lamp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Lamp {
static Future turnOn({double intensity = 1.0}) => _channel.invokeMethod('turnOn', {'intensity' : intensity.clamp(0.01, 1.0)});
static Future turnOff() => _channel.invokeMethod('turnOff');
static Future<bool> get hasLamp async => await _channel.invokeMethod('hasLamp');
static Future flash(Duration duration) => turnOn().whenComplete(() => Future.delayed(duration, () => turnOff()));
static Future flash(Duration duration) => turnOn().whenComplete(() => new Future.delayed(duration, () => turnOff()));

}

0 comments on commit 8b10a8d

Please sign in to comment.