An open API service indexing awesome lists of open source software.

https://github.com/cloudacy/flutter_native_barcode_scanner

A barcode scanner for Flutter, using platform native APIs.
https://github.com/cloudacy/flutter_native_barcode_scanner

android flutter flutter-plugin ios

Last synced: 4 months ago
JSON representation

A barcode scanner for Flutter, using platform native APIs.

Awesome Lists containing this project

README

          

# flutter_native_barcode_scanner

A barcode scanner for Flutter, using platform native APIs.

⚠️ This package is still in beta stage! ⚠️

## Example

```dart
class FlutterNativeBarcodeScannerExample extends StatefulWidget {
@override
_FlutterNativeBarcodeScannerExampleState createState() => _FlutterNativeBarcodeScannerExampleState();
}

class _FlutterNativeBarcodeScannerExampleState extends State {
final _textureStream = StreamController();

@override
void initState() {
super.initState();

_scanBarcode();
}

Future _scanBarcode() async {
try {
// Start the barcode scan.
final texture = await FlutterNativeBarcodeScanner.start();
if (texture == null) {
// Handle error...

// Stop the barcode scan process.
await FlutterNativeBarcodeScanner.stop();
return;
}

// Add the returned texture to the textureStream.
_textureStream.add(texture);

// Wait until the first barcode comes in.
final code = await FlutterNativeBarcodeScanner.getBarcode();
if (code == null) {
// Handle error...

// Stop the barcode scan process.
await FlutterNativeBarcodeScanner.stop();
return;
}

// Process code ...
} catch (e) {
// Handle error...
} finally {
// Stop the barcode scan process.
await FlutterNativeBarcodeScanner.stop();
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('barcode scan example')),
body: Center(
child: StreamBuilder(
stream: _textureStream.stream,
builder: (context, snapshot) {
final texture = snapshot.data;
if (texture == null) {
return CircularProgressIndicator();
}

return FlutterNativeBarcodeScannerPreview(texture: texture);
},
),
),
);
}
}
```

## Installation

### Android

**This plugin supports Android 5.0 ("Lollipop", SDK 21) or higher.**

Add the barcode ML model to the `/android/app/src/main/AndroidManifest.xml` file of the app.
https://firebase.google.com/docs/ml-kit/android/read-barcodes

```xml

...

```

### iOS

**This plugin supports iOS 12.0 or higher.**

Make sure that the `NSCameraUsageDescription` (or `Privacy - Camera Usage Description`) string is set at `ios/Runner/info.plist` to scan codes.

```xml
NSCameraUsageDescription
...
```