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.
- Host: GitHub
- URL: https://github.com/cloudacy/flutter_native_barcode_scanner
- Owner: cloudacy
- License: mit
- Created: 2020-05-01T21:25:32.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-23T12:13:19.000Z (over 2 years ago)
- Last Synced: 2024-02-23T13:27:19.471Z (over 2 years ago)
- Topics: android, flutter, flutter-plugin, ios
- Language: Dart
- Homepage:
- Size: 351 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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
...
```