diff --git a/flutter_pretty_qr/.gitignore b/flutter_pretty_qr/.gitignore deleted file mode 100644 index 5d4c566..0000000 --- a/flutter_pretty_qr/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -*.iml -*.ipr -*.iws -.idea/ -.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ -.dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies -.packages -.pub-cache/ -.pub/ -/build/ -/coverage/ -.fvm/ - -./pubspec.lock diff --git a/flutter_pretty_qr/LICENSE b/flutter_pretty_qr/LICENSE deleted file mode 100644 index a4a8fa7..0000000 --- a/flutter_pretty_qr/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 Oleg Lobkov - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/flutter_pretty_qr/analysis_options.yaml b/flutter_pretty_qr/analysis_options.yaml deleted file mode 100644 index d34253c..0000000 --- a/flutter_pretty_qr/analysis_options.yaml +++ /dev/null @@ -1,37 +0,0 @@ -include: package:flutter_lints/flutter.yaml - -dart_code_metrics: - extends: - - package:dart_code_metrics_presets/all.yaml - - package:dart_code_metrics_presets/pub.yaml - rules: - # style - arguments-ordering: false - enum-constants-ordering: false - format-comment: - only-doc-comments: true - member-ordering: false - newline-before-return: false - parameters-ordering: false - prefer-widget-private-members: false - prefer-correct-identifier-length: - exceptions: ['i', 'x', 'y'] - min-identifier-length: 3 - max-identifier-length: 27 - prefer-returning-conditional-expressions: false - unnecessary-trailing-comma: false - - # warning - avoid-non-null-assertion: false - avoid-passing-default-values: false - no-equal-arguments: false - no-magic-number: false - prefer-match-file-name: false - prefer-commenting-analyzer-ignores: false - avoid-late-keyword: false - - - pubspec-rules: - prefer-caret-version-syntax: false - prefer-publish-to-none: false - diff --git a/flutter_pretty_qr/lib/pretty_qr_code.dart b/flutter_pretty_qr/lib/pretty_qr_code.dart deleted file mode 100644 index 3753376..0000000 --- a/flutter_pretty_qr/lib/pretty_qr_code.dart +++ /dev/null @@ -1,24 +0,0 @@ -/// Flutter widgets that make it easy to rendering QR code. -library pretty_qr_code; - -export 'package:qr/qr.dart'; -export 'src/widgets/pretty_qr.dart'; -export 'src/widgets/pretty_qr_view.dart'; - -export 'src/base/pretty_qr_matrix.dart'; -export 'src/base/pretty_qr_module.dart'; -export 'src/base/pretty_qr_neighbour_direction.dart'; - -export 'src/painting/pretty_qr_shape.dart'; -export 'src/painting/pretty_qr_decoration.dart'; -export 'src/painting/pretty_qr_decoration_image.dart'; - -export 'src/painting/shapes/pretty_qr_smooth_symbol.dart'; -export 'src/painting/shapes/pretty_qr_rounded_symbol.dart'; - -export 'src/painting/animation/pretty_qr_decoration_tween.dart'; - -export 'src/painting/extensions/pretty_qr_image_extension.dart'; -export 'src/painting/extensions/pretty_qr_module_extensions.dart'; -export 'src/painting/extensions/pretty_qr_neighbour_direction_extensions.dart'; -export 'src/painting/pretty_qr_impeller.dart'; diff --git a/flutter_pretty_qr/lib/src/base/pretty_qr_matrix.dart b/flutter_pretty_qr/lib/src/base/pretty_qr_matrix.dart deleted file mode 100644 index 8002ee9..0000000 --- a/flutter_pretty_qr/lib/src/base/pretty_qr_matrix.dart +++ /dev/null @@ -1,97 +0,0 @@ -import 'dart:math'; - -import 'package:qr/qr.dart'; -import 'package:meta/meta.dart'; - -import 'package:pretty_qr_code/src/base/pretty_qr_module.dart'; -import 'package:pretty_qr_code/src/base/pretty_qr_neighbour_direction.dart'; - -/// {@template pretty_qr_code.PrettyQrMatrix} -/// The QR code matrix consisting of an array of nominally square modules. -/// {@endtemplate} -@sealed -class PrettyQrMatrix extends Iterable { - /// The size (side length) of the matrix. - @nonVirtual - final int dimension; - - /// The array of QR code modules. - @visibleForTesting - final List modules; - - /// Each Position Detection Pattern may be viewed as three superimposed - /// concentric squares and is constructed of dark `7x7` modules, light `5x5` - /// modules and dark `3x3` modules. - static const kFinderPatternDimension = 7; - - /// Creates a QR matrix. - @literal - const PrettyQrMatrix({ - required this.modules, - required this.dimension, - }); - - /// Creates a qr matrix from [QrImage]. - factory PrettyQrMatrix.fromQrImage( - final QrImage qrImage, - ) { - return PrettyQrMatrix( - modules: List.generate( - qrImage.moduleCount * qrImage.moduleCount, - (index) { - final col = index % qrImage.moduleCount; - final row = index ~/ qrImage.moduleCount; - return PrettyQrModule(col, row, isDark: qrImage.isDark(row, col)); - }, - growable: false, - ), - dimension: qrImage.moduleCount, - ); - } - - /// Returns the value of the module at position [x], [y] or `null` if the - /// coordinate is outside the matrix. - @useResult - PrettyQrModule? getModule(int x, int y) { - if (y < 0 || y >= dimension) return null; - if (x < 0 || x >= dimension) return null; - - // ignore: avoid-unsafe-collection-methods - return modules[y * dimension + x]; - } - - /// Set `isDark` equals to `false` fot the module at position [x], [y]. - @nonVirtual - void removeDarkAt(int x, int y) { - final module = getModule(x, y); - modules[y * dimension + x] = module!.copyWith(isDark: false); - } - - /// Returns the directions to the nearest neighbours of the [point]. - @nonVirtual - Set getNeighboursDirections( - final Point point, - ) { - return { - for (final value in PrettyQrNeighbourDirection.values) - if (getModule(point.x + value.x, point.y + value.y)?.isDark ?? false) - value, - }; - } - - /// Returns `true` if the point is part of one of three Finder Pattern - /// components. - @nonVirtual - bool isFinderPatternPoint(Point point) { - const pSide = kFinderPatternDimension; - if (point.x < pSide && point.y < pSide) return true; - if (point.x < pSide && point.y >= dimension - pSide) return true; - if (point.x >= dimension - pSide && point.y < pSide) return true; - return false; - } - - @override - Iterator get iterator { - return modules.iterator; - } -} diff --git a/flutter_pretty_qr/lib/src/base/pretty_qr_module.dart b/flutter_pretty_qr/lib/src/base/pretty_qr_module.dart deleted file mode 100644 index fff2514..0000000 --- a/flutter_pretty_qr/lib/src/base/pretty_qr_module.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'dart:math'; - -import 'package:meta/meta.dart'; - -/// {@template pretty_qr_code.PrettyQrModule} -/// The QR code module. -/// {@endtemplate} -@sealed -@immutable -class PrettyQrModule extends Point { - /// Returns `true` if the point is dark. - @nonVirtual - final bool isDark; - - /// Creates a QR module. - @literal - const PrettyQrModule( - super.x, - super.y, { - required this.isDark, - }); - - /// Creates a copy of this [PrettyQrModule] but with the given fields replaced - /// with the new values. - @factory - @useResult - PrettyQrModule copyWith({ - final bool? isDark, - }) { - return PrettyQrModule(x, y, isDark: isDark ?? this.isDark); - } - - @override - int get hashCode { - return runtimeType.hashCode ^ super.hashCode ^ isDark.hashCode; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - if (other.runtimeType != runtimeType) return false; - - return other is PrettyQrModule && super == other && other.isDark == isDark; - } -} diff --git a/flutter_pretty_qr/lib/src/base/pretty_qr_neighbour_direction.dart b/flutter_pretty_qr/lib/src/base/pretty_qr_neighbour_direction.dart deleted file mode 100644 index 95ab2a2..0000000 --- a/flutter_pretty_qr/lib/src/base/pretty_qr_neighbour_direction.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:meta/meta.dart'; - -/// {@template pretty_qr_code.PrettyQrNeighbourDirection} -/// The direction in which there is a closest point. -/// {@endtemplate} -enum PrettyQrNeighbourDirection { - /// The top left corner. - topLeft(-1, -1), - - /// The point along the top edge. - top(0, -1), - - /// The top right corner. - topRight(1, -1), - - /// The point along the left edge. - left(-1, 0), - - /// The point along the right edge. - right(1, 0), - - /// The bottom left corner. - bottomLeft(-1, 1), - - /// The point along the bottom edge. - bottom(0, 1), - - /// The bottom right corner. - bottomRight(1, 1); - - /// The distance fraction in the horizontal direction. - @nonVirtual - final int x; - - /// The distance fraction in the vertical direction. - @nonVirtual - final int y; - - /// {@macro pretty_qr_code.PrettyQrNeighbourDirection} - @literal - const PrettyQrNeighbourDirection(this.x, this.y); -} diff --git a/flutter_pretty_qr/lib/src/painting/animation/pretty_qr_decoration_tween.dart b/flutter_pretty_qr/lib/src/painting/animation/pretty_qr_decoration_tween.dart deleted file mode 100644 index 807cb8e..0000000 --- a/flutter_pretty_qr/lib/src/painting/animation/pretty_qr_decoration_tween.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:flutter/animation.dart'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; - -/// An interpolation between two [PrettyQrDecoration]s. -/// -/// This class specializes the interpolation of [Tween] to -/// use [PrettyQrDecoration.lerp]. -class PrettyQrDecorationTween extends Tween { - /// Creates a QR decoration tween. - PrettyQrDecorationTween({super.begin, super.end}); - - /// Returns the value this variable has at the given animation clock value. - @override - PrettyQrDecoration lerp(double t) { - return PrettyQrDecoration.lerp(begin, end, t)!; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_image_extension.dart b/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_image_extension.dart deleted file mode 100644 index 165d94d..0000000 --- a/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_image_extension.dart +++ /dev/null @@ -1,92 +0,0 @@ -import 'dart:async'; -import 'dart:ui' as ui; -import 'dart:typed_data'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; -import 'package:qr/qr.dart'; -import 'package:flutter/rendering.dart'; - -import 'package:pretty_qr_code/src/base/pretty_qr_matrix.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_painter.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; - -/// Extensions that apply to QR Image. -extension PrettyQrImageExtension on QrImage { - /// Returns the QR Code image. - /// NOTE: Does not work with nested images on the Web - /// until the stable Flutter 3.7.0 version (https://github.com/flutter/flutter/issues/103803). - Future toImage({ - required final int size, - final PrettyQrDecoration decoration = const PrettyQrDecoration(), - final ImageConfiguration configuration = ImageConfiguration.empty, - }) { - final imageSize = Size.square(size.toDouble()); - final imageCompleter = Completer(); - final pictureRecorder = ui.PictureRecorder(); - final imageConfiguration = configuration.copyWith(size: imageSize); - - final context = PrettyQrPaintingContext( - Canvas(pictureRecorder), - Offset.zero & imageSize, - matrix: PrettyQrMatrix.fromQrImage(this), - textDirection: configuration.textDirection, - ); - - late PrettyQrPainter decorationPainter; - try { - decorationPainter = decoration.createPainter(() { - decorationPainter.paint(context, imageConfiguration); - final picture = pictureRecorder.endRecording(); - imageCompleter.complete(picture.toImage(size, size)); - }); - decorationPainter.paint(context, imageConfiguration); - - final decorationImageStream = decoration.image?.image.resolve( - configuration, - ); - - if (decorationImageStream == null) { - final picture = pictureRecorder.endRecording(); - imageCompleter.complete(picture.toImage(size, size)); - } else { - late ImageStreamListener imageStreamListener; - imageStreamListener = ImageStreamListener( - (imageInfo, synchronous) { - decorationImageStream.removeListener(imageStreamListener); - imageInfo.dispose(); - if (synchronous) { - final picture = pictureRecorder.endRecording(); - imageCompleter.complete(picture.toImage(size, size)); - } - }, - onError: (error, stackTrace) { - decorationImageStream.removeListener(imageStreamListener); - imageCompleter.completeError(error, stackTrace); - }, - ); - decorationImageStream.addListener(imageStreamListener); - } - } catch (error, stackTrace) { - imageCompleter.completeError(error, stackTrace); - } - - return imageCompleter.future.whenComplete(() { - decorationPainter.dispose(); - }); - } - - /// Returns the QR Code image as a list of bytes. - Future toImageAsBytes({ - required final int size, - final ui.ImageByteFormat format = ui.ImageByteFormat.png, - final PrettyQrDecoration decoration = const PrettyQrDecoration(), - final ImageConfiguration configuration = ImageConfiguration.empty, - }) async { - final image = await toImage( - size: size, - decoration: decoration, - configuration: configuration, - ); - return image.toByteData(format: format); - } -} diff --git a/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_module_extensions.dart b/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_module_extensions.dart deleted file mode 100644 index 0618b0f..0000000 --- a/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_module_extensions.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter/painting.dart'; - -import 'package:pretty_qr_code/src/base/pretty_qr_module.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; - -/// Extensions that apply to QR symbol. -extension PrettyQrModuleExtension on PrettyQrModule { - /// Convert this instance into a floating-point rectangle whose coordinates - /// are relative to a given QR module. - Rect resolveRect(PrettyQrPaintingContext context) { - final canvasSize = context.estimatedBounds.longestSide; - final pointSize = canvasSize / context.matrix.dimension; - return Rect.fromLTWH(pointSize * x, pointSize * y, pointSize, pointSize); - } -} diff --git a/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_neighbour_direction_extensions.dart b/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_neighbour_direction_extensions.dart deleted file mode 100644 index 31fc0c4..0000000 --- a/flutter_pretty_qr/lib/src/painting/extensions/pretty_qr_neighbour_direction_extensions.dart +++ /dev/null @@ -1,56 +0,0 @@ -import 'package:pretty_qr_code/src/base/pretty_qr_neighbour_direction.dart'; - -/// Extensions that apply to [Set]. -extension PrettyQrNeighbourDirectionSetExt on Set { - /// Returns `true` if the set containts `top` or `left` direction. - bool get atTopOrLeft => atTop || atLeft; - - /// Returns `true` if the set containts `top` or `right` direction. - bool get atTopOrRight => atTop || atRight; - - /// Returns `true` if the set containts `bottom` or `left` direction. - bool get atBottomOrLeft => atBottom || atLeft; - - /// Returns `true` if the set containts `bottom` or `right` direction. - bool get atBottomOrRight => atBottom || atRight; - - /// Returns `true` if the set containts `top` and `left` direction. - bool get atTopAndLeft => atTop && atLeft; - - /// Returns `true` if the set containts `top` and `right` direction. - bool get atTopAndRight => atTop && atRight; - - /// Returns `true` if the set containts `bottom` and `left` direction. - bool get atBottomAndLeft => atBottom && atLeft; - - /// Returns `true` if the set containts `bottom` and `right` direction. - bool get atBottomAndRight => atBottom && atRight; - - /// Returns `true` if the set containts `top`, `left`, `right` or `bottom` - /// direction. - bool get hasClosest => atTop || atLeft || atRight || atBottom; - - /// Returns `true` if the set containts `topLeft` direction. - bool get atToptLeft => contains(PrettyQrNeighbourDirection.topLeft); - - /// Returns `true` if the set containts `top` direction. - bool get atTop => contains(PrettyQrNeighbourDirection.top); - - /// Returns `true` if the set containts `topRight` direction. - bool get atToptRight => contains(PrettyQrNeighbourDirection.topRight); - - /// Returns `true` if the set containts `left` direction. - bool get atLeft => contains(PrettyQrNeighbourDirection.left); - - /// Returns `true` if the set containts `right` direction. - bool get atRight => contains(PrettyQrNeighbourDirection.right); - - /// Returns `true` if the set containts `bottomLeft` direction. - bool get atBottomLeft => contains(PrettyQrNeighbourDirection.bottomLeft); - - /// Returns `true` if the set containts `bottom` direction. - bool get atBottom => contains(PrettyQrNeighbourDirection.bottom); - - /// Returns `true` if the set containts `bottomRight` direction. - bool get atBottomRight => contains(PrettyQrNeighbourDirection.bottomRight); -} diff --git a/flutter_pretty_qr/lib/src/painting/pretty_qr_decoration.dart b/flutter_pretty_qr/lib/src/painting/pretty_qr_decoration.dart deleted file mode 100644 index c45890e..0000000 --- a/flutter_pretty_qr/lib/src/painting/pretty_qr_decoration.dart +++ /dev/null @@ -1,112 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:flutter/foundation.dart'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_shape.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_painter.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration_image.dart'; -import 'package:pretty_qr_code/src/painting/shapes/pretty_qr_smooth_symbol.dart'; - -/// {@template pretty_qr_code.PrettyQrDecoration} -/// An immutable description of how to paint a QR image. -/// {@endtemplate} -@immutable -class PrettyQrDecoration with Diagnosticable { - /// The QR modules shape. - @nonVirtual - final PrettyQrShape shape; - - /// The image will be embed to the center of the QR code. - @nonVirtual - final PrettyQrDecorationImage? image; - - /// Creates a QR image decoration. - @literal - const PrettyQrDecoration({ - this.image, - this.shape = const PrettyQrSmoothSymbol(), - }); - - @override - String toStringShort() { - return objectRuntimeType(this, 'PrettyQrDecoration'); - } - - /// Creates a copy of this [PrettyQrDecoration] but with the given fields - /// replaced with the new values. - @factory - @useResult - PrettyQrDecoration copyWith({ - final PrettyQrShape? shape, - final PrettyQrDecorationImage? image, - }) { - return PrettyQrDecoration( - image: image ?? this.image, - shape: shape ?? this.shape, - ); - } - - /// Returns a [PrettyQrPainter] that will paint QR code with this decoration. - @nonVirtual - PrettyQrPainter createPainter(VoidCallback onChanged) { - return PrettyQrPainter(decoration: this, onChanged: onChanged); - } - - /// Linearly interpolates between two [PrettyQrDecoration]s. - /// - /// {@macro dart.ui.shadow.lerp} - @factory - static PrettyQrDecoration? lerp( - final PrettyQrDecoration? a, - final PrettyQrDecoration? b, - final double t, - ) { - if (identical(a, b)) { - return a; - } - - if (a != null && b != null) { - if (t == 0.0) return a; - if (t == 1.0) return b; - } - - return PrettyQrDecoration( - shape: PrettyQrShape.lerp(a?.shape, b?.shape, t)!, - image: PrettyQrDecorationImage.lerp(a?.image, b?.image, t), - ); - } - - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); - properties - ..add( - DiagnosticsProperty( - 'shape', - shape, - defaultValue: const PrettyQrSmoothSymbol(), - ), - ) - ..add( - DiagnosticsProperty( - 'image', - image, - defaultValue: null, - ), - ); - } - - @override - int get hashCode { - return runtimeType.hashCode ^ Object.hash(image, shape); - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - if (other.runtimeType != runtimeType) return false; - - return other is PrettyQrDecoration && - other.image == image && - other.shape == shape; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/pretty_qr_decoration_image.dart b/flutter_pretty_qr/lib/src/painting/pretty_qr_decoration_image.dart deleted file mode 100644 index 8d186af..0000000 --- a/flutter_pretty_qr/lib/src/painting/pretty_qr_decoration_image.dart +++ /dev/null @@ -1,118 +0,0 @@ -import 'dart:ui'; - -import 'package:meta/meta.dart'; -import 'package:flutter/painting.dart'; - -/// {@template pretty_qr_code.PrettyQrDecorationImagePosition} -/// Where to paint a image decoration. -/// {@endtemplate} -enum PrettyQrDecorationImagePosition { - /// Paint the image decoration inside the QR code. - embedded, - - /// Paint the image decoration behind the QR code. - background, - - /// Paint the image decoration in front of the QR code. - foreground, -} - -/// An image for a QR decoration. -@immutable -class PrettyQrDecorationImage extends DecorationImage { - /// The padding for the QR image. - @nonVirtual - final EdgeInsetsGeometry padding; - - /// {@macro pretty_qr_code.PrettyQrDecorationImagePosition} - final PrettyQrDecorationImagePosition position; - - /// Creates an image to show into QR code. - /// - /// Not recommended to use scale over `0.2`, see the - /// [qr code error correction feature](https://www.qrcode.com/en/about/error_correction.html). - @literal - const PrettyQrDecorationImage({ - required super.image, - super.scale = 0.2, - this.padding = EdgeInsets.zero, - this.position = PrettyQrDecorationImagePosition.embedded, - }) : assert(scale >= 0 && scale <= 1); - - /// Creates a copy of this [PrettyQrDecorationImage] but with the given fields - /// replaced with the new values. - @factory - @useResult - PrettyQrDecorationImage copyWith({ - final double? scale, - final ImageProvider? image, - final EdgeInsetsGeometry? padding, - final PrettyQrDecorationImagePosition? position, - }) { - return PrettyQrDecorationImage( - scale: scale ?? this.scale, - image: image ?? this.image, - padding: padding ?? this.padding, - position: position ?? this.position, - ); - } - - /// Linearly interpolates between two [PrettyQrDecorationImage]s. - /// - /// {@macro dart.ui.shadow.lerp} - static PrettyQrDecorationImage? lerp( - final PrettyQrDecorationImage? a, - final PrettyQrDecorationImage? b, - final double t, - ) { - if (identical(a, b)) { - return a; - } - - if (a != null && b != null) { - if (t == 0.0) return a; - if (t == 1.0) return b; - } - - if (a == null) { - return PrettyQrDecorationImage( - image: b!.image, - scale: b.scale * t, - position: b.position, - padding: EdgeInsetsGeometry.lerp(null, b.padding, t)!, - ); - } - - if (b == null) { - return PrettyQrDecorationImage( - image: a.image, - scale: a.scale * (1.0 - t), - position: a.position, - padding: EdgeInsetsGeometry.lerp(a.padding, null, t)!, - ); - } - - return PrettyQrDecorationImage( - image: t < 0.5 ? a.image : b.image, - scale: lerpDouble(a.scale, b.scale, t)!, - position: t < 0.5 ? a.position : b.position, - padding: EdgeInsetsGeometry.lerp(a.padding, b.padding, t)!, - ); - } - - @override - int get hashCode { - return runtimeType.hashCode ^ super.hashCode ^ padding.hashCode; - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - if (other.runtimeType != runtimeType) return false; - - return other is PrettyQrDecorationImage && - super == other && - other.padding == padding && - other.position == position; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/pretty_qr_impeller.dart b/flutter_pretty_qr/lib/src/painting/pretty_qr_impeller.dart deleted file mode 100644 index 090c1b0..0000000 --- a/flutter_pretty_qr/lib/src/painting/pretty_qr_impeller.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'dart:io'; - -import 'package:meta/meta.dart'; -import 'package:flutter/foundation.dart'; - -/// {@template pretty_qr_code.painting.PrettyQrImpeller} -/// For more information, see impleller -/// [issue (#126212)](https://github.com/flutter/flutter/issues/126212). -/// {@endtemplate} -@sealed -abstract class PrettyQrImpeller { - /// The default behavior is result of call [isImpellerDefaultEngine]. - /// You can set this to your own value to override this default behavior. - // ignore: avoid-global-state - static bool? enabled; - - /// Attempts to indirectly detect whether the `Impeller` rendering engine is - /// enabled or not. - @internal - static bool get isImpellerDefaultEngine { - if (kIsWeb) return false; - return Platform.version.startsWith('3.') && Platform.isIOS; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/pretty_qr_painter.dart b/flutter_pretty_qr/lib/src/painting/pretty_qr_painter.dart deleted file mode 100644 index e20d151..0000000 --- a/flutter_pretty_qr/lib/src/painting/pretty_qr_painter.dart +++ /dev/null @@ -1,90 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:flutter/painting.dart'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration_image.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; -import 'package:pretty_qr_code/src/painting/extensions/pretty_qr_module_extensions.dart'; - -/// A stateful class that can paint a QR code. -/// -/// To obtain a painter, call [PrettyQrDecoration.createPainter]. -@internal -class PrettyQrPainter { - /// Callback that is invoked if an asynchronously-loading resource used by the - /// decoration finishes loading. For example, an image. When this is invoked, - /// the [paint] method should be called again. - @nonVirtual - final VoidCallback onChanged; - - /// What decoration to paint. - @nonVirtual - final PrettyQrDecoration decoration; - - /// The painter for a [PrettyQrDecorationImage]. - @protected - DecorationImagePainter? _decorationImagePainter; - - /// Creates a QR code painter. - PrettyQrPainter({ - required this.onChanged, - required this.decoration, - }); - - /// Draw the QR code image onto the given canvas. - @nonVirtual - void paint( - final PrettyQrPaintingContext context, - final ImageConfiguration configuration, - ) { - final image = decoration.image; - - if (image != null) { - final size = context.estimatedBounds.size; - final imageScale = image.scale.clamp(0.0, 1.0); - final imageScaledRect = Rect.fromCenter( - center: size.center(Offset.zero), - width: size.width * imageScale, - height: size.height * imageScale, - ); - - // clear space for the embedded image - if (image.position == PrettyQrDecorationImagePosition.embedded) { - for (final module in context.matrix) { - final moduleRect = module.resolveRect(context); - if (imageScaledRect.overlaps(moduleRect)) { - context.matrix.removeDarkAt(module.x, module.y); - } - } - } - - if (image.position == PrettyQrDecorationImagePosition.foreground) { - decoration.shape.paint(context); - } - - final imagePadding = (image.padding * imageScale).resolve( - configuration.textDirection, - ); - final imageCroppedRect = imagePadding.deflateRect(imageScaledRect); - - _decorationImagePainter ??= image.createPainter(onChanged); - _decorationImagePainter?.paint( - context.canvas, - imageCroppedRect, - null, - configuration.copyWith(size: imageCroppedRect.size), - ); - } - - if (image?.position != PrettyQrDecorationImagePosition.foreground) { - decoration.shape.paint(context); - } - } - - /// Discard any resources being held by the object. - @mustCallSuper - void dispose() { - _decorationImagePainter?.dispose(); - _decorationImagePainter = null; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/pretty_qr_shape.dart b/flutter_pretty_qr/lib/src/painting/pretty_qr_shape.dart deleted file mode 100644 index 2ba0129..0000000 --- a/flutter_pretty_qr/lib/src/painting/pretty_qr_shape.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:meta/meta.dart'; - -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; - -/// {@template pretty_qr_code.PrettyQrShape} -/// Base class for shape QR modules. -/// {@endtemplate} -@immutable -abstract class PrettyQrShape { - /// Abstract const constructor. This constructor enables subclasses to provide - /// const constructors so that they can be used in const expressions. - @literal - const PrettyQrShape(); - - /// Linearly interpolates from another [PrettyQrShape] (which may be of a - /// different class) to `this`. - /// - /// Instead of calling this directly, use [PrettyQrShape.lerp]. - PrettyQrShape? lerpFrom(PrettyQrShape? a, double t) => null; - - /// Linearly interpolates from `this` to another [PrettyQrShape] (which may be - /// of a different class). - /// - /// Instead of calling this directly, use [PrettyQrShape.lerp]. - PrettyQrShape? lerpTo(PrettyQrShape? b, double t) => null; - - /// Paints the QR matrix on the canvas of the given painting context. - void paint(PrettyQrPaintingContext context); - - /// Linearly interpolates between two [PrettyQrShape]s. - /// - /// This attempts to use [lerpFrom] and [lerpTo] on `b` and `a` - /// respectively to find a solution. - /// - /// {@macro dart.ui.shadow.lerp} - static PrettyQrShape? lerp( - final PrettyQrShape? a, - final PrettyQrShape? b, - final double t, - ) { - if (identical(a, b)) { - return a; - } - - if (a == null) return b!.lerpFrom(null, t) ?? b; - if (b == null) return a.lerpTo(null, t) ?? a; - - if (t == 0.0) return a; - if (t == 1.0) return b; - - return b.lerpFrom(a, t) ?? a.lerpTo(b, t) ?? b; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/shapes/pretty_qr_rounded_symbol.dart b/flutter_pretty_qr/lib/src/painting/shapes/pretty_qr_rounded_symbol.dart deleted file mode 100644 index 80362ea..0000000 --- a/flutter_pretty_qr/lib/src/painting/shapes/pretty_qr_rounded_symbol.dart +++ /dev/null @@ -1,108 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:flutter/painting.dart'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_shape.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; -import 'package:pretty_qr_code/src/painting/extensions/pretty_qr_module_extensions.dart'; - -/// A rectangular symbol with rounded corners. -@sealed -class PrettyQrRoundedSymbol extends PrettyQrShape { - /// The color of QR Code symbol. - @nonVirtual - final Color color; - - /// If non-null, the corners of QR modules are rounded by this [BorderRadius]. - @nonVirtual - final BorderRadiusGeometry borderRadius; - - /// The default value for [borderRadius]. - static const kDefaultBorderRadius = BorderRadius.all( - Radius.circular(8), - ); - - /// Creates a basic QR shape. - @literal - const PrettyQrRoundedSymbol({ - this.color = const Color(0xFF000000), - this.borderRadius = kDefaultBorderRadius, - }); - - @override - void paint(PrettyQrPaintingContext context) { - final path = Path(); - final paint = Paint() - ..color = color - ..isAntiAlias = true - ..style = PaintingStyle.fill; - - final radius = borderRadius.resolve(context.textDirection); - - for (final module in context.matrix) { - if (!module.isDark) continue; - - final modulePath = Path(); - final moduleRect = module.resolveRect(context); - modulePath.addRRect(radius.toRRect(moduleRect)); - - if (context.isImpellerEngineEnabled) { - context.canvas.drawPath(modulePath, paint); - } else { - path.addPath(modulePath, Offset.zero); - } - } - - context.canvas.drawPath(path, paint); - } - - @override - PrettyQrRoundedSymbol? lerpFrom(PrettyQrShape? a, double t) { - if (identical(a, this)) { - return this; - } - - if (a == null) return this; - if (a is! PrettyQrRoundedSymbol) return null; - - if (t == 0.0) return a; - if (t == 1.0) return this; - - return PrettyQrRoundedSymbol( - color: Color.lerp(a.color, color, t)!, - borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!, - ); - } - - @override - PrettyQrRoundedSymbol? lerpTo(PrettyQrShape? b, double t) { - if (identical(this, b)) { - return this; - } - - if (b == null) return this; - if (b is! PrettyQrRoundedSymbol) return null; - - if (t == 0.0) return this; - if (t == 1.0) return b; - - return PrettyQrRoundedSymbol( - color: Color.lerp(color, b.color, t)!, - borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!, - ); - } - - @override - int get hashCode { - return runtimeType.hashCode ^ Object.hash(color, borderRadius); - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - if (other.runtimeType != runtimeType) return false; - - return other is PrettyQrRoundedSymbol && - other.color == color && - other.borderRadius == borderRadius; - } -} diff --git a/flutter_pretty_qr/lib/src/painting/shapes/pretty_qr_smooth_symbol.dart b/flutter_pretty_qr/lib/src/painting/shapes/pretty_qr_smooth_symbol.dart deleted file mode 100644 index 03bb8c4..0000000 --- a/flutter_pretty_qr/lib/src/painting/shapes/pretty_qr_smooth_symbol.dart +++ /dev/null @@ -1,200 +0,0 @@ -import 'dart:ui'; - -import 'package:meta/meta.dart'; -import 'package:flutter/painting.dart'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_shape.dart'; -import 'package:pretty_qr_code/src/base/pretty_qr_neighbour_direction.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; -import 'package:pretty_qr_code/src/painting/extensions/pretty_qr_module_extensions.dart'; -import 'package:pretty_qr_code/src/painting/extensions/pretty_qr_neighbour_direction_extensions.dart'; - -/// A rectangular symbol with smoothed flow. -@sealed -class PrettyQrSmoothSymbol extends PrettyQrShape { - /// The color of QR symbol. - @nonVirtual - final Color color; - - /// The corners of dots are rounded by this [BorderRadiusGeometry] value. - @nonVirtual - final double roundFactor; - - /// Creates a pretty QR shape. - @literal - const PrettyQrSmoothSymbol({ - this.roundFactor = 1, - this.color = const Color(0xFF000000), - }) : assert(roundFactor <= 1, 'roundFactor must be less than 1'), - assert(roundFactor >= 0, 'roundFactor must be greater than 0'); - - @override - void paint(PrettyQrPaintingContext context) { - final path = Path(); - final paint = Paint() - ..color = color - ..isAntiAlias = true - ..style = PaintingStyle.fill; - - for (final module in context.matrix) { - final moduleRect = module.resolveRect(context); - final moduleNeighbours = context.matrix.getNeighboursDirections(module); - Path modulePath; - - if (module.isDark) { - modulePath = Path(); - modulePath.addRRect( - transformDarkModuleRect(moduleRect, moduleNeighbours), - ); - } else { - modulePath = transformWhiteModuleRect(moduleRect, moduleNeighbours); - } - - if (context.isImpellerEngineEnabled) { - context.canvas.drawPath(modulePath, paint); - } else { - path.addPath(modulePath, Offset.zero); - } - } - - context.canvas.drawPath(path, paint); - } - - @protected - RRect transformDarkModuleRect( - final Rect moduleRect, - final Set neighbours, - ) { - final cornersRadius = Radius.circular( - moduleRect.shortestSide / 2 * roundFactor.clamp(0.0, 1.0), - ); - - if (!neighbours.hasClosest) { - return RRect.fromRectAndRadius(moduleRect, cornersRadius / 2); - } - - return RRect.fromRectAndCorners( - moduleRect, - topLeft: neighbours.atTopOrLeft ? Radius.zero : cornersRadius, - topRight: neighbours.atTopOrRight ? Radius.zero : cornersRadius, - bottomLeft: neighbours.atBottomOrLeft ? Radius.zero : cornersRadius, - bottomRight: neighbours.atBottomOrRight ? Radius.zero : cornersRadius, - ); - } - - @protected - Path transformWhiteModuleRect( - final Rect moduleRect, - final Set neighbours, - ) { - final path = Path(); - final padding = (roundFactor / 2).clamp(0.0, 0.5) * moduleRect.longestSide; - - if (neighbours.atTopAndLeft && neighbours.atToptLeft) { - path.addPath( - buildInnerCornerShape( - moduleRect.topLeft.translate(0, padding), - moduleRect.topLeft, - moduleRect.topLeft.translate(padding, 0), - ), - Offset.zero, - ); - } - - if (neighbours.atTopAndRight && neighbours.atToptRight) { - path.addPath( - buildInnerCornerShape( - moduleRect.topRight.translate(-padding, 0), - moduleRect.topRight, - moduleRect.topRight.translate(0, padding), - ), - Offset.zero, - ); - } - - if (neighbours.atBottomAndLeft && neighbours.atBottomLeft) { - path.addPath( - buildInnerCornerShape( - moduleRect.bottomLeft.translate(0, -padding), - moduleRect.bottomLeft, - moduleRect.bottomLeft.translate(padding, 0), - ), - Offset.zero, - ); - } - - if (neighbours.atBottomAndRight && neighbours.atBottomRight) { - path.addPath( - buildInnerCornerShape( - moduleRect.bottomRight.translate(-padding, 0), - moduleRect.bottomRight, - moduleRect.bottomRight.translate(0, -padding), - ), - Offset.zero, - ); - } - - return path; - } - - @protected - Path buildInnerCornerShape(Offset p1, Offset p2, Offset p3) { - return Path() - ..moveTo(p1.dx, p1.dy) - ..quadraticBezierTo(p2.dx, p2.dy, p3.dx, p3.dy) - ..lineTo(p2.dx, p2.dy) - ..lineTo(p1.dx, p1.dy) - ..close(); - } - - @override - PrettyQrSmoothSymbol? lerpFrom(PrettyQrShape? a, double t) { - if (identical(a, this)) { - return this; - } - - if (a == null) return this; - if (a is! PrettyQrSmoothSymbol) return null; - - if (t == 0.0) return a; - if (t == 1.0) return this; - - return PrettyQrSmoothSymbol( - color: Color.lerp(a.color, color, t)!, - roundFactor: lerpDouble(a.roundFactor, roundFactor, t)!, - ); - } - - @override - PrettyQrSmoothSymbol? lerpTo(PrettyQrShape? b, double t) { - if (identical(this, b)) { - return this; - } - - if (b == null) return this; - if (b is! PrettyQrSmoothSymbol) return null; - - if (t == 0.0) return this; - if (t == 1.0) return b; - - return PrettyQrSmoothSymbol( - color: Color.lerp(color, b.color, t)!, - roundFactor: lerpDouble(roundFactor, b.roundFactor, t)!, - ); - } - - @override - int get hashCode { - return runtimeType.hashCode ^ Object.hash(color, roundFactor); - } - - @override - bool operator ==(Object other) { - if (identical(other, this)) return true; - if (other.runtimeType != runtimeType) return false; - - return other is PrettyQrSmoothSymbol && - other.color == color && - other.roundFactor == roundFactor; - } -} diff --git a/flutter_pretty_qr/lib/src/rendering/pretty_qr_painting_context.dart b/flutter_pretty_qr/lib/src/rendering/pretty_qr_painting_context.dart deleted file mode 100644 index 136b271..0000000 --- a/flutter_pretty_qr/lib/src/rendering/pretty_qr_painting_context.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:meta/meta.dart'; -import 'package:flutter/rendering.dart'; - -import 'package:pretty_qr_code/src/base/pretty_qr_matrix.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_impeller.dart'; - -/// {@template pretty_qr_code.PrettyQrPaintingContext} -/// A place to paint QR. -/// {@endtemplate} -@sealed -class PrettyQrPaintingContext { - /// The canvas on which to paint. - @nonVirtual - final Canvas canvas; - - /// The bounds within which the painting context's [canvas] will record - /// painting commands. - final Rect estimatedBounds; - - /// {@macro pretty_qr_code.PrettyQrMatrix} - @nonVirtual - final PrettyQrMatrix matrix; - - /// The reading direction of the language. - @nonVirtual - final TextDirection? textDirection; - - /// Creates a QR painting context. - @literal - const PrettyQrPaintingContext( - this.canvas, - this.estimatedBounds, { - required this.matrix, - this.textDirection, - }); - - /// {@macro pretty_qr_code.painting.PrettyQrImpeller} - @nonVirtual - bool get isImpellerEngineEnabled { - return PrettyQrImpeller.enabled ?? PrettyQrImpeller.isImpellerDefaultEngine; - } -} diff --git a/flutter_pretty_qr/lib/src/rendering/pretty_qr_render_view.dart b/flutter_pretty_qr/lib/src/rendering/pretty_qr_render_view.dart deleted file mode 100644 index 30a3d88..0000000 --- a/flutter_pretty_qr/lib/src/rendering/pretty_qr_render_view.dart +++ /dev/null @@ -1,159 +0,0 @@ -import 'dart:math' as math; - -import 'package:qr/qr.dart'; -import 'package:meta/meta.dart'; -import 'package:flutter/rendering.dart'; - -import 'package:pretty_qr_code/src/base/pretty_qr_matrix.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_painter.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_painting_context.dart'; - -/// {@template pretty_qr_code.PrettyQrRenderView} -/// An QR code image in the render tree. -/// {@endtemplate} -@internal -class PrettyQrRenderView extends RenderBox { - /// {@template pretty_qr_code.PrettyQrRenderView.qrImage} - /// The QR to display. - /// {@endtemplate} - @nonVirtual - late QrImage _qrImage; - - /// {@template pretty_qr_code.PrettyQrRenderView.decoration} - /// What decoration to paint. - /// {@endtemplate} - @nonVirtual - late PrettyQrDecoration _decoration; - - /// {@template pretty_qr_code.PrettyQrRenderView.configuration} - /// The settings to pass to the decoration when painting, so that it can - /// resolve images appropriately. See [ImageProvider.resolve]. - /// {@endtemplate} - @nonVirtual - late ImageConfiguration _configuration; - - /// The painter for a [PrettyQrPainter]. - @protected - PrettyQrPainter? _decorationPainter; - - /// Creates a QR view. - PrettyQrRenderView({ - required QrImage qrImage, - required PrettyQrDecoration decoration, - final ImageConfiguration configuration = ImageConfiguration.empty, - }) : _qrImage = qrImage, - _decoration = decoration, - _configuration = configuration; - - /// {@macro pretty_qr_code.PrettyQrRenderView.qrImage} - QrImage get qrImage { - return _qrImage; - } - - /// Sets the qr image. - set qrImage(QrImage value) { - if (_qrImage == value) return; - - _qrImage = value; - markNeedsPaint(); - } - - /// {@macro pretty_qr_code.PrettyQrRenderView.decoration} - PrettyQrDecoration get decoration { - return _decoration; - } - - /// Sets the current decoration. - set decoration(PrettyQrDecoration value) { - if (_decoration == value) return; - - _decorationPainter?.dispose(); - _decorationPainter = null; - - _decoration = value; - markNeedsPaint(); - } - - /// {@macro pretty_qr_code.PrettyQrRenderView.configuration} - ImageConfiguration get configuration { - return _configuration; - } - - /// Sets the image configuration. - set configuration(ImageConfiguration value) { - if (value == _configuration) return; - - _configuration = value; - markNeedsPaint(); - } - - @override - bool hitTestSelf(Offset position) { - return true; - } - - @override - void performLayout() { - size = _sizeForConstraints(constraints); - } - - @override - Size computeDryLayout(BoxConstraints constraints) { - return _sizeForConstraints(constraints); - } - - /// Find a size for the QR image within the given constraints. - @protected - Size _sizeForConstraints(BoxConstraints constraints) { - final minDimension = math.min(constraints.maxWidth, constraints.maxHeight); - return constraints.constrain(Size.square(minDimension)); - } - - @override - void paint(PaintingContext context, Offset offset) { - context.canvas.save(); - if (offset != Offset.zero) { - context.canvas.translate(offset.dx, offset.dy); - } - - try { - final size = Size.square( - configuration.size?.shortestSide ?? this.size.shortestSide, - ); - - final paintingContext = PrettyQrPaintingContext( - context.canvas, - Offset.zero & size, - matrix: PrettyQrMatrix.fromQrImage(qrImage), - textDirection: configuration.textDirection, - ); - - _decorationPainter ??= decoration.createPainter(markNeedsPaint); - _decorationPainter?.paint(paintingContext, configuration); - } finally { - context.canvas.restore(); - } - } - - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); - properties - ..add( - DiagnosticsProperty( - 'configuration', - configuration, - ), - ) - ..add(DiagnosticsProperty('qrImage', qrImage)) - ..add(decoration.toDiagnosticsNode(name: 'decoration')); - } - - @override - void dispose() { - _decorationPainter?.dispose(); - - super.dispose(); - } -} diff --git a/flutter_pretty_qr/lib/src/widgets/pretty_qr.dart b/flutter_pretty_qr/lib/src/widgets/pretty_qr.dart deleted file mode 100644 index 9e1c139..0000000 --- a/flutter_pretty_qr/lib/src/widgets/pretty_qr.dart +++ /dev/null @@ -1,127 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'package:pretty_qr_code/src/widgets/pretty_qr_view.dart'; -import 'package:qr/qr.dart'; -import 'package:meta/meta.dart'; -import 'package:flutter/widgets.dart'; - -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration_image.dart'; -import 'package:pretty_qr_code/src/painting/shapes/pretty_qr_smooth_symbol.dart'; - -/// {@macro pretty_qr_code.PrettyQrView} -@Deprecated('Use `PrettyQrView.data` instead') -class PrettyQr extends StatefulWidget { - /// Widget size. - @nonVirtual - final double size; - - /// Qr code data. - @nonVirtual - final String data; - - /// Square color. - @nonVirtual - final Color elementColor; - - /// Error correct level. - @nonVirtual - final int errorCorrectLevel; - - /// Round the corners. - @nonVirtual - final bool roundEdges; - - /// Number of type generation (1 to 40 or null for auto). - @nonVirtual - final int? typeNumber; - - /// The image to be painted into QR code. - @nonVirtual - final ImageProvider? image; - - @literal - @Deprecated('Use `PrettyQrView.data` instead') - const PrettyQr({ - required this.data, - super.key, - this.image, - this.typeNumber, - this.size = 100, - this.roundEdges = false, - this.elementColor = const Color(0xFF000000), - this.errorCorrectLevel = QrErrorCorrectLevel.M, - }); - - @override - State createState() => _PrettyQrState(); -} - -@sealed -class _PrettyQrState extends State { - @protected - late QrImage qrImage; - - @override - void initState() { - super.initState(); - prepareQrImage(); - } - - @override - void didUpdateWidget( - covariant PrettyQr oldWidget, - ) { - super.didUpdateWidget(oldWidget); - - if (oldWidget.data != widget.data) { - prepareQrImage(); - } else if (oldWidget.typeNumber != widget.typeNumber) { - prepareQrImage(); - } else if (oldWidget.errorCorrectLevel != widget.errorCorrectLevel) { - prepareQrImage(); - } - } - - @protected - void prepareQrImage() { - if (widget.typeNumber == null) { - final qrCode = QrCode.fromData( - data: widget.data, - errorCorrectLevel: widget.errorCorrectLevel, - ); - - qrImage = QrImage(qrCode); - } else { - final qrCode = QrCode( - widget.typeNumber!, - widget.errorCorrectLevel, - )..addData(widget.data); - - qrImage = QrImage(qrCode); - } - } - - @override - Widget build(BuildContext context) { - return SizedBox.square( - dimension: widget.size, - child: PrettyQrView( - qrImage: qrImage, - decoration: PrettyQrDecoration( - shape: PrettyQrSmoothSymbol( - color: widget.elementColor, - roundFactor: widget.roundEdges ? 1 : 0, - ), - image: widget.image == null - ? null - : PrettyQrDecorationImage( - image: widget.image!, - scale: 0.25, - position: PrettyQrDecorationImagePosition.embedded, - ), - ), - ), - ); - } -} diff --git a/flutter_pretty_qr/lib/src/widgets/pretty_qr_data_view.dart b/flutter_pretty_qr/lib/src/widgets/pretty_qr_data_view.dart deleted file mode 100644 index 3180ae8..0000000 --- a/flutter_pretty_qr/lib/src/widgets/pretty_qr_data_view.dart +++ /dev/null @@ -1,75 +0,0 @@ -import 'package:qr/qr.dart'; -import 'package:meta/meta.dart'; -import 'package:flutter/widgets.dart'; - -import 'package:pretty_qr_code/src/widgets/pretty_qr_view.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; - -/// {@macro pretty_qr_code.PrettyQrView} -@internal -class PrettyQrDataView extends StatefulWidget { - /// The QR code data. - @protected - final String data; - - /// The QR code error correction level. - @protected - final int errorCorrectLevel; - - /// {@macro pretty_qr_code.PrettyQrRenderView.decoration} - @protected - final PrettyQrDecoration decoration; - - @literal - const PrettyQrDataView({ - required this.data, - super.key, - this.decoration = const PrettyQrDecoration(), - this.errorCorrectLevel = QrErrorCorrectLevel.L, - }) : assert(errorCorrectLevel >= 0 && errorCorrectLevel <= 3); - - @override - State createState() => _PrettyQrDataViewState(); -} - -@sealed -class _PrettyQrDataViewState extends State { - @protected - late QrImage qrImage; - - @override - void initState() { - super.initState(); - prepareQrImage(); - } - - @override - void didUpdateWidget( - covariant PrettyQrDataView oldWidget, - ) { - super.didUpdateWidget(oldWidget); - - if (oldWidget.data != widget.data) { - prepareQrImage(); - } else if (oldWidget.errorCorrectLevel != widget.errorCorrectLevel) { - prepareQrImage(); - } - } - - @protected - void prepareQrImage() { - final qrCode = QrCode.fromData( - data: widget.data, - errorCorrectLevel: widget.errorCorrectLevel, - ); - qrImage = QrImage(qrCode); - } - - @override - Widget build(BuildContext context) { - return PrettyQrView( - qrImage: qrImage, - decoration: widget.decoration, - ); - } -} diff --git a/flutter_pretty_qr/lib/src/widgets/pretty_qr_view.dart b/flutter_pretty_qr/lib/src/widgets/pretty_qr_view.dart deleted file mode 100644 index 647bf98..0000000 --- a/flutter_pretty_qr/lib/src/widgets/pretty_qr_view.dart +++ /dev/null @@ -1,98 +0,0 @@ -import 'package:qr/qr.dart'; -import 'package:meta/meta.dart'; -import 'package:flutter/widgets.dart'; -import 'package:flutter/foundation.dart'; - -import 'package:pretty_qr_code/src/widgets/pretty_qr_data_view.dart'; -import 'package:pretty_qr_code/src/painting/pretty_qr_decoration.dart'; -import 'package:pretty_qr_code/src/rendering/pretty_qr_render_view.dart'; - -/// {@template pretty_qr_code.PrettyQrView} -/// A widget that displays a QR code image. -/// {@endtemplate} -/// -/// {@tool snippet} -/// This sample code shows how to use `PrettyQrView` to display QR code image. -/// -/// ```dart -/// PrettyQrView.data( -/// data: '...', -/// errorCorrectLevel: QrErrorCorrectLevel.H, -/// decoration: const PrettyQrDecoration( -/// shape: PrettyQrSmoothModules(), -/// image: PrettyQrDecorationImage( -/// image: AssetImage('images/flutter.png'), -/// position: PrettyQrDecorationImagePosition.embedded, -/// ), -/// ), -/// ) -/// ``` -/// {@end-tool} -@sealed -class PrettyQrView extends LeafRenderObjectWidget { - /// {@macro pretty_qr_code.PrettyQrRenderView.qrImage} - @protected - final QrImage qrImage; - - /// {@macro pretty_qr_code.PrettyQrRenderView.decoration} - @protected - final PrettyQrDecoration decoration; - - /// Creates a widget that displays an QR image obtained from a [qrImage]. - @literal - const PrettyQrView({ - required this.qrImage, - super.key, - this.decoration = const PrettyQrDecoration(), - }); - - /// Creates a widget that displays an QR image obtained from a [data]. - @factory - static PrettyQrDataView data({ - required final String data, - final Key? key, - final int errorCorrectLevel = QrErrorCorrectLevel.L, - final PrettyQrDecoration decoration = const PrettyQrDecoration(), - }) { - return PrettyQrDataView( - key: key, - data: data, - decoration: decoration, - errorCorrectLevel: errorCorrectLevel, - ); - } - - @override - PrettyQrRenderView createRenderObject(BuildContext context) { - return PrettyQrRenderView( - qrImage: qrImage, - decoration: decoration, - configuration: createLocalImageConfiguration(context), - ); - } - - @override - void updateRenderObject( - final BuildContext context, - final PrettyQrRenderView renderObject, - ) { - // ignore: avoid-mutating-parameters - renderObject - ..qrImage = qrImage - ..decoration = decoration - ..configuration = createLocalImageConfiguration(context); - } - - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); - properties - ..add( - DiagnosticsProperty( - 'decoration', - decoration, - ), - ) - ..add(DiagnosticsProperty('qrImage', qrImage)); - } -} diff --git a/flutter_pretty_qr/pubspec.lock b/flutter_pretty_qr/pubspec.lock deleted file mode 100644 index 173cf5a..0000000 --- a/flutter_pretty_qr/pubspec.lock +++ /dev/null @@ -1,96 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - dart_code_metrics_presets: - dependency: "direct dev" - description: - name: dart_code_metrics_presets - sha256: "0a19eb6842db4c9a913f9472b063d9ad4df8b0fa9e01bb7cf52968d0c441bbd2" - url: "https://pub.dev" - source: hosted - version: "2.5.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_lints: - dependency: "direct dev" - description: - name: flutter_lints - sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 - url: "https://pub.dev" - source: hosted - version: "2.0.3" - lints: - dependency: transitive - description: - name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" - url: "https://pub.dev" - source: hosted - version: "0.5.0" - meta: - dependency: "direct main" - description: - name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e - url: "https://pub.dev" - source: hosted - version: "1.10.0" - qr: - dependency: "direct main" - description: - name: qr - sha256: "64957a3930367bf97cc211a5af99551d630f2f4625e38af10edd6b19131b64b3" - url: "https://pub.dev" - source: hosted - version: "3.0.1" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - web: - dependency: transitive - description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 - url: "https://pub.dev" - source: hosted - version: "0.3.0" -sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" - flutter: ">=3.0.0" diff --git a/flutter_pretty_qr/pubspec.yaml b/flutter_pretty_qr/pubspec.yaml deleted file mode 100644 index 039deab..0000000 --- a/flutter_pretty_qr/pubspec.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: pretty_qr_code -description: Pretty QR code for Flutter. You can round the edges with parameter or use the standard view. - -version: 3.1.0 -homepage: https://github.com/promops/flutter_pretty_qr - -environment: - sdk: '>=2.17.0 <4.0.0' - flutter: ">=3.0.0" - -dependencies: - flutter: - sdk: flutter - - qr: ^3.0.1 - meta: ^1.7.0 - -dev_dependencies: - dart_code_metrics_presets: ^2.5.0 - - # lints - flutter_lints: ^2.0.1 diff --git a/lib/components/qr_dialog.dart b/lib/components/qr_dialog.dart index 66b1787..4ec987c 100644 --- a/lib/components/qr_dialog.dart +++ b/lib/components/qr_dialog.dart @@ -1,28 +1,20 @@ -import 'dart:ui'; - +import 'package:dio/dio.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:pretty_qr_code/pretty_qr_code.dart'; +import 'package:kzlinks/utils/fetcher.dart'; import 'package:share_plus/share_plus.dart'; Future showQRDialog(BuildContext context, String shortCode) async { - final qrCode = QrCode.fromData( - data: "https://kzilla.xyz/$shortCode", - errorCorrectLevel: QrErrorCorrectLevel.H, - ); - - final qrImage = QrImage(qrCode); - const decoration = PrettyQrDecoration( - image: PrettyQrDecorationImage( - image: AssetImage( - 'assets/kz_logo.png', - ), - ), - ); + final kzillaUrl = 'https://kzilla.xyz/$shortCode'; + final imageUrl = + 'https://chart.googleapis.com/chart?cht=qr&chs=500x500&chl=$kzillaUrl'; await showDialog( context: context, builder: (context) { return Dialog( + backgroundColor: Colors.white, + surfaceTintColor: Colors.white, child: Container( width: MediaQuery.of(context).size.width, padding: const EdgeInsets.only( @@ -43,9 +35,49 @@ Future showQRDialog(BuildContext context, String shortCode) async { ), ), const SizedBox(height: 20), - PrettyQrView( - qrImage: qrImage, - decoration: decoration, + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(16), + border: Border.all( + color: Colors.grey.shade300, + width: 2, + ), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(16), + child: Image.network( + imageUrl, + width: MediaQuery.of(context).size.width * 0.8, + fit: BoxFit.contain, + loadingBuilder: (context, child, loadingProgress) { + if (loadingProgress == null) { + return child; + } + return Container( + width: 250, + height: 250, + child: Center( + child: Text( + 'Loading...', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + ), + ); + }, + errorBuilder: (context, error, stackTrace) { + return Container( + width: 250, + height: 250, + child: Center( + child: Text('Error loading image from URL'), + ), + ); + }, + ), + ), ), const SizedBox(height: 20), const SizedBox(width: 10), @@ -55,27 +87,19 @@ Future showQRDialog(BuildContext context, String shortCode) async { child: FilledButton( onPressed: () async { try { - final image = await qrImage.toImageAsBytes( - size: 2000, - decoration: decoration, - format: ImageByteFormat.png, + final response = await dio.get( + imageUrl, + options: Options(responseType: ResponseType.bytes), ); - - if (image == null) { - throw Exception( - 'Failed to save QR Code!', - ); - } - await Share.shareXFiles( [ XFile.fromData( - image.buffer.asUint8List(), - name: 'qr_code.png', - mimeType: 'image/png', + response.data as Uint8List, + name: 'qr_code_$shortCode.jpeg', + mimeType: 'image/jpeg', ), ], - text: 'https://kzilla.xyz/$shortCode', + text: 'QR Code for $kzillaUrl', ); } catch (e) { debugPrint(e.toString()); diff --git a/pubspec.lock b/pubspec.lock index d95aaac..0dc4206 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -384,21 +384,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.7.3" - pretty_qr_code: - dependency: "direct main" - description: - path: flutter_pretty_qr - relative: true - source: path - version: "3.1.0" - qr: - dependency: transitive - description: - name: qr - sha256: "64957a3930367bf97cc211a5af99551d630f2f4625e38af10edd6b19131b64b3" - url: "https://pub.dev" - source: hosted - version: "3.0.1" share_plus: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 4b34b95..aaa215d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,8 +37,6 @@ dependencies: google_fonts: ^5.1.0 dio: ^5.3.2 flutter_secure_storage: ^9.0.0 - pretty_qr_code: - path: ./flutter_pretty_qr path_provider: ^2.1.1 share_plus: ^7.1.0 jpeg_encode: ^1.0.1