Skip to content

Commit

Permalink
fix: module gap
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmannZ committed Aug 27, 2020
1 parent b2055e6 commit 134ef55
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.1.1] - 27-08-2020.

- Fixed an issue where small lines between modules were visible.

## [1.1.0+1] - 10-08-2020.

- Fixed the licence path in the readme.
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Default

By default the modules in the QR code will have rounded corners with a radius of `4.0`.
By default the modules in the QR code will have rounded corners with a radius of `2.0`.

```dart
import 'package:flutter/material.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rounded_qr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RoundedQR extends StatefulWidget {
this.errorCorrectLevel = QrErrorCorrectLevel.M,
this.quietZone = 4,
this.moduleColor = Colors.black,
this.moduleRadius = 4.0,
this.moduleRadius = 2.0,
this.backgroundColor = Colors.white,
this.backgroundRadius = 8.0,
this.image,
Expand Down
42 changes: 22 additions & 20 deletions lib/src/rounded_qr_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ class RoundedQRPainter extends CustomPainter {
}

var pixelSize = size.width / (_qrCode.moduleCount + 2 * quietZone);
var gapFill = pixelSize / 40;

for (var x = 0; x < _qrCode.moduleCount; x++) {
for (var y = 0; y < _qrCode.moduleCount; y++) {
if (matrix[y + 1][x + 1]) {
final squareRect = Rect.fromLTWH(
(x + quietZone) * pixelSize,
(y + quietZone) * pixelSize,
pixelSize,
pixelSize,
((x + quietZone) * pixelSize) - gapFill,
((y + quietZone) * pixelSize) - gapFill,
pixelSize + (2 * gapFill),
pixelSize + (2 * gapFill),
);

_setShape(
Expand Down Expand Up @@ -182,7 +183,7 @@ class RoundedQRPainter extends CustomPainter {
// bottom right check
if (matrix[y + 1][x] && matrix[y][x + 1] && matrix[y + 1][x + 1]) {
final p1 = Offset(
heightX + pixelSize - (0.25 * pixelSize),
heightX + pixelSize - (moduleRadius / 6 * pixelSize),
widthY + pixelSize,
);
final p2 = Offset(
Expand All @@ -191,7 +192,7 @@ class RoundedQRPainter extends CustomPainter {
);
final p3 = Offset(
heightX + pixelSize,
widthY + pixelSize - (0.25 * pixelSize),
widthY + pixelSize - (moduleRadius / 6 * pixelSize),
);

_drawCurve(
Expand All @@ -207,14 +208,14 @@ class RoundedQRPainter extends CustomPainter {
if (matrix[y - 1][x] && matrix[y][x - 1] && matrix[y - 1][x - 1]) {
final p1 = Offset(
heightX,
widthY + (0.25 * pixelSize),
widthY + (moduleRadius / 6 * pixelSize),
);
final p2 = Offset(
heightX,
widthY,
);
final p3 = Offset(
heightX + (0.25 * pixelSize),
heightX + (moduleRadius / 6 * pixelSize),
widthY,
);

Expand All @@ -231,14 +232,14 @@ class RoundedQRPainter extends CustomPainter {
if (matrix[y + 1][x] && matrix[y][x - 1] && matrix[y + 1][x - 1]) {
final p1 = Offset(
heightX,
widthY + pixelSize - (0.25 * pixelSize),
widthY + pixelSize - (moduleRadius / 6 * pixelSize),
);
final p2 = Offset(
heightX,
widthY + pixelSize,
);
final p3 = Offset(
heightX + (0.25 * pixelSize),
heightX + (moduleRadius / 6 * pixelSize),
widthY + pixelSize,
);

Expand All @@ -254,7 +255,7 @@ class RoundedQRPainter extends CustomPainter {
// top right check
if (matrix[y - 1][x] && matrix[y][x + 1] && matrix[y - 1][x + 1]) {
final p1 = Offset(
heightX + pixelSize - (0.25 * pixelSize),
heightX + pixelSize - (moduleRadius / 6 * pixelSize),
widthY,
);
final p2 = Offset(
Expand All @@ -263,7 +264,7 @@ class RoundedQRPainter extends CustomPainter {
);
final p3 = Offset(
heightX + pixelSize,
widthY + (0.25 * pixelSize),
widthY + (moduleRadius / 6 * pixelSize),
);

_drawCurve(
Expand Down Expand Up @@ -299,10 +300,10 @@ class RoundedQRPainter extends CustomPainter {
canvas.drawRRect(
RRect.fromRectAndCorners(
squareRect,
bottomRight: Radius.circular(moduleRadius / 2),
bottomLeft: Radius.circular(moduleRadius / 2),
topLeft: Radius.circular(moduleRadius / 2),
topRight: Radius.circular(moduleRadius / 2),
bottomRight: Radius.circular(moduleRadius),
bottomLeft: Radius.circular(moduleRadius),
topLeft: Radius.circular(moduleRadius),
topRight: Radius.circular(moduleRadius),
),
paint,
);
Expand Down Expand Up @@ -361,6 +362,7 @@ class RoundedQRPainter extends CustomPainter {

// size of point
final pixelSize = size.width / (_qrCode.moduleCount + 2 * quietZone);
var gapFill = pixelSize / 40;

for (var x = 0; x < _qrCode.moduleCount; x++) {
for (var y = 0; y < _qrCode.moduleCount; y++) {
Expand All @@ -375,10 +377,10 @@ class RoundedQRPainter extends CustomPainter {
if (_qrCode.isDark(y, x)) {
canvas.drawRect(
Rect.fromLTWH(
(x + quietZone) * pixelSize,
(y + quietZone) * pixelSize,
pixelSize,
pixelSize,
((x + quietZone) * pixelSize) - gapFill,
((y + quietZone) * pixelSize) - gapFill,
pixelSize + (2 * gapFill),
pixelSize + (2 * gapFill),
),
_paint,
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: rounded_qr
description: An easy to use package for creating QR codes that can be rounded, and can have an image in the center.
version: 1.1.0+1
version: 1.1.1
homepage: https://github.com/zino-hofmann/rounded-qr-flutter

environment:
Expand Down

0 comments on commit 134ef55

Please sign in to comment.