@@ -8,6 +8,8 @@ import 'package:simple_barcode_scanner/constant.dart';
88import 'package:simple_barcode_scanner/enum.dart' ;
99import 'package:webview_windows/webview_windows.dart' ;
1010
11+ import '../barcode_appbar.dart' ;
12+
1113class WindowBarcodeScanner extends StatelessWidget {
1214 final String lineColor;
1315 final String cancelButtonText;
@@ -16,6 +18,7 @@ class WindowBarcodeScanner extends StatelessWidget {
1618 final Function (String ) onScanned;
1719 final String ? appBarTitle;
1820 final bool ? centerTitle;
21+ final BarcodeAppBar ? barcodeAppBar;
1922
2023 const WindowBarcodeScanner ({
2124 super .key,
@@ -26,6 +29,7 @@ class WindowBarcodeScanner extends StatelessWidget {
2629 required this .onScanned,
2730 this .appBarTitle,
2831 this .centerTitle,
32+ this .barcodeAppBar,
2933 });
3034
3135 @override
@@ -39,18 +43,7 @@ class WindowBarcodeScanner extends StatelessWidget {
3943 });
4044
4145 return Scaffold (
42- appBar: AppBar (
43- title: Text (appBarTitle ?? kScanPageTitle),
44- centerTitle: centerTitle,
45- leading: IconButton (
46- onPressed: () {
47- /// send close event to web-view
48- controller.postWebMessage (json.encode ({"event" : "close" }));
49- Navigator .pop (context);
50- },
51- icon: const Icon (Icons .arrow_back_ios),
52- ),
53- ),
46+ appBar: _buildAppBar (controller, context),
5447 body: FutureBuilder <bool >(
5548 future: initPlatformState (
5649 controller: controller,
@@ -155,4 +148,42 @@ class WindowBarcodeScanner extends StatelessWidget {
155148 }
156149 return true ;
157150 }
151+
152+ _buildAppBar (WebviewController controller, BuildContext context) {
153+ if (appBarTitle == null && barcodeAppBar == null ) {
154+ return null ;
155+ }
156+ if (barcodeAppBar != null ) {
157+ return AppBar (
158+ title: barcodeAppBar? .appBarTitle != null
159+ ? Text (barcodeAppBar! .appBarTitle! )
160+ : null ,
161+ centerTitle: barcodeAppBar? .centerTitle ?? false ,
162+ leading: barcodeAppBar! .enableBackButton == true
163+ ? IconButton (
164+ onPressed: () {
165+ /// send close event to web-view
166+ controller.postWebMessage (json.encode ({"event" : "close" }));
167+ Navigator .pop (context);
168+ },
169+ icon: barcodeAppBar? .backButtonIcon ??
170+ const Icon (Icons .arrow_back_ios),
171+ )
172+ : null ,
173+ automaticallyImplyLeading: false ,
174+ );
175+ }
176+ return AppBar (
177+ title: Text (appBarTitle ?? kScanPageTitle),
178+ centerTitle: centerTitle,
179+ leading: IconButton (
180+ onPressed: () {
181+ /// send close event to web-view
182+ controller.postWebMessage (json.encode ({"event" : "close" }));
183+ Navigator .pop (context);
184+ },
185+ icon: const Icon (Icons .arrow_back_ios),
186+ ),
187+ );
188+ }
158189}
0 commit comments