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 not centered #1

Closed
tobiasgubo opened this issue Dec 1, 2018 · 14 comments
Closed

Barcode not centered #1

tobiasgubo opened this issue Dec 1, 2018 · 14 comments

Comments

@tobiasgubo
Copy link

The barcode painter is not centered inside the barcode image as you can see on the image.

screenshot_1543666980

Steps to Reproduce:

BarCodeImage( data: "1234243534557", codeType: BarCodeType.CodeEAN13, lineWidth: 3.0, backgroundColor: Colors.blue, ),

@bigship
Copy link
Owner

bigship commented Dec 10, 2018

You're right, I should wrap the custom painter in a Center widget, that should solve your problem. I'll fix it very soon.

@tobiasgubo
Copy link
Author

awesome, thank you!

@kaciula
Copy link

kaciula commented Sep 3, 2019

@bigship I'm having a similar problem. Any recommendations on how to modify the library code to achieve this? Centering the CustomPaint does not work.

Ideally, the barcode image widget should be the exact width and height of the barcode itself so we can position it on the screen however we want.

@sooxt98
Copy link

sooxt98 commented Sep 6, 2019

@kaciula HI, after hours of stumbling the code myself, I found out that simply remove the default 5.0 padding from BarCodeImage works!

@kaciula
Copy link

kaciula commented Sep 7, 2019

@sooxiaotong Hi. Thanks for the message. However, the removal of the padding does not really solve the problem. As you can see in the OP, the blue background is larger than the 5.0 padding. I believe the issue is with calculating the canvas width where the barcode is being drawn. For some bar code types, it doesn't calculate the right width.

@sooxt98
Copy link

sooxt98 commented Sep 7, 2019

@kaciula maybe you could try FittedBox, and I'm using with code128, the centering works great

@sooxt98
Copy link

sooxt98 commented Sep 7, 2019

@kaciula for your EAN13, try modify to this, and you're good to go~

image

@kaciula
Copy link

kaciula commented Sep 7, 2019

@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

@sooxt98
Copy link

sooxt98 commented Sep 7, 2019

@kaciula I knew why, you haven't disable the padding and set it to 0, the red background wont be visible if you disabled the barcode padding.

@kaciula
Copy link

kaciula commented Sep 7, 2019

@sooxiaotong I don't think you understand. I left the pink padding to show you that the right part of the barcode goes beyond the padded box. You don't see any pink on the right because the barcode is being drawn over. And that's why centering the barcode does not work very well, because it centers the pink box, not the actual barcode (which can be larger to the right)

@sooxt98
Copy link

sooxt98 commented Sep 7, 2019

@sooxiaotong but i tested with diff kind of data and code, it doesn't overflow and center properly when you didn't specific padding. Although the whole painter algorithm is quite a mess and author need to use hard coded value the calculate the width for barcode container width. But my eyes can't tell any difference after i tweaked the code.

@sooxt98
Copy link

sooxt98 commented Sep 7, 2019

IMG_5484

I have tried all looks good!

Code Data
Code128 2zg3
CodeEAN13 1234243534557
CodeEAN8 123123112

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 update to 1.1.0 and check the new API, the issue 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

5 participants