yushulx / flutter_barcode_sdk

Build barcode QR detection apps for Windows, Linux, macOS, Android, iOS and web.
https://pub.dev/packages/flutter_barcode_sdk
MIT License
47 stars 18 forks source link

Error with Flutter Web: "method not found: 'createDefaultScanner'" when deploying locally #29

Closed ben-pac closed 2 years ago

ben-pac commented 2 years ago

Hi, Thank you for this package!

I am running into an issue when trying out to scan something after deploying a Web application locally (using python http.server module).

Everything works well when starting it through android studio, but when deployed, it seems that it cannot find the methods of the js library, giving the following error during the "init()" call: image

I feel like I am missing something obvious, but I can't figure it out...

Following the readme, I have the following in the index.html:

<!DOCTYPE html>
<html>
<head>
  <base href="$FLUTTER_BASE_HREF">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="error_flutter_barcode_sdk">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>error_flutter_barcode_sdk</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    var serviceWorkerVersion = null;
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
  <script>
    window.addEventListener('load', function(ev) {
      // Download main.dart.js
      _flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: serviceWorkerVersion,
        }
      }).then(function(engineInitializer) {
        return engineInitializer.initializeEngine();
      }).then(function(appRunner) {
        return appRunner.runApp();
      });
    });
  </script>
  <script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.0.0/dist/dbr.js"></script>
  <script src="https://yushulx.me/javascript-barcode-qr-code-scanner/dbr-scanner-wrapper.js"></script>
</body>
</html>

I made a simple repo that reproduce this error here: https://github.com/ben-pac/error_flutter_barcode_sdk

I just build it with the command flutter build web and start the local server with python3 -m http.server inside the build/web folder. Upon loading the page, the error appears.

Output of flutter doctor if it helps:

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.0.0, on Microsoft Windows [version 10.0.19044.1645], locale fr-CH) [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [√] Chrome - develop for the web [X] Visual Studio - develop for Windows X Visual Studio not installed; this is necessary for Windows development. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2021.2) [√] VS Code (version 1.67.1) [√] Connected device (3 available) [√] HTTP Host Availability

yushulx commented 2 years ago

@ben-pac thanks for your feedback. I've fixed the issue https://github.com/yushulx/flutter_barcode_sdk/commit/c392211a6176523f116fc0d6083bffe6efaf05e0. You can update the SDK to v2.0.3