Skip to content

Commit 3d92738

Browse files
Merge pull request #45 from AdelAskri/main
add possibility to have a child on web
2 parents 0e33039 + 3b35701 commit 3d92738

6 files changed

Lines changed: 72 additions & 17 deletions

File tree

example/lib/main.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,21 @@ class _HomePageState extends State<HomePage> {
4242
var res = await Navigator.push(
4343
context,
4444
MaterialPageRoute(
45-
builder: (context) => const SimpleBarcodeScannerPage(),
45+
builder: (context) => const SimpleBarcodeScannerPage(
46+
child: Column(
47+
children: [
48+
SizedBox(
49+
height: 20,
50+
),
51+
TextField(
52+
decoration: InputDecoration(
53+
labelText: 'Enter Text',
54+
border: OutlineInputBorder(),
55+
),
56+
),
57+
],
58+
),
59+
),
4660
));
4761
setState(() {
4862
if (res is String) {

lib/screens/io_device.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ class BarcodeScanner extends StatelessWidget {
1414
final Function(String) onScanned;
1515
final String? appBarTitle;
1616
final bool? centerTitle;
17+
final Widget? child;
1718
const BarcodeScanner({
18-
Key? key,
19+
super.key,
1920
required this.lineColor,
2021
required this.cancelButtonText,
2122
required this.isShowFlashIcon,
2223
required this.scanType,
2324
required this.onScanned,
25+
this.child,
2426
this.appBarTitle,
2527
this.centerTitle,
26-
}) : super(key: key);
28+
});
2729

2830
@override
2931
Widget build(BuildContext context) {

lib/screens/unsupported.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ class BarcodeScanner extends StatelessWidget {
99
final Function(String) onScanned;
1010
final String? appBarTitle;
1111
final bool? centerTitle;
12+
final Widget? child;
1213
const BarcodeScanner(
13-
{Key? key,
14+
{super.key,
1415
this.lineColor = "#ff6666",
1516
this.cancelButtonText = "Cancel",
1617
this.isShowFlashIcon = false,
1718
this.scanType = ScanType.barcode,
1819
required this.onScanned,
1920
this.appBarTitle,
20-
this.centerTitle})
21-
: super(key: key);
21+
this.child,
22+
this.centerTitle});
2223

2324
@override
2425
Widget build(BuildContext context) {

lib/screens/web.dart

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore: avoid_web_libraries_in_flutter
22
import 'dart:html' as html;
3-
import 'dart:ui' as ui;
3+
import 'dart:ui_web' as ui;
44

55
import 'package:flutter/material.dart';
66
import '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
}

lib/screens/window.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ class WindowBarcodeScanner extends StatelessWidget {
1818
final bool? centerTitle;
1919

2020
const WindowBarcodeScanner({
21-
Key? key,
21+
super.key,
2222
required this.lineColor,
2323
required this.cancelButtonText,
2424
required this.isShowFlashIcon,
2525
required this.scanType,
2626
required this.onScanned,
2727
this.appBarTitle,
2828
this.centerTitle,
29-
}) : super(key: key);
29+
});
3030

3131
@override
3232
Widget build(BuildContext context) {

lib/simple_barcode_scanner.dart

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,39 @@ class SimpleBarcodeScannerPage extends StatelessWidget {
2525
///center Title
2626
final bool? centerTitle;
2727

28+
/// Specify a child widget to be positioned beneath the scanner.
29+
/// This is beneficial when you need to include a customized text field
30+
/// for manual entry of barcode/QR code.
31+
/// example:
32+
/// ```dart
33+
/// child: Column(
34+
/// children: [
35+
/// SizedBox(
36+
/// height: 20,
37+
/// ),
38+
/// TextField(
39+
/// decoration: InputDecoration(
40+
/// labelText: 'Enter Barcode manually',
41+
/// border: OutlineInputBorder(),
42+
/// ),
43+
/// ),
44+
/// ],
45+
/// ),
46+
/// ```
47+
final Widget? child;
48+
2849
/// appBatTitle and centerTitle support in web and window only
2950
/// Remaining field support in only mobile devices
3051
const SimpleBarcodeScannerPage({
31-
Key? key,
52+
super.key,
3253
this.lineColor = "#ff6666",
3354
this.cancelButtonText = "Cancel",
3455
this.isShowFlashIcon = false,
3556
this.scanType = ScanType.barcode,
3657
this.appBarTitle,
3758
this.centerTitle,
38-
}) : super(key: key);
59+
this.child,
60+
});
3961

4062
@override
4163
Widget build(BuildContext context) {
@@ -46,6 +68,7 @@ class SimpleBarcodeScannerPage extends StatelessWidget {
4668
scanType: scanType,
4769
appBarTitle: appBarTitle,
4870
centerTitle: centerTitle,
71+
child: child,
4972
onScanned: (res) {
5073
Navigator.pop(context, res);
5174
},

0 commit comments

Comments
 (0)