From fdf848231e4c314617958b83844805f18354a4a1 Mon Sep 17 00:00:00 2001 From: Enrico Benedos Date: Mon, 11 Jan 2021 21:52:29 +0100 Subject: [PATCH] Call controller methods async --- example/lib/main.dart | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) 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(); } }