From 8f1c4256dc6069180a90a2d9aa4520830df9f98c Mon Sep 17 00:00:00 2001 From: Luis Thein Date: Fri, 19 Jul 2019 09:01:07 +0200 Subject: [PATCH] Globalkey gets added in Widget creation --- example/lib/main.dart | 2 ++ lib/qr_code_scanner.dart | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c050628..2e01987 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,6 +22,7 @@ class _QRViewExampleState extends State { var flashState = flash_on; var cameraState = front_camera; QRViewController controller; + final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); @override Widget build(BuildContext context) { @@ -30,6 +31,7 @@ class _QRViewExampleState extends State { children: [ Expanded( child: QRView( + key: qrKey, onQRViewCreated: _onQRViewCreated, ), flex: 4, diff --git a/lib/qr_code_scanner.dart b/lib/qr_code_scanner.dart index d944a80..e707de1 100644 --- a/lib/qr_code_scanner.dart +++ b/lib/qr_code_scanner.dart @@ -8,8 +8,8 @@ typedef void QRViewCreatedCallback(QRViewController controller); class QRView extends StatefulWidget { const QRView({ - Key key, - this.onQRViewCreated, + @required Key key, + @required this.onQRViewCreated, }) : super(key: key); final QRViewCreatedCallback onQRViewCreated; @@ -19,7 +19,6 @@ class QRView extends StatefulWidget { } class _QRViewState extends State { - final GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); @override Widget build(BuildContext context) { var androidView = AndroidView( @@ -48,7 +47,7 @@ class _QRViewState extends State { if (widget.onQRViewCreated == null) { return; } - widget.onQRViewCreated(QRViewController._(id, qrKey)); + widget.onQRViewCreated(QRViewController._(id, widget.key)); } }