@@ -24,10 +24,15 @@ class WindowBarcodeScanner extends StatelessWidget {
2424 @override
2525 Widget build (BuildContext context) {
2626 WebviewController controller = WebviewController ();
27-
27+ bool isPermissionGranted = false ;
2828 return Scaffold (
29+ appBar: AppBar (
30+ title: Text (kScanPageTitle),
31+ ),
2932 body: FutureBuilder <bool >(
30- future: initPlatformState (controller: controller),
33+ future: initPlatformState (
34+ controller: controller,
35+ ),
3136 builder: (context, snapshot) {
3237 if (snapshot.hasData && snapshot.data != null ) {
3338 return Webview (
@@ -37,7 +42,8 @@ class WindowBarcodeScanner extends StatelessWidget {
3742 url: url,
3843 kind: permissionKind,
3944 isUserInitiated: isUserInitiated,
40- context: context),
45+ context: context,
46+ isPermissionGranted: isPermissionGranted),
4147 );
4248 } else if (snapshot.hasError) {
4349 return Center (
@@ -55,27 +61,37 @@ class WindowBarcodeScanner extends StatelessWidget {
5561 {required String url,
5662 required WebviewPermissionKind kind,
5763 required bool isUserInitiated,
58- required BuildContext context}) async {
59- final decision = await showDialog <WebviewPermissionDecision >(
60- context: context,
61- builder: (BuildContext context) => AlertDialog (
62- title: const Text ('Permission requested' ),
63- content:
64- Text ('\' ${kind .name }\' permission is require to scan qr/barcode' ),
65- actions: < Widget > [
66- TextButton (
67- onPressed: () =>
68- Navigator .pop (context, WebviewPermissionDecision .deny),
69- child: const Text ('Deny' ),
70- ),
71- TextButton (
72- onPressed: () =>
73- Navigator .pop (context, WebviewPermissionDecision .allow),
74- child: const Text ('Allow' ),
75- ),
76- ],
77- ),
78- );
64+ required BuildContext context,
65+ required bool isPermissionGranted}) async {
66+ final WebviewPermissionDecision ? decision;
67+ if (! isPermissionGranted) {
68+ decision = await showDialog <WebviewPermissionDecision >(
69+ context: context,
70+ builder: (BuildContext context) => AlertDialog (
71+ title: const Text ('Permission requested' ),
72+ content:
73+ Text ('\' ${kind .name }\' permission is require to scan qr/barcode' ),
74+ actions: < Widget > [
75+ TextButton (
76+ onPressed: () {
77+ Navigator .pop (context, WebviewPermissionDecision .deny);
78+ isPermissionGranted = false ;
79+ },
80+ child: const Text ('Deny' ),
81+ ),
82+ TextButton (
83+ onPressed: () {
84+ Navigator .pop (context, WebviewPermissionDecision .allow);
85+ isPermissionGranted = true ;
86+ },
87+ child: const Text ('Allow' ),
88+ ),
89+ ],
90+ ),
91+ );
92+ } else {
93+ decision = WebviewPermissionDecision .allow;
94+ }
7995
8096 return decision ?? WebviewPermissionDecision .none;
8197 }
0 commit comments