11// ignore: avoid_web_libraries_in_flutter
22import 'dart:html' as html;
3- import 'dart:ui ' as ui;
3+ import 'dart:ui_web ' as ui;
44
55import 'package:flutter/material.dart' ;
66import 'package:simple_barcode_scanner/constant.dart' ;
@@ -15,17 +15,18 @@ class BarcodeScanner extends StatelessWidget {
1515 final Function (String ) onScanned;
1616 final String ? appBarTitle;
1717 final bool ? centerTitle;
18-
18+ final Widget ? child;
1919 const BarcodeScanner ({
20- Key ? key,
20+ super . key,
2121 required this .lineColor,
2222 required this .cancelButtonText,
2323 required this .isShowFlashIcon,
2424 required this .scanType,
2525 required this .onScanned,
2626 this .appBarTitle,
2727 this .centerTitle,
28- }) : super (key: key);
28+ this .child,
29+ });
2930
3031 @override
3132 Widget build (BuildContext context) {
@@ -35,6 +36,8 @@ class BarcodeScanner extends StatelessWidget {
3536 final html.IFrameElement iframe = html.IFrameElement ()
3637 ..src = PackageConstant .barcodeFileWebPath
3738 ..style.border = 'none'
39+ ..style.width = '100%'
40+ ..style.height = '100%'
3841 ..onLoad.listen ((event) async {
3942 /// Barcode listener on success barcode scanned
4043 html.window.onMessage.listen ((event) {
@@ -49,14 +52,26 @@ class BarcodeScanner extends StatelessWidget {
4952 // ignore: undefined_prefixed_name
5053 ui.platformViewRegistry
5154 .registerViewFactory (createdViewId, (int viewId) => iframe);
52-
55+ final width = MediaQuery .of (context).size.width;
56+ final height = width / (16 / 9 );
5357 return Scaffold (
5458 appBar: AppBar (
5559 title: Text (appBarTitle ?? kScanPageTitle),
5660 centerTitle: centerTitle,
5761 ),
58- body: HtmlElementView (
59- viewType: createdViewId,
62+ body: SingleChildScrollView (
63+ child: Column (
64+ children: [
65+ SizedBox (
66+ height: height,
67+ width: width,
68+ child: HtmlElementView (
69+ viewType: createdViewId,
70+ ),
71+ ),
72+ if (child != null ) child! ,
73+ ],
74+ ),
6075 ),
6176 );
6277 }
0 commit comments