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

Barcode is rendered outside the canvas #13

Closed
bruceanwyl opened this issue Oct 4, 2019 · 3 comments
Closed

Barcode is rendered outside the canvas #13

bruceanwyl opened this issue Oct 4, 2019 · 3 comments

Comments

@bruceanwyl
Copy link

@sooxiaotong FittedBox does not help with this. I've attached a screenshot to show that the barcode width is larger than the width computed by the package. And I am also generationg barcode for code128. I know the _calcCanvasWIdth() should be modified but I would have to invest some time to figure out how to do it.

Anyway, I was hoping the author would provide some direct help. Thanks.

screenshot

Originally posted by @kaciula in #1 (comment)

@bruceanwyl
Copy link
Author

bruceanwyl commented Oct 4, 2019

The root cause is that the width calculation of the canvas does not account for the padding built into this component. You can see in the image above (and below) that the overflow is exactly the amount of displacement caused by the left padding. The right padding appears as if it was ignored.

This issue is most apparent in Code39, Code93, Code128 and can be seen in the Code39 barcode below. This was obtained by changing the BarcodeImage to have a background color as shown in the following snippet:

                    child: new BarCodeImage(
                      backgroundColor: Colors.red,
                      data: element.codeStr,
                      codeType: element.type,
                      lineWidth: 2.0,
                      barHeight: 100.0,
                      hasText: element.hasText,
                      onError: (error) {
                        print("Generate barcode failed. error msg: $error");
                      },
                    ),

padding_overflow

Now, we could change the calculation to include padding but if you look carefully at the image above, the single line width gaps between the barcode characters are not painted and there is a trailing gap that we cannot see. It would be better to remove padding as a feature and change the painting of the white bars so that they are the color of the background. Of course, the most common background color is going to be white.

Note also that the Code128 barcode shown by @kaciula does not have gaps like the Code39 barcode but if you look carefully at the image, you can see the background color leaking through in very fine lines.

If padding is required around the barcode, just wrap it in a Padding object in your UI.

bruceanwyl added a commit to bruceanwyl/barcode.flutter that referenced this issue Oct 5, 2019
Barcode not centered bigship#1
foregroundColor doesn't work bigship#3
Barcode is rendered outside the canvas bigship#13
Code93 barcode has extra bars on the end bigship#14
@v0l
Copy link
Contributor

v0l commented Oct 10, 2019

fixed in #19

bigship added a commit that referenced this issue Oct 26, 2019
Version 1.1.0  Add ITF Support, fix issue #1 #9 #13
@bigship
Copy link
Owner

bigship commented Oct 26, 2019

Please check the new API, it should be fixed now.

@bigship bigship closed this as completed Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants