khoren93 / flutter_zxing

Flutter plugin for scanning and generating QR codes using the ZXing library, supporting Android, iOS, and desktop platforms
https://pub.dev/packages/flutter_zxing
MIT License
89 stars 50 forks source link

Camera preview is distorted on older Android devices #68

Closed kaboc closed 10 months ago

kaboc commented 1 year ago

The red box in the screenshot below is a square, but it is shown as a rectangular on Android 5.1. It does not happen on my another phone with Android 10. I'm not really sure if it is related to Android versions though, because I have only those two real devices.

It didn't happen on the same device when I was using another QR scanner plugin.

Environment:

Reproducible code:

import 'package:flutter/material.dart';
import 'package:flutter_zxing/flutter_zxing.dart';

void main() {
  runApp(const App());
}

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: ReaderWidget(
          onScan: (_) {},
        ),
      ),
    );
  }
}

Screenshot:

kaboc commented 1 year ago

I suspected that it might be because of the aspect ratio on a wider screen, but it does not seem to be the direct cause. I don't see the issue on Android 10 even if I change the aspect ratio to be wider.

@override
Widget build(BuildContext context) {
  return MaterialApp(
    home: Scaffold(
      body: AspectRatio(
        aspectRatio: 3 / 4,
        child: ReaderWidget(
          onScan: (_) {},
        ),
      ),
    ),
  );
}
kaboc commented 1 year ago

I noticed this issue was due to a bug of package:camera. The aspect ratio changes when startImageStream() is called. So I searched related for bug reports in the Flutter repo on GitHub and found this.

None of the workarounds written in the page worked for me. There may be no choice but to wait for the bug to be fixed. It looks like the issue has been around for almost five years...

khoren93 commented 10 months ago

I appreciate your thorough investigation into this issue. It's frustrating to see that the problem has persisted for so long. I'll take note of this and will proceed to close the issue. If there are any updates or changes in the future, we can reopen it. Thank you for your patience!