Skip to content

Commit

Permalink
Merge pull request #91 from SriramKiranSenthilkumar/master
Browse files Browse the repository at this point in the history
committed the release source
  • Loading branch information
JayavigneshwaranG authored Dec 17, 2020
2 parents 680e350 + a70be65 commit 3b77b4c
Show file tree
Hide file tree
Showing 550 changed files with 100,931 additions and 33,795 deletions.
38 changes: 19 additions & 19 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/syncfusion_flutter_barcodes/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ void main() {
return runApp(MyApp());
}

/// Creates the barcode generator
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand Down
46 changes: 19 additions & 27 deletions packages/syncfusion_flutter_barcodes/lib/barcodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,23 @@
/// * [Knowledge base](https://www.syncfusion.com/kb/flutter)
library barcodes;

import 'dart:convert' show utf8;
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:syncfusion_flutter_core/theme.dart';

// export barcode library
part './src/barcode_generator/base/barcode_generator.dart';
part './src/barcode_generator/base/symbology_base.dart';
part './src/barcode_generator/one_dimensional/codabar_symbology.dart';
part './src/barcode_generator/one_dimensional/code39_symbology.dart';
part './src/barcode_generator/one_dimensional/code39_extended_symbology.dart';
part './src/barcode_generator/one_dimensional/code93_symbology.dart';
part './src/barcode_generator/one_dimensional/code128_symbology.dart';
part './src/barcode_generator/one_dimensional/code128a_symbology.dart';
part './src/barcode_generator/one_dimensional/code128b_symbology.dart';
part './src/barcode_generator/one_dimensional/code128c_symbology.dart';
part './src/barcode_generator/one_dimensional/ean8_symbology.dart';
part './src/barcode_generator/one_dimensional/ean13_symbology.dart';
part './src/barcode_generator/one_dimensional/upca_symbology.dart';
part './src/barcode_generator/one_dimensional/upce_symbology.dart';
part './src/barcode_generator/utils/helper.dart';
part './src/barcode_generator/utils/enum.dart';
part './src/barcode_generator/common/barcode_renderer.dart';
part './src/barcode_generator/two_dimensional/error_correction_codewords.dart';
part './src/barcode_generator/two_dimensional/qr_code_symbology.dart';
part './src/barcode_generator/two_dimensional/qr_code_values.dart';
part './src/barcode_generator/two_dimensional/datamatrix_symbology.dart';
export './src/barcode_generator/base/barcode_generator.dart';
export './src/barcode_generator/base/symbology_base.dart';
export './src/barcode_generator/one_dimensional/codabar_symbology.dart';
export './src/barcode_generator/one_dimensional/code128_symbology.dart';
export './src/barcode_generator/one_dimensional/code128a_symbology.dart';
export './src/barcode_generator/one_dimensional/code128b_symbology.dart';
export './src/barcode_generator/one_dimensional/code128c_symbology.dart';

export './src/barcode_generator/one_dimensional/code39_extended_symbology.dart';
export './src/barcode_generator/one_dimensional/code39_symbology.dart';
export './src/barcode_generator/one_dimensional/code93_symbology.dart';

export './src/barcode_generator/one_dimensional/ean13_symbology.dart';
export './src/barcode_generator/one_dimensional/ean8_symbology.dart';
export './src/barcode_generator/one_dimensional/upca_symbology.dart';
export './src/barcode_generator/one_dimensional/upce_symbology.dart';
export './src/barcode_generator/two_dimensional/datamatrix_symbology.dart';
export './src/barcode_generator/two_dimensional/qr_code_symbology.dart';
export './src/barcode_generator/utils/enum.dart';
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
part of barcodes;
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:syncfusion_flutter_core/theme.dart';
import '../common/barcode_renderer.dart';
import '../one_dimensional/codabar_symbology.dart';
import '../one_dimensional/code128_symbology.dart';
import '../one_dimensional/code128a_symbology.dart';
import '../one_dimensional/code128b_symbology.dart';
import '../one_dimensional/code128c_symbology.dart';

import '../one_dimensional/code39_extended_symbology.dart';
import '../one_dimensional/code39_symbology.dart';
import '../one_dimensional/code93_symbology.dart';

import '../one_dimensional/ean13_symbology.dart';
import '../one_dimensional/ean8_symbology.dart';
import '../one_dimensional/upca_symbology.dart';
import '../one_dimensional/upce_symbology.dart';

import '../renderers/one_dimensional/codabar_renderer.dart';

import '../renderers/one_dimensional/code128A_renderer.dart';
import '../renderers/one_dimensional/code128B_renderer.dart';
import '../renderers/one_dimensional/code128C_renderer.dart';
import '../renderers/one_dimensional/code128_renderer.dart';
import '../renderers/one_dimensional/code39_extended_renderer.dart';
import '../renderers/one_dimensional/code39_renderer.dart';
import '../renderers/one_dimensional/code93_renderer.dart';
import '../renderers/one_dimensional/ean13_renderer.dart';
import '../renderers/one_dimensional/ean8_renderer.dart';
import '../renderers/one_dimensional/symbology_base_renderer.dart';
import '../renderers/one_dimensional/upca_renderer.dart';
import '../renderers/one_dimensional/upce_renderer.dart';
import '../renderers/two_dimensional/datamatrix_renderer.dart';
import '../renderers/two_dimensional/qr_code_renderer.dart';
import '../two_dimensional/datamatrix_symbology.dart';
import '../two_dimensional/qr_code_symbology.dart';

import '../utils/helper.dart';
import 'symbology_base.dart';

/// Create barcode to generate and display data in a machine-readable
/// industry-standard 1D and 2D barcodes.
Expand Down Expand Up @@ -226,6 +266,8 @@ class _SfBarcodeGeneratorState extends State<SfBarcodeGenerator> {
/// Specifies the text size
Size _textSize;

SymbologyRenderer _symbologyRenderer;

@override
void didChangeDependencies() {
_barcodeTheme = SfBarcodeTheme.of(context);
Expand All @@ -237,22 +279,64 @@ class _SfBarcodeGeneratorState extends State<SfBarcodeGenerator> {
if (widget.showValue &&
(oldWidget.value != widget.value ||
oldWidget.textStyle != widget.textStyle)) {
_textSize = _measureText(widget.value.toString(), widget.textStyle);
_textSize = measureText(widget.value.toString(), widget.textStyle);
}

if (widget.symbology != oldWidget.symbology) {
_createSymbologyRenderer();
}

super.didUpdateWidget(oldWidget);
}

@override
void initState() {
_createSymbologyRenderer();
super.initState();
}

void _createSymbologyRenderer() {
if (widget.symbology is Codabar) {
_symbologyRenderer = CodabarRenderer(symbology: widget.symbology);
} else if (widget.symbology is Code39Extended) {
_symbologyRenderer = Code39ExtendedRenderer(symbology: widget.symbology);
} else if (widget.symbology is Code39) {
_symbologyRenderer = Code39Renderer(symbology: widget.symbology);
} else if (widget.symbology is Code93) {
_symbologyRenderer = Code93Renderer(symbology: widget.symbology);
} else if (widget.symbology is Code128) {
_symbologyRenderer = Code128Renderer(symbology: widget.symbology);
} else if (widget.symbology is Code128A) {
_symbologyRenderer = Code128ARenderer(symbology: widget.symbology);
} else if (widget.symbology is Code128B) {
_symbologyRenderer = Code128BRenderer(symbology: widget.symbology);
} else if (widget.symbology is Code128C) {
_symbologyRenderer = Code128CRenderer(symbology: widget.symbology);
} else if (widget.symbology is EAN8) {
_symbologyRenderer = EAN8Renderer(symbology: widget.symbology);
} else if (widget.symbology is EAN13) {
_symbologyRenderer = EAN13Renderer(symbology: widget.symbology);
} else if (widget.symbology is UPCA) {
_symbologyRenderer = UPCARenderer(symbology: widget.symbology);
} else if (widget.symbology is UPCE) {
_symbologyRenderer = UPCERenderer(symbology: widget.symbology);
} else if (widget.symbology is QRCode) {
_symbologyRenderer = QRCodeRenderer(symbology: widget.symbology);
} else if (widget.symbology is DataMatrix) {
_symbologyRenderer = DataMatrixRenderer(symbology: widget.symbology);
}
}

@override
Widget build(BuildContext context) {
if (widget.showValue && _textSize == null) {
_textSize = _measureText(widget.value.toString(), widget.textStyle);
_textSize = measureText(widget.value.toString(), widget.textStyle);
}
widget.symbology._getIsValidateInput(widget.value);
widget.symbology._textSize = _textSize;
_symbologyRenderer.getIsValidateInput(widget.value);
_symbologyRenderer.textSize = _textSize;
return Container(
color: widget.backgroundColor ?? _barcodeTheme.backgroundColor,
child: _SfBarcodeGeneratorRenderObjectWidget(
child: SfBarcodeGeneratorRenderObjectWidget(
value: widget.value,
symbology: widget.symbology,
foregroundColor: widget.barColor ?? _barcodeTheme.barColor,
Expand All @@ -266,6 +350,7 @@ class _SfBarcodeGeneratorState extends State<SfBarcodeGenerator> {
fontStyle: widget.textStyle.fontStyle,
fontWeight: widget.textStyle.fontWeight,
textBaseline: widget.textStyle.textBaseline),
symbologyRenderer: _symbologyRenderer,
textSize: _textSize,
textAlign: widget.textAlign),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
part of barcodes;

/// Define the barcode symbology that will be used to encode the input value
/// to the visual barcode representation.
///
Expand Down Expand Up @@ -47,118 +45,4 @@ abstract class Symbology {
///}
/// ```dart
final int module;

/// Specifies the value with start and the stop symbol
String _valueWithStartAndStopSymbol;

/// Specifies the text size
Size _textSize;

/// Method to valid whether the provided input character is supported
/// by corresponding symbology
bool _getIsValidateInput(String value);

/// Method to render the barcode value
void _renderBarcode(
Canvas canvas,
Size size,
Offset offset,
String value,
Color foregroundColor,
TextStyle textStyle,
double textSpacing,
TextAlign textAlign,
bool showValue);

/// Renders the paint for the bar code
Paint _getBarPaint(Color foregroundColor) {
return Paint()
..color = foregroundColor
..strokeWidth = 1
..style = PaintingStyle.fill;
}

/// Calculates the left value of the initial bar code
double _getLeftPosition(
int barWidth, int module, double width, double offsetX) {
final int calculatedWidth = barWidth * module;
// Calculates the left position of the barcode based on the provided
// module value
double diffInWidth = (width - calculatedWidth) / 2;
diffInWidth += offsetX;
return diffInWidth;
}

/// Method to render the input value of the barcode
void _drawText(Canvas canvas, Offset offset, Size size, String value,
TextStyle textStyle, double textSpacing, TextAlign textAlign,
[Offset actualOffset, Size actualSize]) {
final TextSpan span = TextSpan(text: value, style: textStyle);
final TextPainter textPainter = TextPainter(
text: span, textDirection: TextDirection.ltr, textAlign: textAlign);
textPainter.layout();
double x;
double y;
if ((this is UPCA || this is EAN13 || this is UPCE) && value.length == 1) {
x = offset.dx;
y = offset.dy;
} else {
switch (textAlign) {
case TextAlign.justify:
case TextAlign.center:
{
x = (offset.dx + size.width / 2) - textPainter.width / 2;
y = offset.dy + size.height + textSpacing;
}
break;
case TextAlign.left:
case TextAlign.start:
{
x = offset.dx;
y = offset.dy + size.height + textSpacing;
}
break;
case TextAlign.right:
case TextAlign.end:
{
x = offset.dx + (size.width - textPainter.width);
y = offset.dy + size.height + textSpacing;
}
break;
}
}

if (this is UPCE || this is UPCA || this is EAN8 || this is EAN13) {
// Checks whether the calculated x value is present inside the control
// size
if (x >= actualOffset.dx &&
x + textPainter.width <= actualOffset.dx + actualSize.width) {
textPainter.paint(canvas, Offset(x, y));
}
} else {
textPainter.paint(canvas, Offset(x, y));
}
}

/// Calculates whether the corresponding type has extra height barcode
bool _getHasExtraHeight(int currentItemIndex, List<String> code) {
if (((currentItemIndex == 0 || currentItemIndex == code.length - 1) &&
(this is Code39 || this is Code39Extended)) ||
((this is EAN8 || this is EAN13) &&
(currentItemIndex == 0 ||
currentItemIndex == 2 ||
currentItemIndex == code.length - 1)) ||
this is UPCA &&
(currentItemIndex == 1 ||
currentItemIndex == code.length - 2 ||
currentItemIndex == code.length - 4) ||
this is UPCE &&
(currentItemIndex == 1 ||
currentItemIndex == code.length - 2 ||
currentItemIndex == code.length - 4)) {
return true;
} else {
return false;
}
}
}
Loading

0 comments on commit 3b77b4c

Please sign in to comment.