Skip to content

Commit 3325d34

Browse files
Merge pull request #4 from tashi146/main
Added back button,title and permission for web and window
2 parents 161a31e + 0014de5 commit 3325d34

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

example/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ packages:
136136
path: ".."
137137
relative: true
138138
source: path
139-
version: "0.0.3"
139+
version: "0.0.4"
140140
sky_engine:
141141
dependency: transitive
142142
description: flutter
@@ -225,7 +225,7 @@ packages:
225225
name: webview_windows
226226
url: "https://pub.dartlang.org"
227227
source: hosted
228-
version: "0.1.9"
228+
version: "0.2.0"
229229
sdks:
230230
dart: ">=2.17.0 <3.0.0"
231231
flutter: ">=3.0.0"

lib/constant.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ class PackageConstant {
44
static const barcodeFileWebPath =
55
"assets/packages/simple_barcode_scanner/assets/barcode.html";
66
}
7+
8+
String kScanPageTitle = 'Scan barcode/qrcode';

lib/screens/web.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class BarcodeScanner extends StatelessWidget {
4646
.registerViewFactory(createdViewId, (int viewId) => iframe);
4747

4848
return Scaffold(
49+
appBar: AppBar(
50+
title: Text(kScanPageTitle),
51+
),
4952
body: HtmlElementView(
5053
viewType: createdViewId,
5154
),

lib/screens/window.dart

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
flutter:
1717
sdk: flutter
1818
# Flutter window webview
19-
webview_windows: ^0.1.9
19+
webview_windows: ^0.2.0
2020
# Barcode scanner for android and ios
2121
flutter_barcode_scanner: ^2.0.0
2222
#Get assets path for window platform
@@ -25,7 +25,7 @@ dependencies:
2525
dev_dependencies:
2626
flutter_test:
2727
sdk: flutter
28-
flutter_lints: ^2.0.0
28+
flutter_lints: ^2.0.1
2929

3030
# For information on the generic Dart part of this file, see the
3131
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)