Showing
1 changed file
with
67 additions
and
60 deletions
| @@ -75,15 +75,15 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | @@ -75,15 +75,15 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 75 | return Scaffold( | 75 | return Scaffold( |
| 76 | appBar: AppBar(title: const Text('Mobile Scanner')), | 76 | appBar: AppBar(title: const Text('Mobile Scanner')), |
| 77 | body: MobileScanner( | 77 | body: MobileScanner( |
| 78 | - allowDuplicates: false, | ||
| 79 | - onDetect: (barcode) { | ||
| 80 | - if (barcode.rawValue == null) { | ||
| 81 | - debugPrint('Failed to scan Barcode'); | ||
| 82 | - } else { | ||
| 83 | - final String code = barcode.rawValue!; | ||
| 84 | - debugPrint('Barcode found! $code'); | 78 | + // fit: BoxFit.contain, |
| 79 | + onDetect: (capture) { | ||
| 80 | + final List<Barcode> barcodes = capture.barcodes; | ||
| 81 | + final Uint8List? image = capture.image; | ||
| 82 | + for (final barcode in barcodes) { | ||
| 83 | + debugPrint('Barcode found! ${barcode.rawValue}'); | ||
| 85 | } | 84 | } |
| 86 | - }), | 85 | + }, |
| 86 | + ), | ||
| 87 | ); | 87 | ); |
| 88 | } | 88 | } |
| 89 | ``` | 89 | ``` |
| @@ -98,17 +98,18 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | @@ -98,17 +98,18 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 98 | return Scaffold( | 98 | return Scaffold( |
| 99 | appBar: AppBar(title: const Text('Mobile Scanner')), | 99 | appBar: AppBar(title: const Text('Mobile Scanner')), |
| 100 | body: MobileScanner( | 100 | body: MobileScanner( |
| 101 | - allowDuplicates: false, | 101 | + // fit: BoxFit.contain, |
| 102 | controller: MobileScannerController( | 102 | controller: MobileScannerController( |
| 103 | - facing: CameraFacing.front, torchEnabled: true), | ||
| 104 | - onDetect: (barcode) { | ||
| 105 | - if (barcode.rawValue == null) { | ||
| 106 | - debugPrint('Failed to scan Barcode'); | ||
| 107 | - } else { | ||
| 108 | - final String code = barcode.rawValue!; | ||
| 109 | - debugPrint('Barcode found! $code'); | 103 | + facing: CameraFacing.front, torchEnabled: true, |
| 104 | + ), | ||
| 105 | + onDetect: (capture) { | ||
| 106 | + final List<Barcode> barcodes = capture.barcodes; | ||
| 107 | + final Uint8List? image = capture.image; | ||
| 108 | + for (final barcode in barcodes) { | ||
| 109 | + debugPrint('Barcode found! ${barcode.rawValue}'); | ||
| 110 | } | 110 | } |
| 111 | - }), | 111 | + }, |
| 112 | + ), | ||
| 112 | ); | 113 | ); |
| 113 | } | 114 | } |
| 114 | ``` | 115 | ``` |
| @@ -161,16 +162,17 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | @@ -161,16 +162,17 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 161 | ], | 162 | ], |
| 162 | ), | 163 | ), |
| 163 | body: MobileScanner( | 164 | body: MobileScanner( |
| 164 | - allowDuplicates: false, | 165 | + // fit: BoxFit.contain, |
| 165 | controller: cameraController, | 166 | controller: cameraController, |
| 166 | - onDetect: (barcode) { | ||
| 167 | - if (barcode.rawValue == null) { | ||
| 168 | - debugPrint('Failed to scan Barcode'); | ||
| 169 | - } else { | ||
| 170 | - final String code = barcode.rawValue!; | ||
| 171 | - debugPrint('Barcode found! $code'); | 167 | + onDetect: (capture) { |
| 168 | + final List<Barcode> barcodes = capture.barcodes; | ||
| 169 | + final Uint8List? image = capture.image; | ||
| 170 | + for (final barcode in barcodes) { | ||
| 171 | + debugPrint('Barcode found! ${barcode.rawValue}'); | ||
| 172 | } | 172 | } |
| 173 | - })); | 173 | + }, |
| 174 | + ), | ||
| 175 | + ); | ||
| 174 | } | 176 | } |
| 175 | ``` | 177 | ``` |
| 176 | 178 | ||
| @@ -184,25 +186,25 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | @@ -184,25 +186,25 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 184 | return Scaffold( | 186 | return Scaffold( |
| 185 | appBar: AppBar(title: const Text('Mobile Scanner')), | 187 | appBar: AppBar(title: const Text('Mobile Scanner')), |
| 186 | body: MobileScanner( | 188 | body: MobileScanner( |
| 189 | + fit: BoxFit.contain, | ||
| 187 | controller: MobileScannerController( | 190 | controller: MobileScannerController( |
| 188 | - facing: CameraFacing.front, | ||
| 189 | - torchEnabled: true, | 191 | + // facing: CameraFacing.back, |
| 192 | + // torchEnabled: false, | ||
| 190 | returnImage: true, | 193 | returnImage: true, |
| 191 | ), | 194 | ), |
| 192 | - onDetect: (barcode) { | ||
| 193 | - if (barcode.rawValue == null) { | ||
| 194 | - debugPrint('Failed to scan Barcode'); | ||
| 195 | - } else { | ||
| 196 | - final String code = barcode.rawValue!; | ||
| 197 | - debugPrint('Barcode found! $code'); | ||
| 198 | - | ||
| 199 | - debugPrint( | ||
| 200 | - 'Image returned! length: ${barcode.image!.lengthInBytes}b'); | 195 | + onDetect: (capture) { |
| 196 | + final List<Barcode> barcodes = capture.barcodes; | ||
| 197 | + final Uint8List? image = capture.image; | ||
| 198 | + for (final barcode in barcodes) { | ||
| 199 | + debugPrint('Barcode found! ${barcode.rawValue}'); | ||
| 200 | + } | ||
| 201 | + if (image != null) { | ||
| 201 | showDialog( | 202 | showDialog( |
| 202 | context: context, | 203 | context: context, |
| 203 | - builder: (context) => Image(image: MemoryImage(barcode.image!)), | 204 | + builder: (context) => |
| 205 | + Image(image: MemoryImage(image)), | ||
| 204 | ); | 206 | ); |
| 205 | - Future.delayed(const Duration(seconds: 2), () { | 207 | + Future.delayed(const Duration(seconds: 5), () { |
| 206 | Navigator.pop(context); | 208 | Navigator.pop(context); |
| 207 | }); | 209 | }); |
| 208 | } | 210 | } |
| @@ -212,25 +214,30 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | @@ -212,25 +214,30 @@ import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 212 | } | 214 | } |
| 213 | ``` | 215 | ``` |
| 214 | 216 | ||
| 215 | -### Scan result | ||
| 216 | - | ||
| 217 | -You can use the following properties of the Barcode, which gets | ||
| 218 | -passed to the `onDetect` function. | ||
| 219 | - | ||
| 220 | -| Property name | Type | Description | ||
| 221 | -|---------------|----------------|-------------------- | ||
| 222 | -| image | Uint8List? | only if returnImage was set to true | ||
| 223 | -| format | BarcodeFormat | | ||
| 224 | -| rawBytes | Uint8List? | binary scan result | ||
| 225 | -| rawValue | String? | Value if barcode is in UTF-8 format | ||
| 226 | -| displayValue | String? | | ||
| 227 | -| type | BarcodeType | | ||
| 228 | -| calendarEvent | CalendarEvent? | | ||
| 229 | -| contactInfo | ContactInfo? | | ||
| 230 | -| driverLicense | DriverLicense? | | ||
| 231 | -| email | Email? | | ||
| 232 | -| geoPoint | GeoPoint? | | ||
| 233 | -| phone | Phone? | | ||
| 234 | -| sms | SMS? | | ||
| 235 | -| url | UrlBookmark? | | ||
| 236 | -| wifi | WiFi? | WiFi Access-Point details | 217 | +### BarcodeCapture |
| 218 | + | ||
| 219 | +The onDetect function returns a BarcodeCapture objects which contains the following items. | ||
| 220 | + | ||
| 221 | +| Property name | Type | Description | | ||
| 222 | +|---------------|---------------|-----------------------------------| | ||
| 223 | +| barcodes | List<Barcode> | A list with scanned barcodes. | | ||
| 224 | +| image | Uint8List? | If enabled, an image of the scan. | | ||
| 225 | + | ||
| 226 | +You can use the following properties of the Barcode object. | ||
| 227 | + | ||
| 228 | +| Property name | Type | Description | | ||
| 229 | +|---------------|----------------|-------------------------------------| | ||
| 230 | +| format | BarcodeFormat | | | ||
| 231 | +| rawBytes | Uint8List? | binary scan result | | ||
| 232 | +| rawValue | String? | Value if barcode is in UTF-8 format | | ||
| 233 | +| displayValue | String? | | | ||
| 234 | +| type | BarcodeType | | | ||
| 235 | +| calendarEvent | CalendarEvent? | | | ||
| 236 | +| contactInfo | ContactInfo? | | | ||
| 237 | +| driverLicense | DriverLicense? | | | ||
| 238 | +| email | Email? | | | ||
| 239 | +| geoPoint | GeoPoint? | | | ||
| 240 | +| phone | Phone? | | | ||
| 241 | +| sms | SMS? | | | ||
| 242 | +| url | UrlBookmark? | | | ||
| 243 | +| wifi | WiFi? | WiFi Access-Point details | |
-
Please register or login to post a comment