Skip to content

Commit 9197395

Browse files
committed
Added onDispose property
1 parent efa779d commit 9197395

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

example/lib/main.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class _MyHomePageState extends State<MyHomePage> {
5353
});
5454
},
5555
onDetect: (p0) {},
56+
onDispose: () {
57+
debugPrint("Barcode scanner disposed!");
58+
},
5659
controller: MobileScannerController(
5760
detectionSpeed: DetectionSpeed.noDuplicates,
5861
),

lib/src/ai_barcode_scanner.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ class AiBarcodeScanner extends StatefulWidget {
127127
/// The function that signals when the barcode scanner is started.
128128
final void Function(MobileScannerArguments?)? onScannerStarted;
129129

130+
/// Called when this object is removed from the tree permanently.
131+
final void Function()? onDispose;
132+
130133
/// if set barcodes will only be scanned if they fall within this [Rect]
131134
/// useful for having a cut-out overlay for example. these [Rect]
132135
/// coordinates are relative to the widget size, so by how much your
@@ -173,6 +176,7 @@ class AiBarcodeScanner extends StatefulWidget {
173176
this.errorBuilder,
174177
this.placeholderBuilder,
175178
this.onScannerStarted,
179+
this.onDispose,
176180
this.scanWindow,
177181
this.startDelay,
178182
this.hintWidget,
@@ -203,6 +207,10 @@ class _AiBarcodeScannerState extends State<AiBarcodeScanner> {
203207
void dispose() {
204208
controller.dispose();
205209
super.dispose();
210+
211+
if (widget.onDispose != null) {
212+
widget.onDispose!();
213+
}
206214
}
207215

208216
@override

0 commit comments

Comments
 (0)