diff --git a/README.md b/README.md index 3c7a6c9..5e9a69d 100644 --- a/README.md +++ b/README.md @@ -132,23 +132,23 @@ In order to use this plugin, add the following to your Info.plist file: ## Flip Camera (Back/Front) The default camera is the back camera. ```dart -controller.flipCamera(); +await controller.flipCamera(); ``` ## Flash (Off/On) By default, flash is OFF. ```dart -controller.toggleFlash(); +await controller.toggleFlash(); ``` ## Resume/Pause Pause camera stream and scanner. ```dart -controller.pauseCamera(); +await controller.pauseCamera(); ``` Resume camera stream and scanner. ```dart -controller.resumeCamera(); +await controller.resumeCamera(); ``` diff --git a/example/README.md b/example/README.md index d389eb9..c698290 100644 --- a/example/README.md +++ b/example/README.md @@ -80,9 +80,10 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () => setState(() { - controller?.toggleFlash(); - }), + onPressed: () async { + await controller?.toggleFlash(); + setState(() {}); + }, child: FutureBuilder( future: controller?.getFlashStatus(), builder: (context, snapshot) { @@ -93,9 +94,10 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () => setState(() { - controller?.flipCamera(); - }), + onPressed: () async { + await controller?.flipCamera(); + setState(() {}); + }, child: FutureBuilder( future: controller?.getCameraInfo(), builder: (context, snapshot) { @@ -117,8 +119,8 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () { - controller?.pauseCamera(); + onPressed: () async { + await controller?.pauseCamera(); }, child: Text('pause', style: TextStyle(fontSize: 20)), ), @@ -126,8 +128,8 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () { - controller?.resumeCamera(); + onPressed: () async { + await controller?.resumeCamera(); }, child: Text('resume', style: TextStyle(fontSize: 20)), ), @@ -181,13 +183,10 @@ class _QRViewExampleState extends State { @override void dispose() { - controller.dispose(); + controller?.dispose(); super.dispose(); } } - - - ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index 13072f0..2cc42f9 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -57,9 +57,10 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () => setState(() { - controller?.toggleFlash(); - }), + onPressed: () async { + await controller?.toggleFlash(); + setState(() {}); + }, child: FutureBuilder( future: controller?.getFlashStatus(), builder: (context, snapshot) { @@ -70,9 +71,10 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () => setState(() { - controller?.flipCamera(); - }), + onPressed: () async { + await controller?.flipCamera(); + setState(() {}); + }, child: FutureBuilder( future: controller?.getCameraInfo(), builder: (context, snapshot) { @@ -94,8 +96,8 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () { - controller?.pauseCamera(); + onPressed: () async { + await controller?.pauseCamera(); }, child: Text('pause', style: TextStyle(fontSize: 20)), ), @@ -103,8 +105,8 @@ class _QRViewExampleState extends State { Container( margin: EdgeInsets.all(8), child: RaisedButton( - onPressed: () { - controller?.resumeCamera(); + onPressed: () async { + await controller?.resumeCamera(); }, child: Text('resume', style: TextStyle(fontSize: 20)), ), @@ -156,7 +158,7 @@ class _QRViewExampleState extends State { @override void dispose() { - controller.dispose(); + controller?.dispose(); super.dispose(); } }