Cannot scan barcode in image
kaboc opened this issue · 3 comments
kaboc commented
Scanning a barcode in an image returns Code with empty text
and error
at 1.4.0 and 1.4.1. There was no issue at the point of v1.3.2.
Code sample
- Create a new Flutter project.
- Create an "assets" folder and place an image in there.
- Run the code below.
- Press the button and see the text shown in the screen.
pubspec.yaml
...
dependencies:
...
flutter_zxing: 1.4.1
path_provider: ^2.1.1
...
flutter:
assets:
- assets/
main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(const App());
class App extends StatefulWidget {
const App();
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
Code? _code;
Future<void> _read() async {
final image = await rootBundle.load('assets/image.jpg'); // Put the actual file name
final dir = await getTemporaryDirectory();
final file = File('${dir.path}/${DateTime.now().microsecondsSinceEpoch}');
file.writeAsBytesSync(image.buffer.asUint8List());
final code = await zx.readBarcodeImagePathString(file.path);
setState(() => _code = code);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: _read,
child: const Text('Scan'),
),
const SizedBox(height: 24.0),
Text('Text: ${_code?.text}'),
Text('Error: ${_code?.error}'),
],
),
),
),
),
);
}
}
kaboc commented
I think this is a regression. Besides the issue above, it seems to me that it is also problematic that there is currently no way to automatically detect such a regression. Some tests may be necessary. It wouldn't be difficult to write tests for scanning an image file, compared to scanning with a camera.
cmy665 commented
It is also not recognized in version 1.5.2