Skip to content

Commit e6fa7d1

Browse files
committed
camera permission refactored
1 parent 7fb5001 commit e6fa7d1

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

lib/screens/window.dart

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ 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(),
2930
body: FutureBuilder<bool>(
30-
future: initPlatformState(controller: controller),
31+
future: initPlatformState(
32+
controller: controller,
33+
),
3134
builder: (context, snapshot) {
3235
if (snapshot.hasData && snapshot.data != null) {
3336
return Webview(
@@ -37,7 +40,8 @@ class WindowBarcodeScanner extends StatelessWidget {
3740
url: url,
3841
kind: permissionKind,
3942
isUserInitiated: isUserInitiated,
40-
context: context),
43+
context: context,
44+
isPermissionGranted: isPermissionGranted),
4145
);
4246
} else if (snapshot.hasError) {
4347
return Center(
@@ -55,27 +59,37 @@ class WindowBarcodeScanner extends StatelessWidget {
5559
{required String url,
5660
required WebviewPermissionKind kind,
5761
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-
);
62+
required BuildContext context,
63+
required bool isPermissionGranted}) async {
64+
final WebviewPermissionDecision? decision;
65+
if (!isPermissionGranted) {
66+
decision = await showDialog<WebviewPermissionDecision>(
67+
context: context,
68+
builder: (BuildContext context) => AlertDialog(
69+
title: const Text('Permission requested'),
70+
content:
71+
Text('\'${kind.name}\' permission is require to scan qr/barcode'),
72+
actions: <Widget>[
73+
TextButton(
74+
onPressed: () {
75+
Navigator.pop(context, WebviewPermissionDecision.deny);
76+
isPermissionGranted = false;
77+
},
78+
child: const Text('Deny'),
79+
),
80+
TextButton(
81+
onPressed: () {
82+
Navigator.pop(context, WebviewPermissionDecision.allow);
83+
isPermissionGranted = true;
84+
},
85+
child: const Text('Allow'),
86+
),
87+
],
88+
),
89+
);
90+
} else {
91+
decision = WebviewPermissionDecision.allow;
92+
}
7993

8094
return decision ?? WebviewPermissionDecision.none;
8195
}

0 commit comments

Comments
 (0)