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

Padding does not work as expected #104

Closed
hhkkyy opened this issue Jul 29, 2020 · 10 comments · May be fixed by #144
Closed

Padding does not work as expected #104

hhkkyy opened this issue Jul 29, 2020 · 10 comments · May be fixed by #144
Assignees
Labels
bug Something isn't working fixed Fixed and will be included in next release
Milestone

Comments

@hhkkyy
Copy link

hhkkyy commented Jul 29, 2020

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
        appBar: AppBar(),
        body: Row(
          children: <Widget>[
            Expanded(child: QrImage(
              data: 'datadatadatadatadatadatadatadatadata',
              padding: EdgeInsets.zero,
            )),
            Expanded(child: QrImage(
              data: 'datadatadatadatadatadatadatadatadata',
              padding: EdgeInsets.all(5),
            )),
            Expanded(child: QrImage(
              data: 'datadatadatadatadatadatadatadatadata',
              padding: EdgeInsets.all(10),
            )),
            Expanded(child: QrImage(
              data: 'datadatadatadatadatadatadatadatadata',
              padding: EdgeInsets.all(15),
            )),
          ],
        ),
      ),
    );
  }
}

image
image

The 2nd qrCode and the 3rd one has different padding but share the 'same' size. I understand that they have different widget size and QrImage resized the image to the same. But this makes it impossible for me to get a qrCode with a size I wanted, it's always resized to some certain size. I think the image should always fit the size of the widget.

What's more, with zero padding, the qrCode overflows the boudary.
In my app this code caused overflow

Container(
  width: 80,
  child: QrImage(
    data: 'datadatadatadatadatadatadatadatadata',
    padding: EdgeInsets.zero,
  ),
),

image

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.1, on Microsoft Windows [Version 10.0.18362.959], locale zh-CN)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[!] Android Studio (version 3.2)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2017.3)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code, 64-bit edition (version 1.41.0)
[√] Connected device (1 available

qr_flutter: ^3.0.1

@hhkkyy hhkkyy added the bug Something isn't working label Jul 29, 2020
@hhkkyy
Copy link
Author

hhkkyy commented Jul 30, 2020

I changed the following code in qr_painter.dart line 389 and the bug seems solved

  void _calculateMetrics() {
    final gapTotal = (moduleCount - 1) * gapSize;
    var pixelSize = (containerSize - gapTotal) / moduleCount;
    // _pixelSize = (pixelSize * 2).roundToDouble() / 2;
    _pixelSize = pixelSize;
    _innerContentSize = (_pixelSize * moduleCount) + gapTotal;
    _inset = (containerSize - _innerContentSize) / 2;
  }

Seems roundToDouble caused this, it makes every single square has an int size W and for the entire image it causes the image size only allowed in certain sizes that is n times of W. Hope this will help.

@Yann39
Copy link

Yann39 commented Aug 13, 2020

I am also facing this bug and I can confirm the change suggested fixes the problem.

@tristansb1
Copy link

Yep, facing this bug here also.

@andyxiaoxi
Copy link

me too

@ximi66
Copy link

ximi66 commented Jul 13, 2021

Is this bug still unresolved?

vanlooverenkoen added a commit to vanlooverenkoen/qr.flutter that referenced this issue Aug 3, 2021
@vanlooverenkoen
Copy link

I used the sollution of @hhkkyy and created a pull request #144

@vanlooverenkoen
Copy link

Use this for now

  qr_flutter:
    git:
      url: https://github.com/vanlooverenkoen/qr.flutter
      ref: bugfix/#104-padding-fix

@lukef
Copy link
Collaborator

lukef commented Mar 4, 2022

Fixed in 5.0.0.

@lukef lukef closed this as completed Mar 4, 2022
@lukef lukef added this to the 5.0.0 milestone Mar 4, 2022
@lukef lukef added the fixed Fixed and will be included in next release label Mar 4, 2022
@CaiWanFeng
Copy link

CaiWanFeng commented Aug 30, 2022

@lukef It's still qr_flutter 4.0.0 long time gone and when publish 5.0.0?

@vanlooverenkoen
Copy link

It seems that 5.0.0 is 91% done. Only 1 web ticket. You can find the progress here for 5.0.0 (https://github.com/theyakka/qr.flutter/milestone/3) @lukef do you have a timeline when we can expect this version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Fixed and will be included in next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants