Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot scan barcode in image #109

Open
kaboc opened this issue Sep 17, 2023 · 2 comments
Open

Cannot scan barcode in image #109

kaboc opened this issue Sep 17, 2023 · 2 comments

Comments

@kaboc
Copy link

kaboc commented Sep 17, 2023

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

  1. Create a new Flutter project.
  2. Create an "assets" folder and place an image in there.
  3. Run the code below.
  4. 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
Copy link
Author

kaboc commented Sep 17, 2023

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
Copy link

cmy665 commented May 14, 2024

It is also not recognized in version 1.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants