pdliuw / ai_barcode

Barcode generation,Barcode scanning,qrcode,qrcode generation,qrcode creator,flutter barcode,flutter qrcode,support android iOS web platform
BSD 3-Clause "New" or "Revised" License
125 stars 82 forks source link

Camera Facing Setting #79

Open rickyok opened 2 years ago

rickyok commented 2 years ago

Hi, i really like your plugin, really works well in my project.

I have one suggestion, if you don't mind. Please make config to select the camera facing for "environment" or "user". Especially for web.

I kinda hardcoded specific for my case in qr_code_scanner_web_impl.dart

    // find out what device this apps is running from
    String facingMode = "environment"; // default
    try {
      final userAgent = html.window.navigator.userAgent.toString()
          .toLowerCase();
      if (userAgent.contains('iphone'))
        facingMode = 'environment';
      else if (userAgent.contains('ipad'))
        facingMode = 'user';
      else if (userAgent.contains('macintosh'))
        facingMode = 'user';
      else if (userAgent.contains('android')) facingMode = 'environment';
    }
    catch (err) {
      // do nothing
    }

    // Access the webcam stream
    try {
      html.window.navigator.mediaDevices?.getUserMedia({
        'video': {'facingMode': facingMode}
      }).then((html.MediaStream stream) {
        _stream = stream;
        _video.srcObject = stream;
        _video.setAttribute('playsinline',
            'true'); // required to tell iOS safari we don't want fullscreen
        _video.play();
      });
    } catch (err) {
      print(err);
      //Fallback
      try {
        html.window.navigator
            .getUserMedia(video: {'facingMode': facingMode}).then(
                (html.MediaStream stream) {
          _stream = stream;
          _video.srcObject = stream;
          _video.setAttribute('playsinline',
              'true'); // required to tell iOS safari we don't want fullscreen
          _video.play();
        });
      } catch (e) {
        print(e);
      }
    }

I wanna push request myself. But i'm really new into flutter, and haven't learn how to send parameter from the parent plugin to the web implementation.

I want to make some paremeter to pass like

PlatformAiBarcodeScannerWidget(platformScannerController: _scannerController, facing: 'user')

Thanks