juliansteenbakker / mobile_scanner

A universal scanner for Flutter based on MLKit. Uses CameraX on Android and AVFoundation on iOS.
BSD 3-Clause "New" or "Revised" License
756 stars 446 forks source link

Support landscape startup scanning #107

Closed victorLyw closed 1 year ago

victorLyw commented 2 years ago

I use the Android phone in landscape mode and start QR code scanning, but the MobileScanner view cannot achieve the expected effect.

eivihnd commented 2 years ago

This is also a problem in iOS. Are there any workarounds to support landscape mode?

Cosmo2357 commented 1 year ago

We have the same issue with iOS. Any idea of a temporal alternative way to use landscape mode?

victorLyw commented 1 year ago

@Cosmo2357 You can try using qr_code_scanner

Cosmo2357 commented 1 year ago

@victorLyw Thanx vicorLyw :D Actually, I'm trying to switch from qr_code_scanner since mobile_scanner is pretty fast and steady. it seems native_device_orientation works. I'm not sure though... [https://github.com/juliansteenbakker/mobile_scanner/discussions/17(https://github.com/juliansteenbakker/mobile_scanner/discussions/17)

eivihnd commented 1 year ago

We use mobile_scannner, and wrap it in a Transform.rotate widget. Then, using a simple function we can make the rotation conditional:

bool isLandscape(BuildContext context) => orientation(context) == Orientation.landscape ? true : false;

It is not ideal, as it will not support full screen in landscape mode (a portrait image will be shown with "letterboxing" on each side), but it does enable us to use mobile_scanner.

qr_code_scanner is not maintained and have some issues with Flutter 3

Cosmo2357 commented 1 year ago

@eivihnd Thanx elvihnd! That's an interesting way. works without external package?maybe...? I have no idea what would happen if I won't use full-screen mode in our app though. maybe aspect ratio will change or something like that?

Yep. qr_code_scanner is not maintained. that's my concern too.

eivihnd commented 1 year ago

Yes, it works without any external packages, as Orientation is part of Flutter's MediaQuery. If you have issues with Aspect Ratio, wrapping it in a AspectRatio widget might be a solution. Worth a try...

Cosmo2357 commented 1 year ago

@eivihnd Thanks eivihnd! That’s great! But unfortunately, the camera gets whited out on my real iOS device if I wrap Mobile_Scanner widget with Transform.rotate widget.
on the iPhone simulator, the camera appears working so I guess It's my old iPhone-specific issue. I'm still using iPhone 6. in case someone gets stuck with the same issue on an antique device. I'll try again when I get a new phone! 😄 Thanks

eivihnd commented 1 year ago

Hmm, strange. We use it on different iPads, and it works without any problems. Does issue #175 relate to your problem?

Cosmo2357 commented 1 year ago

@victorLyw Maybe not. The camera is not scanning either 😞 I simply used flutter run

eivihnd commented 1 year ago

How are you handling the key supplied to the MobileScanner? Have you tried supplying a GlobalKey, and seen what happens?

MobileScanner( key: GlobalKey(debugLabel: "mobile-scanner-key"), controller: widget._controller, onDetect: onQrDetected, ),

Cosmo2357 commented 1 year ago

@eivihnd I'm actually new to flutter... Maybe I should learn bout key at first. My code is nothing special. just like an example code of the package. and I warped it with Transform.rotate and I wrote key: GlobalKey(debugLabel: "mobile-scanner-key"),as you mentioned. still white screen... if I remove Transform.rotate it works.

MobileScannerController cameraController = MobileScannerController();
…..
Transform.rotate(
  angle: 60,
  child: MobileScanner(
    key: GlobalKey(debugLabel: "mobile-scanner-key"),
    allowDuplicates: true,
    controller: cameraController,
    onDetect: (barcode, args) {
      if (barcode.rawValue == null) {
        debugPrint('Failed to scan Barcode');
      } else {
        final String code = barcode.rawValue;
        _myFunc(code);
      }
    }
  ),
),
eivihnd commented 1 year ago

@Cosmo2357 Your code works on my iPad. Have you tried with a different device?

Cosmo2357 commented 1 year ago

@eivihnd Sorry for the late reply. I don't have any other iOS mobile devices. So, I asked my friends to check it with their devices.

Btw It seems that the author of mobile_scanner is trying to implement the rotation function. How to handle device orientation changes #17 Is it possible to detect landscape left or landscape right too in your code without external packages?

I appreciate your help :D

Cosmo2357 commented 1 year ago

@eivihnd My friend had the same issue with my code on his iPad. weird... About implementing "right left detection" part, Maybe we have to use method channel or event channel , I guess 🤔

eivihnd commented 1 year ago

It seems like more people have a similar issue, ref #200. If I find time, I will test it on my iPhone.

juliansteenbakker commented 1 year ago

I'm closing this issue in favor of #17 in order to keep the issues section clean.