mobile/apps/auth/plugins/qr/README.md
A Flutter plugin for scanning QR codes from image files. This plugin provides a simple interface to scan QR codes from images on both Android and iOS platforms.
| Platform | Support |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| Web | ❌ |
| macOS | ❌ |
| Windows | ❌ |
| Linux | ❌ |
Add this to your package's pubspec.yaml file:
dependencies:
ente_qr:
path: path/to/ente_qr
import 'package:ente_qr/ente_qr.dart';
final qr = EnteQr();
// Scan QR code from an image file
final result = await qr.scanQrFromImage('/path/to/image.jpg');
if (result.success) {
print('QR Code content: ${result.content}');
} else {
print('Error: ${result.error}');
}
import 'package:flutter/material.dart';
import 'package:ente_qr/ente_qr.dart';
import 'package:file_picker/file_picker.dart';
class QrScannerPage extends StatefulWidget {
@override
_QrScannerPageState createState() => _QrScannerPageState();
}
class _QrScannerPageState extends State<QrScannerPage> {
final _enteQr = EnteQr();
String _result = 'No QR code scanned';
Future<void> _scanQrFromImage() async {
// Pick an image file
FilePickerResult? fileResult = await FilePicker.platform.pickFiles(
type: FileType.image,
allowMultiple: false,
);
if (fileResult != null && fileResult.files.single.path != null) {
final imagePath = fileResult.files.single.path!;
// Scan QR code from the selected image
final qrResult = await _enteQr.scanQrFromImage(imagePath);
setState(() {
if (qrResult.success) {
_result = 'QR Code: ${qrResult.content}';
} else {
_result = 'Error: ${qrResult.error}';
}
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('QR Scanner')),
body: Column(
children: [
ElevatedButton(
onPressed: _scanQrFromImage,
child: Text('Pick Image and Scan QR'),
),
Text(_result),
],
),
);
}
}
The main class for QR code scanning operations.
scanQrFromImage(String imagePath)Scans a QR code from an image file.
Parameters:
imagePath (String): The file path to the image containing the QR codeReturns:
Future<QrScanResult>: A result object containing either the QR code content or an errorThe result object returned by QR scanning operations.
Properties:
content (String?): The QR code content if successful, null otherwiseerror (String?): Error message if scanning failed, null otherwisesuccess (bool): Whether the scanning operation was successfulFactory Constructors:
QrScanResult.success(String content): Creates a successful resultQrScanResult.error(String error): Creates an error resultThe Android implementation uses the ZXing library (com.google.zxing) for QR code detection:
com.journeyapps:zxing-android-embedded:4.3.0com.google.zxing:core:3.5.1The iOS implementation uses Core Image framework's built-in QR code detection capabilities via CIDetector.
The plugin provides comprehensive error handling for common scenarios:
All errors are returned as part of the QrScanResult object with descriptive error messages.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the same license as the Ente project.