Explorar el Código

Globalkey gets added in Widget creation

flutter-beta
Luis Thein hace 7 años
padre
commit
8f1c4256dc
Se han modificado 2 ficheros con 5 adiciones y 4 borrados
  1. +2
    -0
      example/lib/main.dart
  2. +3
    -4
      lib/qr_code_scanner.dart

+ 2
- 0
example/lib/main.dart Ver fichero

@@ -22,6 +22,7 @@ class _QRViewExampleState extends State<QRViewExample> {
var flashState = flash_on; var flashState = flash_on;
var cameraState = front_camera; var cameraState = front_camera;
QRViewController controller; QRViewController controller;
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');


@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -30,6 +31,7 @@ class _QRViewExampleState extends State<QRViewExample> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: QRView( child: QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated, onQRViewCreated: _onQRViewCreated,
), ),
flex: 4, flex: 4,


+ 3
- 4
lib/qr_code_scanner.dart Ver fichero

@@ -8,8 +8,8 @@ typedef void QRViewCreatedCallback(QRViewController controller);


class QRView extends StatefulWidget { class QRView extends StatefulWidget {
const QRView({ const QRView({
Key key,
this.onQRViewCreated,
@required Key key,
@required this.onQRViewCreated,
}) : super(key: key); }) : super(key: key);


final QRViewCreatedCallback onQRViewCreated; final QRViewCreatedCallback onQRViewCreated;
@@ -19,7 +19,6 @@ class QRView extends StatefulWidget {
} }


class _QRViewState extends State<QRView> { class _QRViewState extends State<QRView> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var androidView = AndroidView( var androidView = AndroidView(
@@ -48,7 +47,7 @@ class _QRViewState extends State<QRView> {
if (widget.onQRViewCreated == null) { if (widget.onQRViewCreated == null) {
return; return;
} }
widget.onQRViewCreated(QRViewController._(id, qrKey));
widget.onQRViewCreated(QRViewController._(id, widget.key));
} }
} }




Cargando…
Cancelar
Guardar