diff --git a/README.md b/README.md
index 4571bdf10..1b82004d0 100644
--- a/README.md
+++ b/README.md
@@ -30,24 +30,24 @@ Also, you can view the samples code from [this repository](https://github.com/sy
## Packages
-|
Package/Plugin
| Widgets/libraries
| Pub
| Points
| Popularity
|
-|----------------|-------------------|-----|--------|------------|
-| [syncfusion_flutter_charts](./packages/syncfusion_flutter_charts/) | - SfCartesianChart
- SfCircularChart
- SfPyramidChart
- SfFunnelChart
| [](https://pub.dev/packages/syncfusion_flutter_charts) | [](https://pub.dev/packages/syncfusion_flutter_charts/score) | [](https://pub.dev/packages/syncfusion_flutter_charts/score) |
-| [syncfusion_flutter_calendar](./packages/syncfusion_flutter_calendar/) | | [](https://pub.dev/packages/syncfusion_flutter_calendar) | [](https://pub.dev/packages/syncfusion_flutter_calendar/score) | [](https://pub.dev/packages/syncfusion_flutter_calendar/score) |
-| [syncfusion_flutter_datagrid](./packages/syncfusion_flutter_datagrid/) | | [](https://pub.dev/packages/syncfusion_flutter_datagrid) | [](https://pub.dev/packages/syncfusion_flutter_datagrid/score) | [](https://pub.dev/packages/syncfusion_flutter_datagrid/score) |
-| [syncfusion_flutter_pdfviewer](./packages/syncfusion_flutter_pdfviewer/) | | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer) | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer/score) | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer/score) |
-| [syncfusion_flutter_pdf](./packages/syncfusion_flutter_pdf/) | | [](https://pub.dev/packages/syncfusion_flutter_pdf) | [](https://pub.dev/packages/syncfusion_flutter_pdf/score) | [](https://pub.dev/packages/syncfusion_flutter_pdf/score) |
-| [syncfusion_flutter_xlsio](./packages/syncfusion_flutter_xlsio/) | | [](https://pub.dev/packages/syncfusion_flutter_xlsio) | [](https://pub.dev/packages/syncfusion_flutter_xlsio/score) | [](https://pub.dev/packages/syncfusion_flutter_xlsio/score) |
-| [syncfusion_flutter_datepicker](./packages/syncfusion_flutter_datepicker/) | | [](https://pub.dev/packages/syncfusion_flutter_datepicker) | [](https://pub.dev/packages/syncfusion_flutter_datepicker/score) | [](https://pub.dev/packages/syncfusion_flutter_datepicker/score) |
-| [syncfusion_flutter_maps](./packages/syncfusion_flutter_maps/) | | [](https://pub.dev/packages/syncfusion_flutter_maps) | [](https://pub.dev/packages/syncfusion_flutter_maps/score) | [](https://pub.dev/packages/syncfusion_flutter_maps/score) |
-| [syncfusion_flutter_gauges](./packages/syncfusion_flutter_gauges/) | | [](https://pub.dev/packages/syncfusion_flutter_gauges) | [](https://pub.dev/packages/syncfusion_flutter_gauges/score) | [](https://pub.dev/packages/syncfusion_flutter_gauges/score) |
-| [syncfusion_flutter_sliders](./packages/syncfusion_flutter_sliders/) | - SfSlider
- SfRangeSlider
- SfRangeSelector
| [](https://pub.dev/packages/syncfusion_flutter_sliders) | [](https://pub.dev/packages/syncfusion_flutter_sliders/score) | [](https://pub.dev/packages/syncfusion_flutter_sliders/score) |
-| [syncfusion_flutter_signaturepad](./packages/syncfusion_flutter_signaturepad/) | | [](https://pub.dev/packages/syncfusion_flutter_signaturepad) | [](https://pub.dev/packages/syncfusion_flutter_signaturepad/score) | [](https://pub.dev/packages/syncfusion_flutter_signaturepad/score) |
-| [syncfusion_flutter_barcodes](./packages/syncfusion_flutter_barcodes/) | | [](https://pub.dev/packages/syncfusion_flutter_barcodes) | [](https://pub.dev/packages/syncfusion_flutter_barcodes/score) | [](https://pub.dev/packages/syncfusion_flutter_barcodes/score) |
-| [syncfusion_officechart](./packages/syncfusion_officechart/) | | [](https://pub.dev/packages/syncfusion_officechart) | [](https://pub.dev/packages/syncfusion_officechart/score) | [](https://pub.dev/packages/syncfusion_officechart/score) |
-| [syncfusion_officecore](./packages/syncfusion_officecore/) | This package is a dependecy package for `Office chart` library. | [](https://pub.dev/packages/syncfusion_officecore) | [](https://pub.dev/packages/syncfusion_officecore/score) | [](https://pub.dev/packages/syncfusion_officecore/score) |
-| [syncfusion_flutter_core](./packages/syncfusion_flutter_core/) | This package is a dependecy package for all the Syncfusion Flutter widgets and libraries. | [](https://pub.dev/packages/syncfusion_flutter_core) | [](https://pub.dev/packages/syncfusion_flutter_core/score) | [](https://pub.dev/packages/syncfusion_flutter_core/score) |
-| [syncfusion_localizations](./packages/syncfusion_localizations/) | This package contains localized text for 77 cultures for all the applicable Syncfusion Flutter Widgets.| [](https://pub.dev/packages/syncfusion_localizations) | [](https://pub.dev/packages/syncfusion_localizations/score) | [](https://pub.dev/packages/syncfusion_localizations/score) |
+| Package/Plugin | Available widgets/libraries | Pub | Points | Popularity | Likes |
+|----------------|-----------------------------|-----|--------|------------|-------|
+| [syncfusion_flutter_charts](./packages/syncfusion_flutter_charts/) | - SfCartesianChart
- SfCircularChart
- SfPyramidChart
- SfFunnelChart
| [](https://pub.dev/packages/syncfusion_flutter_charts) | [](https://pub.dev/packages/syncfusion_flutter_charts/score) | [](https://pub.dev/packages/syncfusion_flutter_charts/score) | [](https://pub.dev/packages/syncfusion_flutter_charts/score) |
+| [syncfusion_flutter_calendar](./packages/syncfusion_flutter_calendar/) | | [](https://pub.dev/packages/syncfusion_flutter_calendar) | [](https://pub.dev/packages/syncfusion_flutter_calendar/score) | [](https://pub.dev/packages/syncfusion_flutter_calendar/score) | [](https://pub.dev/packages/syncfusion_flutter_calendar/score) |
+| [syncfusion_flutter_datagrid](./packages/syncfusion_flutter_datagrid/) | | [](https://pub.dev/packages/syncfusion_flutter_datagrid) | [](https://pub.dev/packages/syncfusion_flutter_datagrid/score) | [](https://pub.dev/packages/syncfusion_flutter_datagrid/score) | [](https://pub.dev/packages/syncfusion_flutter_datagrid/score) |
+| [syncfusion_flutter_pdfviewer](./packages/syncfusion_flutter_pdfviewer/) | | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer) | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer/score) | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer/score) | [](https://pub.dev/packages/syncfusion_flutter_pdfviewer/score) |
+| [syncfusion_flutter_pdf](./packages/syncfusion_flutter_pdf/) | | [](https://pub.dev/packages/syncfusion_flutter_pdf) | [](https://pub.dev/packages/syncfusion_flutter_pdf/score) | [](https://pub.dev/packages/syncfusion_flutter_pdf/score) | [](https://pub.dev/packages/syncfusion_flutter_pdf/score) |
+| [syncfusion_flutter_xlsio](./packages/syncfusion_flutter_xlsio/) | | [](https://pub.dev/packages/syncfusion_flutter_xlsio) | [](https://pub.dev/packages/syncfusion_flutter_xlsio/score) | [](https://pub.dev/packages/syncfusion_flutter_xlsio/score) | [](https://pub.dev/packages/syncfusion_flutter_xlsio/score) |
+| [syncfusion_flutter_datepicker](./packages/syncfusion_flutter_datepicker/) | | [](https://pub.dev/packages/syncfusion_flutter_datepicker) | [](https://pub.dev/packages/syncfusion_flutter_datepicker/score) | [](https://pub.dev/packages/syncfusion_flutter_datepicker/score) | [](https://pub.dev/packages/syncfusion_flutter_datepicker/score) |
+| [syncfusion_flutter_maps](./packages/syncfusion_flutter_maps/) | | [](https://pub.dev/packages/syncfusion_flutter_maps) | [](https://pub.dev/packages/syncfusion_flutter_maps/score) | [](https://pub.dev/packages/syncfusion_flutter_maps/score) | [](https://pub.dev/packages/syncfusion_flutter_maps/score) |
+| [syncfusion_flutter_gauges](./packages/syncfusion_flutter_gauges/) | | [](https://pub.dev/packages/syncfusion_flutter_gauges) | [](https://pub.dev/packages/syncfusion_flutter_gauges/score) | [](https://pub.dev/packages/syncfusion_flutter_gauges/score) | [](https://pub.dev/packages/syncfusion_flutter_gauges/score) |
+| [syncfusion_flutter_sliders](./packages/syncfusion_flutter_sliders/) | - SfSlider
- SfRangeSlider
- SfRangeSelector
| [](https://pub.dev/packages/syncfusion_flutter_sliders) | [](https://pub.dev/packages/syncfusion_flutter_sliders/score) | [](https://pub.dev/packages/syncfusion_flutter_sliders/score) | [](https://pub.dev/packages/syncfusion_flutter_sliders/score) |
+| [syncfusion_flutter_signaturepad](./packages/syncfusion_flutter_signaturepad/) | | [](https://pub.dev/packages/syncfusion_flutter_signaturepad) | [](https://pub.dev/packages/syncfusion_flutter_signaturepad/score) | [](https://pub.dev/packages/syncfusion_flutter_signaturepad/score) | [](https://pub.dev/packages/syncfusion_flutter_signaturepad/score) |
+| [syncfusion_flutter_barcodes](./packages/syncfusion_flutter_barcodes/) | | [](https://pub.dev/packages/syncfusion_flutter_barcodes) | [](https://pub.dev/packages/syncfusion_flutter_barcodes/score) | [](https://pub.dev/packages/syncfusion_flutter_barcodes/score) | [](https://pub.dev/packages/syncfusion_flutter_barcodes/score) |
+| [syncfusion_officechart](./packages/syncfusion_officechart/) | | [](https://pub.dev/packages/syncfusion_officechart) | [](https://pub.dev/packages/syncfusion_officechart/score) | [](https://pub.dev/packages/syncfusion_officechart/score) | [](https://pub.dev/packages/syncfusion_officechart/score) |
+| [syncfusion_officecore](./packages/syncfusion_officecore/) | This package is a dependecy package for `Office chart` library. | [](https://pub.dev/packages/syncfusion_officecore) | [](https://pub.dev/packages/syncfusion_officecore/score) | [](https://pub.dev/packages/syncfusion_officecore/score) | [](https://pub.dev/packages/syncfusion_officecore/score) |
+| [syncfusion_flutter_core](./packages/syncfusion_flutter_core/) | This package is a dependecy package for all the Syncfusion Flutter widgets and libraries. | [](https://pub.dev/packages/syncfusion_flutter_core) | [](https://pub.dev/packages/syncfusion_flutter_core/score) | [](https://pub.dev/packages/syncfusion_flutter_core/score) | [](https://pub.dev/packages/syncfusion_flutter_core/score) |
+| [syncfusion_localizations](./packages/syncfusion_localizations/) | This package contains localized text for 77 cultures for all the applicable Syncfusion Flutter Widgets.| [](https://pub.dev/packages/syncfusion_localizations) | [](https://pub.dev/packages/syncfusion_localizations/score) | [](https://pub.dev/packages/syncfusion_localizations/score) | [](https://pub.dev/packages/syncfusion_localizations/score) |
## How to use
@@ -141,4 +141,4 @@ Take a look at the following to learn more about Syncfusion Flutter widgets:
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 20,000 customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
-Today we provide 1,000+ controls and frameworks for web ([ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-web-forms-ui-controls), [JavaScript](https://www.syncfusion.com/javascript-ui-controls), [Angular](https://www.syncfusion.com/angular-ui-components), [React](https://www.syncfusion.com/react-ui-components), [Vue](https://www.syncfusion.com/vue-ui-components), and [Blazor](https://www.syncfusion.com/blazor-components), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls), [Flutter](https://www.syncfusion.com/flutter-widgets), [UWP](https://www.syncfusion.com/uwp-ui-controls), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls), [WPF](https://www.syncfusion.com/wpf-ui-controls), and [UWP](https://www.syncfusion.com/uwp-ui-controls)). We provide ready-to deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.
+Today we provide 1,000+ controls and frameworks for web ([ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls), [ASP.NET WebForms](https://www.syncfusion.com/jquery/aspnet-web-forms-ui-controls), [JavaScript](https://www.syncfusion.com/javascript-ui-controls), [Angular](https://www.syncfusion.com/angular-ui-components), [React](https://www.syncfusion.com/react-ui-components), [Vue](https://www.syncfusion.com/vue-ui-components), and [Blazor](https://www.syncfusion.com/blazor-components), mobile ([Xamarin](https://www.syncfusion.com/xamarin-ui-controls), [Flutter](https://www.syncfusion.com/flutter-widgets), [UWP](https://www.syncfusion.com/uwp-ui-controls), and [JavaScript](https://www.syncfusion.com/javascript-ui-controls)), and desktop development ([WinForms](https://www.syncfusion.com/winforms-ui-controls), [WPF](https://www.syncfusion.com/wpf-ui-controls), and [UWP](https://www.syncfusion.com/uwp-ui-controls)). We provide ready-to deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.
\ No newline at end of file
diff --git a/packages/syncfusion_flutter_barcodes/example/lib/main.dart b/packages/syncfusion_flutter_barcodes/example/lib/main.dart
index 836b6a8d6..8d333b1eb 100644
--- a/packages/syncfusion_flutter_barcodes/example/lib/main.dart
+++ b/packages/syncfusion_flutter_barcodes/example/lib/main.dart
@@ -5,6 +5,7 @@ void main() {
return runApp(MyApp());
}
+/// Creates the barcode generator
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
diff --git a/packages/syncfusion_flutter_barcodes/lib/barcodes.dart b/packages/syncfusion_flutter_barcodes/lib/barcodes.dart
index 49275b36f..4da70cc7e 100644
--- a/packages/syncfusion_flutter_barcodes/lib/barcodes.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/barcodes.dart
@@ -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';
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/barcode_generator.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/barcode_generator.dart
index 78c1d0ab3..a25af0cca 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/barcode_generator.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/barcode_generator.dart
@@ -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.
@@ -226,6 +266,8 @@ class _SfBarcodeGeneratorState extends State {
/// Specifies the text size
Size _textSize;
+ SymbologyRenderer _symbologyRenderer;
+
@override
void didChangeDependencies() {
_barcodeTheme = SfBarcodeTheme.of(context);
@@ -237,22 +279,64 @@ class _SfBarcodeGeneratorState extends State {
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,
@@ -266,6 +350,7 @@ class _SfBarcodeGeneratorState extends State {
fontStyle: widget.textStyle.fontStyle,
fontWeight: widget.textStyle.fontWeight,
textBaseline: widget.textStyle.textBaseline),
+ symbologyRenderer: _symbologyRenderer,
textSize: _textSize,
textAlign: widget.textAlign),
);
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/symbology_base.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/symbology_base.dart
index 820f83e66..6f6e91b74 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/symbology_base.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/base/symbology_base.dart
@@ -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.
///
@@ -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 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;
- }
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/common/barcode_renderer.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/common/barcode_renderer.dart
index d4da0c1b9..d5e2e6957 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/common/barcode_renderer.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/common/barcode_renderer.dart
@@ -1,9 +1,13 @@
-part of barcodes;
+import 'dart:ui';
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import '../base/symbology_base.dart';
+import '../renderers/one_dimensional/symbology_base_renderer.dart';
/// Represents the render object widget
-class _SfBarcodeGeneratorRenderObjectWidget extends LeafRenderObjectWidget {
+class SfBarcodeGeneratorRenderObjectWidget extends LeafRenderObjectWidget {
/// Creates the render object widget
- const _SfBarcodeGeneratorRenderObjectWidget(
+ const SfBarcodeGeneratorRenderObjectWidget(
{Key key,
this.value,
this.symbology,
@@ -12,6 +16,7 @@ class _SfBarcodeGeneratorRenderObjectWidget extends LeafRenderObjectWidget {
this.textSpacing,
this.textStyle,
this.textSize,
+ this.symbologyRenderer,
this.textAlign})
: super(key: key);
@@ -40,6 +45,9 @@ class _SfBarcodeGeneratorRenderObjectWidget extends LeafRenderObjectWidget {
/// Specifies the spacing between the text and the barcode.
final TextAlign textAlign;
+ /// Specifies the corresponding renderer class
+ final SymbologyRenderer symbologyRenderer;
+
@override
RenderObject createRenderObject(BuildContext context) {
return _RenderBarcode(
@@ -48,6 +56,7 @@ class _SfBarcodeGeneratorRenderObjectWidget extends LeafRenderObjectWidget {
foregroundColor: foregroundColor,
showText: showText,
textSpacing: textSpacing,
+ symbologyRenderer: symbologyRenderer,
textStyle: textStyle,
textSize: textSize,
textAlign: textAlign);
@@ -58,6 +67,7 @@ class _SfBarcodeGeneratorRenderObjectWidget extends LeafRenderObjectWidget {
renderObject
..value = value
..symbology = symbology
+ ..symbologyRenderer = symbologyRenderer
..foregroundColor = foregroundColor
..showText = showText
..textSpacing = textSpacing
@@ -73,6 +83,7 @@ class _RenderBarcode extends RenderBox {
_RenderBarcode(
{@required String value,
Symbology symbology,
+ SymbologyRenderer symbologyRenderer,
Color foregroundColor,
bool showText,
double textSpacing,
@@ -81,6 +92,7 @@ class _RenderBarcode extends RenderBox {
TextAlign textAlign})
: _value = value,
_symbology = symbology,
+ _symbologyRenderer = symbologyRenderer,
_foregroundColor = foregroundColor,
_showText = showText,
_textSpacing = textSpacing,
@@ -113,6 +125,9 @@ class _RenderBarcode extends RenderBox {
/// Specifies the spacing between the text and the barcode.
TextAlign _textAlign;
+ /// Specifies the symbology renderer corresponding to that symbology
+ SymbologyRenderer _symbologyRenderer;
+
/// Returns the value
String get value => _value;
@@ -137,6 +152,9 @@ class _RenderBarcode extends RenderBox {
/// Returns the text align value
TextAlign get textAlign => _textAlign;
+ /// Returns the text align value
+ SymbologyRenderer get symbologyRenderer => _symbologyRenderer;
+
/// Set the value
set value(String value) {
if (_value != value) {
@@ -201,6 +219,14 @@ class _RenderBarcode extends RenderBox {
}
}
+ /// Sets the symbology renderer value
+ set symbologyRenderer(SymbologyRenderer value) {
+ if (_symbologyRenderer != value) {
+ _symbologyRenderer = value;
+ markNeedsPaint();
+ }
+ }
+
@override
void performLayout() {
const double minHeight = 350;
@@ -219,7 +245,7 @@ class _RenderBarcode extends RenderBox {
@override
void paint(PaintingContext context, Offset offset) {
- symbology._renderBarcode(
+ symbologyRenderer.renderBarcode(
context.canvas,
Size(
size.width,
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/codabar_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/codabar_symbology.dart
index 644ffcfe5..bbf5b53e8 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/codabar_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/codabar_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The [Codabar] is a discrete numeric symbology that can encode 0-9 digits,
/// six symbols, and plus an additional 4 start and stop characters.
@@ -7,136 +7,5 @@ class Codabar extends Symbology {
///
/// The arguments [module] must be non-negative and greater than 0.
///
- Codabar({int module}) : super(module: module) {
- _codeBarMap = {
- '0': '101010011',
- '1': '101011001',
- '2': '101001011',
- '3': '110010101',
- '4': '101101001',
- '5': '110101001',
- '6': '100101011',
- '7': '100101101',
- '8': '100110101',
- '9': '110100101',
- '-': '101001101',
- '\$': '101100101',
- ':': '1101011011',
- '/': '1101101011',
- '.': '1101101101',
- '+': '101100110011',
- 'A': '1011001001',
- 'B': '1001001011',
- 'C': '1010010011',
- 'D': '1010011001'
- };
- }
-
- /// Represents the supported symbol and its byte value
- Map _codeBarMap;
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (!_codeBarMap.containsKey(value[i]) ||
- value[i] == 'A' ||
- value[i] == 'B' ||
- value[i] == 'C' ||
- value[i] == 'D') {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
-
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues(value);
- final int barTotalLength = _getTotalLength(code);
- double left = module == null
- ? offset.dx
- : _getLeftPosition(barTotalLength, module, size.width, offset.dx);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- // Calculates the bar length based on number of individual bar codes
- final int singleModule = (size.width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (size.width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- const bool hasExtraHeight = false;
- final double barHeight = hasExtraHeight
- ? size.height + _textSize.height + textSpacing
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- final bool canDraw = codeValue[j] == '1' ? true : false;
-
- // Draws the barcode when the corresponding bar value is one
- if (canDraw &&
- (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
- left += ratio;
- }
- if (i < code.length - 1) {
- left += ratio;
- }
- }
- if (showValue) {
- _drawText(canvas, offset, size, value, textStyle, textSpacing, textAlign);
- }
- }
-
- /// Calculate total bar length from give input value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final int numberOfDigits = code[i].length;
- count += numberOfDigits;
- }
- count += code.length - 1;
- return count;
- }
-
- /// Method to append the start and the stop symbol
- String _getValueWithStartAndStopSymbol(String value) {
- return 'A' + value + 'A';
- }
-
- /// Returns the encoded value of the provided input value
- List _getCodeValues(String value) {
- _valueWithStartAndStopSymbol = _getValueWithStartAndStopSymbol(value);
- final List codeBarValues =
- List(_valueWithStartAndStopSymbol.length);
- for (int i = 0; i < _valueWithStartAndStopSymbol.length; i++) {
- for (int j = 0; j < _codeBarMap.length; j++) {
- if (_valueWithStartAndStopSymbol[i] ==
- _codeBarMap.entries.elementAt(j).key) {
- codeBarValues[i] = _codeBarMap.entries.elementAt(j).value;
- break;
- }
- }
- }
- return codeBarValues;
- }
+ Codabar({int module}) : super(module: module);
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128_symbology.dart
index 36236d0fc..1a2a4f0b0 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The [Code128] is a highly efficient, high-density linear barcode symbology
/// that allows the encoding of alphanumeric data. It is capable of encoding
@@ -21,679 +21,5 @@ class Code128 extends Symbology {
Code128({int module})
: super(
module: module,
- ) {
- _code128ACharacterSets = [];
-
- _code128ACharacterSets.add(' ');
- _code128ACharacterSets.add('!');
- _code128ACharacterSets.add('"');
- _code128ACharacterSets.add('#');
- _code128ACharacterSets.add('\$');
- _code128ACharacterSets.add('%');
- _code128ACharacterSets.add('&');
- _code128ACharacterSets.add('\'');
- _code128ACharacterSets.add('(');
- _code128ACharacterSets.add(')');
- _code128ACharacterSets.add('*');
- _code128ACharacterSets.add('+');
- _code128ACharacterSets.add(',');
- _code128ACharacterSets.add('-');
- _code128ACharacterSets.add('.');
- _code128ACharacterSets.add('/');
- _code128ACharacterSets.add('0');
- _code128ACharacterSets.add('1');
- _code128ACharacterSets.add('2');
- _code128ACharacterSets.add('3');
- _code128ACharacterSets.add('4');
- _code128ACharacterSets.add('5');
- _code128ACharacterSets.add('6');
- _code128ACharacterSets.add('7');
- _code128ACharacterSets.add('8');
- _code128ACharacterSets.add('9');
- _code128ACharacterSets.add(':');
- _code128ACharacterSets.add(';');
- _code128ACharacterSets.add('<');
- _code128ACharacterSets.add('=');
- _code128ACharacterSets.add('>');
- _code128ACharacterSets.add('?');
- _code128ACharacterSets.add('@');
- _code128ACharacterSets.add('A');
- _code128ACharacterSets.add('B');
- _code128ACharacterSets.add('C');
- _code128ACharacterSets.add('D');
- _code128ACharacterSets.add('E');
- _code128ACharacterSets.add('F');
- _code128ACharacterSets.add('G');
- _code128ACharacterSets.add('H');
- _code128ACharacterSets.add('I');
- _code128ACharacterSets.add('J');
- _code128ACharacterSets.add('K');
- _code128ACharacterSets.add('L');
- _code128ACharacterSets.add('M');
- _code128ACharacterSets.add('N');
- _code128ACharacterSets.add('O');
- _code128ACharacterSets.add('P');
- _code128ACharacterSets.add('Q');
- _code128ACharacterSets.add('R');
- _code128ACharacterSets.add('S');
- _code128ACharacterSets.add('T');
- _code128ACharacterSets.add('U');
- _code128ACharacterSets.add('V');
- _code128ACharacterSets.add('W');
- _code128ACharacterSets.add('X');
- _code128ACharacterSets.add('Y');
- _code128ACharacterSets.add('Z');
- _code128ACharacterSets.add('[');
- _code128ACharacterSets.add('\\');
- _code128ACharacterSets.add(']');
- _code128ACharacterSets.add('^');
- _code128ACharacterSets.add('_');
- _code128ACharacterSets.add('\0');
- _code128ACharacterSets.add('\u0001');
- _code128ACharacterSets.add('\u0002');
- _code128ACharacterSets.add('\u0003');
- _code128ACharacterSets.add('\u0004');
- _code128ACharacterSets.add('\u0005');
- _code128ACharacterSets.add('\u0006');
- _code128ACharacterSets.add('\a');
- _code128ACharacterSets.add('\b');
- _code128ACharacterSets.add('\t');
- _code128ACharacterSets.add('\n');
- _code128ACharacterSets.add('\v');
- _code128ACharacterSets.add('\f');
- _code128ACharacterSets.add('\r');
- _code128ACharacterSets.add('\u000e');
- _code128ACharacterSets.add('\u000f');
- _code128ACharacterSets.add('\u0010');
- _code128ACharacterSets.add('\u0011');
- _code128ACharacterSets.add('\u0012');
- _code128ACharacterSets.add('\u0013');
- _code128ACharacterSets.add('\u0014');
- _code128ACharacterSets.add('\u0015');
- _code128ACharacterSets.add('\u0016');
- _code128ACharacterSets.add('\u0017');
- _code128ACharacterSets.add('\u0018');
- _code128ACharacterSets.add('\u0019');
- _code128ACharacterSets.add('\u001a');
- _code128ACharacterSets.add('\u001b');
- _code128ACharacterSets.add('\u001c');
- _code128ACharacterSets.add('\u001d');
- _code128ACharacterSets.add('\u001e');
- _code128ACharacterSets.add('\u001f');
- _code128ACharacterSets.add('ù');
- _code128ACharacterSets.add('ø');
- _code128ACharacterSets.add('û');
- _code128ACharacterSets.add('ö');
- _code128ACharacterSets.add('õ');
- _code128ACharacterSets.add('ú');
- _code128ACharacterSets.add('÷');
- _code128ACharacterSets.add('ü');
- _code128ACharacterSets.add('ý');
- _code128ACharacterSets.add('þ');
- _code128ACharacterSets.add('ÿ');
-
- _code128BCharacterSets = [];
- _code128BCharacterSets.add(' ');
- _code128BCharacterSets.add('!');
- _code128BCharacterSets.add('"');
- _code128BCharacterSets.add('#');
- _code128BCharacterSets.add('\$');
- _code128BCharacterSets.add('%');
- _code128BCharacterSets.add('&');
- _code128BCharacterSets.add('\'');
- _code128BCharacterSets.add('(');
- _code128BCharacterSets.add(')');
- _code128BCharacterSets.add('*');
- _code128BCharacterSets.add('+');
- _code128BCharacterSets.add(',');
- _code128BCharacterSets.add('-');
- _code128BCharacterSets.add('.');
- _code128BCharacterSets.add('/');
- _code128BCharacterSets.add('0');
- _code128BCharacterSets.add('1');
- _code128BCharacterSets.add('2');
- _code128BCharacterSets.add('3');
- _code128BCharacterSets.add('4');
- _code128BCharacterSets.add('5');
- _code128BCharacterSets.add('6');
- _code128BCharacterSets.add('7');
- _code128BCharacterSets.add('8');
- _code128BCharacterSets.add('9');
- _code128BCharacterSets.add(':');
- _code128BCharacterSets.add(';');
- _code128BCharacterSets.add('<');
- _code128BCharacterSets.add('=');
- _code128BCharacterSets.add('>');
- _code128BCharacterSets.add('?');
- _code128BCharacterSets.add('@');
- _code128BCharacterSets.add('A');
- _code128BCharacterSets.add('B');
- _code128BCharacterSets.add('C');
- _code128BCharacterSets.add('D');
- _code128BCharacterSets.add('E');
- _code128BCharacterSets.add('F');
- _code128BCharacterSets.add('G');
- _code128BCharacterSets.add('H');
- _code128BCharacterSets.add('I');
- _code128BCharacterSets.add('J');
- _code128BCharacterSets.add('K');
- _code128BCharacterSets.add('L');
- _code128BCharacterSets.add('M');
- _code128BCharacterSets.add('N');
- _code128BCharacterSets.add('O');
- _code128BCharacterSets.add('P');
- _code128BCharacterSets.add('Q');
- _code128BCharacterSets.add('R');
- _code128BCharacterSets.add('S');
- _code128BCharacterSets.add('T');
- _code128BCharacterSets.add('U');
- _code128BCharacterSets.add('V');
- _code128BCharacterSets.add('W');
- _code128BCharacterSets.add('X');
- _code128BCharacterSets.add('Y');
- _code128BCharacterSets.add('Z');
- _code128BCharacterSets.add('[');
- _code128BCharacterSets.add('\\');
- _code128BCharacterSets.add(']');
- _code128BCharacterSets.add('^');
- _code128BCharacterSets.add('_');
- _code128BCharacterSets.add('`');
- _code128BCharacterSets.add('a');
- _code128BCharacterSets.add('b');
- _code128BCharacterSets.add('c');
- _code128BCharacterSets.add('d');
- _code128BCharacterSets.add('e');
- _code128BCharacterSets.add('f');
- _code128BCharacterSets.add('g');
- _code128BCharacterSets.add('h');
- _code128BCharacterSets.add('i');
- _code128BCharacterSets.add('j');
- _code128BCharacterSets.add('k');
- _code128BCharacterSets.add('l');
- _code128BCharacterSets.add('m');
- _code128BCharacterSets.add('n');
- _code128BCharacterSets.add('o');
- _code128BCharacterSets.add('p');
- _code128BCharacterSets.add('q');
- _code128BCharacterSets.add('r');
- _code128BCharacterSets.add('s');
- _code128BCharacterSets.add('t');
- _code128BCharacterSets.add('u');
- _code128BCharacterSets.add('v');
- _code128BCharacterSets.add('w');
- _code128BCharacterSets.add('x');
- _code128BCharacterSets.add('y');
- _code128BCharacterSets.add('z');
- _code128BCharacterSets.add('{');
- _code128BCharacterSets.add('|');
- _code128BCharacterSets.add('}');
- _code128BCharacterSets.add('~');
- _code128BCharacterSets.add('\u007f');
- _code128BCharacterSets.add('ù');
- _code128BCharacterSets.add('ø');
- _code128BCharacterSets.add('û');
- _code128BCharacterSets.add('ö');
- _code128BCharacterSets.add('ú');
- _code128BCharacterSets.add('ô');
- _code128BCharacterSets.add('÷');
- _code128BCharacterSets.add('ü');
- _code128BCharacterSets.add('ý');
- _code128BCharacterSets.add('þ');
- _code128BCharacterSets.add('ÿ');
-
- _code128CCharacterSets = [];
- _code128CCharacterSets.add('0');
- _code128CCharacterSets.add('1');
- _code128CCharacterSets.add('2');
- _code128CCharacterSets.add('3');
- _code128CCharacterSets.add('4');
- _code128CCharacterSets.add('5');
- _code128CCharacterSets.add('6');
- _code128CCharacterSets.add('7');
- _code128CCharacterSets.add('8');
- _code128CCharacterSets.add('9');
- _code128CCharacterSets.add('õ');
- _code128CCharacterSets.add('ô');
- _code128CCharacterSets.add('÷');
- _code128CCharacterSets.add('ü');
- _code128CCharacterSets.add('ý');
- _code128CCharacterSets.add('þ');
- _code128CCharacterSets.add('ÿ');
- }
-
- /// Represents the start symbol of code128A
- static const int _codeAStartSymbol = 103;
-
- /// Represents the start symbol for Code128B
- static const int _codeBStartSymbol = 104;
-
- /// Represents the start symbol for Code128C
- static const int _codeCStartSymbol = 105;
-
- /// Specifies the value for code128A
- static const int _codeA = 101;
-
- /// Specifies the value for code128B
- static const int _codeB = 100;
-
- /// Specifies the value for code128C
- static const int _codeC = 99;
-
- /// Specifies the stop symbol
- static const int _codeStopSymbol = 106;
-
- /// Represents the index value of FNC1 special character
- static const int _codeFNC1 = 102;
-
- /// Represents the index value of FNC2 special character
- static const int _codeFNC2 = 97;
-
- /// Represents the index value of FNC3 special character
- static const int _codeFNC3 = 96;
-
- /// Represents the index value of FNC4A special character
- static const int _codeFNC4A = 101;
-
- /// Represents the index value of FNC4B special character
- static const int _codeFNC4B = 100;
-
- /// Represents the FNC1 special character
- static const String _fnc1 = '\u00f1';
-
- /// Represents the FNC2 special character
- static const String _fnc2 = '\u00f2';
-
- /// Represents the FNC3 special character
- static const String _fnc3 = '\u00f3';
-
- /// Represents the FNC4 special character
- static const String _fnc4 = '\u00f4';
-
- /// Represents the supported symbol character of code128A
- List _code128ACharacterSets;
-
- /// Represents the supported symbol character of code128B
- List _code128BCharacterSets;
-
- /// Represents the supported symbol character of code128C
- List _code128CCharacterSets;
-
- /// Returns the byte value of supported symbol
- ///
- /// This is quite a large method. This method could not be
- /// refactored to a smaller methods, since the code value corresponds to this
- /// symbology is added into the collection
- List> _getCodeValue() {
- return >[
- [2, 1, 2, 2, 2, 2],
- [2, 2, 2, 1, 2, 2],
- [2, 2, 2, 2, 2, 1],
- [1, 2, 1, 2, 2, 3],
- [1, 2, 1, 3, 2, 2],
- [1, 3, 1, 2, 2, 2],
- [1, 2, 2, 2, 1, 3],
- [1, 2, 2, 3, 1, 2],
- [1, 3, 2, 2, 1, 2],
- [2, 2, 1, 2, 1, 3],
- [2, 2, 1, 3, 1, 2],
- [2, 3, 1, 2, 1, 2],
- [1, 1, 2, 2, 3, 2],
- [1, 2, 2, 1, 3, 2],
- [1, 2, 2, 2, 3, 1],
- [1, 1, 3, 2, 2, 2],
- [1, 2, 3, 1, 2, 2],
- [1, 2, 3, 2, 2, 1],
- [2, 2, 3, 2, 1, 1],
- [2, 2, 1, 1, 3, 2],
- [2, 2, 1, 2, 3, 1],
- [2, 1, 3, 2, 1, 2],
- [2, 2, 3, 1, 1, 2],
- [3, 1, 2, 1, 3, 1],
- [3, 1, 1, 2, 2, 2],
- [3, 2, 1, 1, 2, 2],
- [3, 2, 1, 2, 2, 1],
- [3, 1, 2, 2, 1, 2],
- [3, 2, 2, 1, 1, 2],
- [3, 2, 2, 2, 1, 1],
- [2, 1, 2, 1, 2, 3],
- [2, 1, 2, 3, 2, 1],
- [2, 3, 2, 1, 2, 1],
- [1, 1, 1, 3, 2, 3],
- [1, 3, 1, 1, 2, 3],
- [1, 3, 1, 3, 2, 1],
- [1, 1, 2, 3, 1, 3],
- [1, 3, 2, 1, 1, 3],
- [1, 3, 2, 3, 1, 1],
- [2, 1, 1, 3, 1, 3],
- [2, 3, 1, 1, 1, 3],
- [2, 3, 1, 3, 1, 1],
- [1, 1, 2, 1, 3, 3],
- [1, 1, 2, 3, 3, 1],
- [1, 3, 2, 1, 3, 1],
- [1, 1, 3, 1, 2, 3],
- [1, 1, 3, 3, 2, 1],
- [1, 3, 3, 1, 2, 1],
- [3, 1, 3, 1, 2, 1],
- [2, 1, 1, 3, 3, 1],
- [2, 3, 1, 1, 3, 1],
- [2, 1, 3, 1, 1, 3],
- [2, 1, 3, 3, 1, 1],
- [2, 1, 3, 1, 3, 1],
- [3, 1, 1, 1, 2, 3],
- [3, 1, 1, 3, 2, 1],
- [3, 3, 1, 1, 2, 1],
- [3, 1, 2, 1, 1, 3],
- [3, 1, 2, 3, 1, 1],
- [3, 3, 2, 1, 1, 1],
- [3, 1, 4, 1, 1, 1],
- [2, 2, 1, 4, 1, 1],
- [4, 3, 1, 1, 1, 1],
- [1, 1, 1, 2, 2, 4],
- [1, 1, 1, 4, 2, 2],
- [1, 2, 1, 1, 2, 4],
- [1, 2, 1, 4, 2, 1],
- [1, 4, 1, 1, 2, 2],
- [1, 4, 1, 2, 2, 1],
- [1, 1, 2, 2, 1, 4],
- [1, 1, 2, 4, 1, 2],
- [1, 2, 2, 1, 1, 4],
- [1, 2, 2, 4, 1, 1],
- [1, 4, 2, 1, 1, 2],
- [1, 4, 2, 2, 1, 1],
- [2, 4, 1, 2, 1, 1],
- [2, 2, 1, 1, 1, 4],
- [4, 1, 3, 1, 1, 1],
- [2, 4, 1, 1, 1, 2],
- [1, 3, 4, 1, 1, 1],
- [1, 1, 1, 2, 4, 2],
- [1, 2, 1, 1, 4, 2],
- [1, 2, 1, 2, 4, 1],
- [1, 1, 4, 2, 1, 2],
- [1, 2, 4, 1, 1, 2],
- [1, 2, 4, 2, 1, 1],
- [4, 1, 1, 2, 1, 2],
- [4, 2, 1, 1, 1, 2],
- [4, 2, 1, 2, 1, 1],
- [2, 1, 2, 1, 4, 1],
- [2, 1, 4, 1, 2, 1],
- [4, 1, 2, 1, 2, 1],
- [1, 1, 1, 1, 4, 3],
- [1, 1, 1, 3, 4, 1],
- [1, 3, 1, 1, 4, 1],
- [1, 1, 4, 1, 1, 3],
- [1, 1, 4, 3, 1, 1],
- [4, 1, 1, 1, 1, 3],
- [4, 1, 1, 3, 1, 1],
- [1, 1, 3, 1, 4, 1],
- [1, 1, 4, 1, 3, 1],
- [3, 1, 1, 1, 4, 1],
- [4, 1, 1, 1, 3, 1],
- [2, 1, 1, 4, 1, 2],
- [2, 1, 1, 2, 1, 4],
- [2, 1, 1, 2, 3, 2],
- [2, 3, 3, 1, 1, 1, 2]
- ];
- }
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- final int currentCharacter = value[i].codeUnitAt(0);
- if (currentCharacter == _fnc1.codeUnitAt(0) ||
- currentCharacter == _fnc2.codeUnitAt(0) ||
- currentCharacter == _fnc3.codeUnitAt(0) ||
- currentCharacter == _fnc4.codeUnitAt(0)) {
- return true;
- } else if (currentCharacter < 127) {
- return true;
- } else {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return false;
- }
-
- /// Returns the encoded value
- List> _getEncodedValue(String value) {
- final List> encodedValue = >[];
- final List> bytes = _getCodeValue();
- int checkDigit = 0;
- int weightValue = 1;
- int codeTypeValue = 0;
- int currentPosition = 0;
- while (currentPosition < value.length) {
- final int currentCodeType =
- _getValidatedCode(currentPosition, codeTypeValue, value);
- int currentIndex;
- if (currentCodeType == codeTypeValue) {
- final int currentValue = value[currentPosition].codeUnitAt(0);
- if (currentValue == _fnc1.codeUnitAt(0)) {
- currentIndex = _codeFNC1;
- } else if (currentValue == _fnc2.codeUnitAt(0)) {
- currentIndex = _codeFNC2;
- } else if (currentValue == _fnc3.codeUnitAt(0)) {
- currentIndex = _codeFNC3;
- } else if (currentValue == _fnc4.codeUnitAt(0)) {
- if (currentCodeType == _codeA) {
- currentIndex = _codeFNC4A;
- } else {
- currentIndex = _codeFNC4B;
- }
- } else {
- // Calculates the current index value based on code128 type
- if (currentCodeType == _codeA) {
- currentIndex =
- value[currentPosition].codeUnitAt(0) - ' '.codeUnitAt(0);
- if (currentIndex < 0) {
- currentIndex += '`'.codeUnitAt(0);
- }
- } else if (currentCodeType == _codeB) {
- currentIndex =
- value[currentPosition].codeUnitAt(0) - ' '.codeUnitAt(0);
- } else {
- currentIndex = int.parse(
- value.substring(currentPosition, currentPosition + 2));
- currentPosition++;
- }
- }
- currentPosition++;
- } else {
- currentIndex = _getCurrentIndex(codeTypeValue, currentCodeType);
- codeTypeValue = currentCodeType;
- }
- encodedValue.add(bytes[currentIndex]);
- checkDigit += currentIndex * weightValue;
- if (currentPosition != 0) {
- weightValue++;
- }
- }
- checkDigit %= 103;
- encodedValue.add(bytes[checkDigit]);
- encodedValue.add(bytes[_codeStopSymbol]);
- return encodedValue;
- }
-
- /// Method to get the current index value
- int _getCurrentIndex(int codeTypeValue, int currentCodeType) {
- int currentIndex;
- if (codeTypeValue == 0) {
- if (currentCodeType == _codeA) {
- currentIndex = _codeAStartSymbol;
- } else if (currentCodeType == _codeB) {
- currentIndex = _codeBStartSymbol;
- } else {
- currentIndex = _codeCStartSymbol;
- }
- } else {
- currentIndex = currentCodeType;
- }
-
- return currentIndex;
- }
-
- /// Method to validate the corresponding code set based on the input
- int _getValidatedCode(int start, int previousCodeSet, String value) {
- CodeType codeType = _getCodeType(start, value);
- final int currentCodeType =
- _getValidatedCodeTypes(start, previousCodeSet, value, codeType);
- if (currentCodeType != null) {
- return currentCodeType;
- }
- if (previousCodeSet == _codeB) {
- if (codeType == CodeType.fnc1) {
- return _codeB;
- }
- codeType = _getCodeType(start + 2, value);
- if (codeType == CodeType.uncodable || codeType == CodeType.singleDigit) {
- return _codeB;
- }
- if (codeType == CodeType.fnc1) {
- codeType = _getCodeType(start + 3, value);
- if (codeType == CodeType.doubleDigit) {
- return this is Code128C ? _codeC : _codeB;
- } else {
- return _codeB;
- }
- }
- int currentIndex = start + 4;
- while (_getCodeType(currentIndex, value) == CodeType.doubleDigit) {
- currentIndex += 2;
- }
- if (codeType == CodeType.singleDigit) {
- return _codeB;
- }
- return this is Code128B ? _codeB : _codeC;
- }
-
- if (codeType == CodeType.fnc1) {
- codeType = _getCodeType(start + 1, value);
- }
-
- if (codeType == CodeType.doubleDigit) {
- return this is Code128B ? _codeB : _codeC;
- }
- return _codeB;
- }
-
- /// Method to get the validated types
- int _getValidatedCodeTypes(
- int start, int previousCodeSet, String value, CodeType codeType) {
- if (codeType == CodeType.singleDigit) {
- if (previousCodeSet == _codeA) {
- return _codeA;
- }
- return _codeB;
- }
-
- if (codeType == CodeType.uncodable) {
- if (start < value.length) {
- final int startIndex = value[start].codeUnitAt(0);
- if (startIndex < ' '.codeUnitAt(0) ||
- (previousCodeSet == _codeA &&
- (startIndex < '`'.codeUnitAt(0) ||
- (startIndex >= _fnc1.codeUnitAt(0) &&
- startIndex <= _fnc4.codeUnitAt(0))))) {
- return _codeA;
- }
- }
- return _codeB;
- }
- if (previousCodeSet == _codeA && codeType == CodeType.fnc1) {
- return _codeA;
- }
- if (previousCodeSet == _codeC) {
- return _codeC;
- }
-
- return null;
- }
-
- /// Returns the code type based on the input
- CodeType _getCodeType(int startIndex, String value) {
- final int length = value.length;
- if (startIndex >= length) {
- return CodeType.uncodable;
- }
- if (String.fromCharCode(value[startIndex].codeUnitAt(0)) ==
- String.fromCharCode(_fnc1.codeUnitAt(0))) {
- return CodeType.fnc1;
- }
- if (value[startIndex].codeUnitAt(0) < '0'.codeUnitAt(0) ||
- value[startIndex].codeUnitAt(0) > '9'.codeUnitAt(0)) {
- return CodeType.uncodable;
- }
-
- if (startIndex + 1 >= length) {
- return CodeType.singleDigit;
- }
-
- if (value[startIndex + 1].codeUnitAt(0) < '0'.codeUnitAt(0) ||
- value[startIndex + 1].codeUnitAt(0) > '9'.codeUnitAt(0)) {
- return CodeType.singleDigit;
- }
-
- return CodeType.doubleDigit;
- }
-
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- final Paint paint = _getBarPaint(foregroundColor);
- final List> encodedValue = _getEncodedValue(value);
- final int totalBarLength = _getTotalBarLength(encodedValue);
- double left = module == null
- ? offset.dx
- : _getLeftPosition(totalBarLength, module, size.width, offset.dx);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- // Calculates the bar length based on number of individual bar codes
- final int singleModule = (size.width ~/ totalBarLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (size.width - (totalBarLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- for (int i = 0; i < encodedValue.length; i++) {
- bool canDraw = true;
- final List currentIndex = encodedValue[i];
- for (int j = 0; j < currentIndex.length; j++) {
- final int currentValue = currentIndex[j];
- // Draws the bar code based on the current value
- for (int k = 0; k < currentValue; k++) {
- if (canDraw) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + size.height);
- canvas.drawRect(individualBarRect, paint);
- }
- left += ratio;
- }
- canDraw = !canDraw;
- }
- }
- if (showValue) {
- _drawText(canvas, offset, size, value, textStyle, textSpacing, textAlign);
- }
- }
-
- /// Calculate total bar length from give input value
- int _getTotalBarLength(List> encodedValue) {
- int length = 0;
- for (int i = 0; i < encodedValue.length; i++) {
- final List currentValue = encodedValue[i];
- for (int j = 0; j < currentValue.length; j++) {
- length += currentValue[j];
- }
- }
- return length;
- }
+ );
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128a_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128a_symbology.dart
index c4d8549c2..0cf5a17d4 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128a_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128a_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../one_dimensional/code128_symbology.dart';
/// The [Code128A] (or chars set A) barcode includes all the standard upper
/// cases, alphanumeric keyboard characters and punctuation characters together
@@ -10,14 +10,4 @@ class Code128A extends Code128 {
/// The arguments [module] must be non-negative and greater than 0.
///
Code128A({int module}) : super(module: module);
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (!_code128ACharacterSets.contains(value[i])) {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128b_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128b_symbology.dart
index c88e0eed8..e6253ac0c 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128b_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128b_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../one_dimensional/code128_symbology.dart';
/// The [Code128B] (or chars set B) barcode includes all the standard upper
/// case, alphanumeric keyboard characters and punctuation characters
@@ -10,14 +10,4 @@ class Code128B extends Code128 {
/// The arguments [module] must be non-negative and greater than 0.
///
Code128B({int module}) : super(module: module);
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (!_code128BCharacterSets.contains(value[i])) {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128c_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128c_symbology.dart
index e2b9c3f46..26e0064d3 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128c_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code128c_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../one_dimensional/code128_symbology.dart';
/// The [Code128C] (or chars set C) barcode includes a set of 100 digit pairs
/// from 00 to 99 inclusive, as well as three special characters.
@@ -10,14 +10,4 @@ class Code128C extends Code128 {
/// The arguments [module] must be non-negative and greater than 0.
///
Code128C({int module}) : super(module: module);
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (!_code128CCharacterSets.contains(value[i])) {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_extended_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_extended_symbology.dart
index 9c54d576c..e3c9d4b0c 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_extended_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_extended_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import 'code39_symbology.dart';
/// The [Code39Extended] is an extended version of [Code39].
/// Lower characters and special characters are additionally supported.
@@ -18,163 +18,5 @@ class Code39Extended extends Code39 {
/// refactored to a smaller methods, but it degrades the performance.Since it
/// adds character corresponding to this symbology is added in to the list
Code39Extended({int module, bool enableCheckSum})
- : super(module: module, enableCheckSum: enableCheckSum ?? true) {
- _code39ExtendedMap = {
- '0': '%U',
- '1': '\$A',
- '2': '\$B',
- '3': '\$C',
- '4': '\$D',
- '5': '\$E',
- '6': '\$F',
- '7': '\$G',
- '8': '\$H',
- '9': '\$I',
- '10': '\$J',
- '11': '\$K',
- '12': '\$L',
- '13': '\$M',
- '14': '\$N',
- '15': '\$O',
- '16': '\$P',
- '17': '\$Q',
- '18': '\$R',
- '19': '\$S',
- '20': '\$T',
- '21': '\$U',
- '22': '\$V',
- '23': '\$W',
- '24': '\$X',
- '25': '\$Y',
- '26': '\$Z',
- '27': '%A',
- '28': '%B',
- '29': '%C',
- '30': '%D',
- '31': '%E',
- '32': ' ',
- '33': '/A',
- '34': '/B',
- '35': '/C',
- '36': '/D',
- '37': '/E',
- '38': '/F',
- '39': '/G',
- '40': '/H',
- '41': '/I',
- '42': '/J',
- '43': '/K',
- '44': '/L',
- '45': '-',
- '46': '.',
- '47': '/O',
- '48': '0',
- '49': '1',
- '50': '2',
- '51': '3',
- '52': '4',
- '53': '5',
- '54': '6',
- '55': '7',
- '56': '8',
- '57': '9',
- '58': '/Z',
- '59': '%F',
- '60': '%G',
- '61': '%H',
- '62': '%I',
- '63': '%J',
- '64': '%V',
- '65': 'A',
- '66': 'B',
- '67': 'C',
- '68': 'D',
- '69': 'E',
- '70': 'F',
- '71': 'G',
- '72': 'H',
- '73': 'I',
- '74': 'J',
- '75': 'K',
- '76': 'L',
- '77': 'M',
- '78': 'N',
- '79': 'O',
- '80': 'P',
- '81': 'Q',
- '82': 'R',
- '83': 'S',
- '84': 'T',
- '85': 'U',
- '86': 'V',
- '87': 'W',
- '88': 'X',
- '89': 'Y',
- '90': 'Z',
- '91': '%K',
- '92': '%L',
- '93': '%M',
- '94': '%N',
- '95': '%O',
- '96': '%W',
- '97': '+A',
- '98': '+B',
- '99': '+C',
- '100': '+D',
- '101': '+E',
- '102': '+F',
- '103': '+G',
- '104': '+H',
- '105': '+I',
- '106': '+J',
- '107': '+K',
- '108': '+L',
- '109': '+M',
- '110': '+N',
- '111': '+O',
- '112': '+P',
- '113': '+Q',
- '114': '+R',
- '115': '+S',
- '116': '+T',
- '117': '+U',
- '118': '+V',
- '119': '+W',
- '120': '+X',
- '121': '+Y',
- '122': '+Z',
- '123': '%P',
- '124': '%Q',
- '125': ' %R',
- '126': '%S',
- '127': '%T',
- };
- }
-
- /// Map to stores the input character and its index
- Map _code39ExtendedMap;
-
- /// To validate the provided input value
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (value[i].codeUnitAt(0) > 127) {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
-
- /// Returns the encoded byte value for the provided value
- @override
- List _getCodeValues(String value) {
- String encodedString = '';
- for (int i = 0; i < value.length; i++) {
- final int asciiValue = value[i].codeUnitAt(0);
- final String actualValue =
- _code39ExtendedMap.entries.elementAt(asciiValue).value;
- encodedString += actualValue;
- }
- return _getEncodedValue(encodedString);
- }
+ : super(module: module, enableCheckSum: enableCheckSum ?? true);
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_symbology.dart
index 6fb07c372..cfd1d278e 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code39_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The [Code39] is a discrete, variable-length symbology that encodes
/// alphanumeric characters into a series of bars.
@@ -23,56 +23,7 @@ class Code39 extends Symbology {
/// a modulo 43 checksum can be added,
/// if the [enableCheckSum] is true.
///
- Code39({int module, this.enableCheckSum = true}) : super(module: module) {
- _code39Symbology = [
- '111221211',
- '211211112',
- '112211112',
- '212211111',
- '111221112',
- '211221111',
- '112221111',
- '111211212',
- '211211211',
- '112211211',
- '211112112',
- '112112112',
- '212112111',
- '111122112',
- '211122111',
- '112122111',
- '111112212',
- '211112211',
- '112112211',
- '111122211',
- '211111122',
- '112111122',
- '212111121',
- '111121122',
- '211121121',
- '112121121',
- '111111222',
- '211111221',
- '112111221',
- '111121221',
- '221111112',
- '122111112',
- '222111111',
- '121121112',
- '221121111',
- '122121111',
- '121111212',
- '221111211',
- '122111211',
- '121121211',
- '121212111',
- '121211121',
- '121112121',
- '111212121'
- ];
-
- _character = _getCode39Character();
- }
+ Code39({int module, this.enableCheckSum = true}) : super(module: module);
/// Whether to add a checksum on the far right side of the barcode.
///
@@ -91,141 +42,4 @@ class Code39 extends Symbology {
///}
/// ```dart
final bool enableCheckSum;
-
- /// Represents the code39 symbology
- List _code39Symbology;
-
- /// Represnts the encoded input character
- String _character;
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (!_character.contains(value[i])) {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
-
- /// Calculates the check sum value based on the input
- String _getCheckSum(String value, String codeBarCharacters) {
- int checkSum = 0;
- for (int i = 0; i < value.length; i++) {
- final int codeNumber = codeBarCharacters.indexOf(value[i]);
- checkSum += codeNumber;
- }
- checkSum = checkSum % 43;
- return checkSum.toString();
- }
-
- /// Returns the provided value with start and stop symbol
- String _getValueWithStartAndStopCharacters(String value) {
- return '*' + value + '*';
- }
-
- /// Returns the pattern collection based on the provided input
- List _getPatternCollection(
- String providedValue, String code39Characters) {
- final List code39Values = [];
- for (int i = 0; i < providedValue.length; i++) {
- final int currentIndex = code39Characters.indexOf(providedValue[i]);
- code39Values.add(_code39Symbology[currentIndex]);
- }
- return code39Values;
- }
-
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues(value);
- final int barTotalLength = _getTotalLength(code);
- double left = module == null
- ? offset.dx
- : _getLeftPosition(barTotalLength, module, size.width, offset.dx);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- // Calculates the bar length based on number of individual bar codes
- final int singleModule = (size.width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (size.width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- const bool hasExtraHeight = false;
- final double barHeight = hasExtraHeight
- ? size.height + _textSize.height + textSpacing
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- // The current bar is drawn, if its value is divisible by 2
- final bool canDraw = j % 2 == 0 ? true : false;
- final int currentValue = int.parse(codeValue[j]);
- if (canDraw &&
- (left >= barCodeRect.left &&
- left + (currentValue * ratio) < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(left, offset.dy,
- left + (currentValue * ratio), offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
- left += currentValue * ratio;
- }
- if (i < code.length - 1) {
- left += ratio;
- }
- }
- if (showValue) {
- _drawText(canvas, offset, size, value, textStyle, textSpacing, textAlign);
- }
- }
-
- /// Returns the encoded value
- List _getCodeValues(String value) {
- return _getEncodedValue(value);
- }
-
- /// Calculate total bar length from give input value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final String currentItem = code[i];
- for (int j = 0; j < currentItem.length; j++) {
- count += int.parse(currentItem[j]);
- }
- }
- count += code.length - 1;
- return count;
- }
-
- /// Represents the encoded value for provided input
- List _getEncodedValue(String providedValue) {
- if (enableCheckSum) {
- final String checkSum = _getCheckSum(providedValue, _character);
- providedValue += checkSum;
- }
- providedValue = _getValueWithStartAndStopCharacters(providedValue);
- return _getPatternCollection(providedValue, _character);
- }
-
- /// Represents the code bar value
- String _getCode39Character() {
- const String code39Character =
- '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *\$/+%';
- return code39Character;
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code93_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code93_symbology.dart
index 265faa342..cbce95508 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code93_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/code93_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The [Code93] was designed to complement and improve [Code39]. It is used to
/// represent the full ASCII character set by using combinations of two
@@ -14,248 +14,5 @@ class Code93 extends Symbology {
/// high level of accuracy.
/// The checksum character is the modulo 47 remainder of the sum of the
/// weighted value of the data characters.
- Code93({int module}) : super(module: module) {
- _character = _getCode93Character();
- }
-
- /// Represents the input value
- String _character;
-
- @override
- bool _getIsValidateInput(String value) {
- for (int i = 0; i < value.length; i++) {
- if (!_character.contains(value[i])) {
- throw 'The provided input cannot be encoded : ' + value[i];
- }
- }
- return true;
- }
-
- /// Returns the weight for the supported input character
- Map _getCharacterWeight() {
- return {
- '0': '0',
- '1': '1',
- '2': '2',
- '3': '3',
- '4': '4',
- '5': '5',
- '6': '6',
- '7': '7',
- '8': '8',
- '9': '9',
- 'A': '10',
- 'B': '11',
- 'C': '12',
- 'D': '13',
- 'E': '14',
- 'F': '15',
- 'G': '16',
- 'H': '17',
- 'I': '18',
- 'J': '19',
- 'K': '20',
- 'L': '21',
- 'M': '22',
- 'N': '23',
- 'O': '24',
- 'P': '25',
- 'Q': '26',
- 'R': '27',
- 'S': '28',
- 'T': '29',
- 'U': '30',
- 'V': '31',
- 'W': '32',
- 'X': '33',
- 'Y': '34',
- 'Z': '35',
- '-': '36',
- '.': '37',
- ' ': '38',
- '\$': '39',
- '/': '40',
- '+': '41',
- '%': '42',
- '(\$)': '43',
- '(/)': '44',
- '(+)': '45',
- '(%)': '46',
- };
- }
-
- /// Returns the byte value of the supported input symbol
- Map _getCodeValue() {
- return {
- '0': '100010100',
- '1': '101001000',
- '2': '101000100',
- '3': '101000010',
- '4': '100101000',
- '5': '100100100',
- '6': '100100010',
- '7': '101010000',
- '8': '100010010',
- '9': '100001010',
- 'A': '110101000',
- 'B': '110100100',
- 'C': '110100010',
- 'D': '110010100',
- 'E': '110010010',
- 'F': '110001010',
- 'G': '101101000',
- 'H': '101100100',
- 'I': '101100010',
- 'J': '100110100',
- 'K': '100011010',
- 'L': '101011000',
- 'M': '101001100',
- 'N': '101000110',
- 'O': '100101100',
- 'P': '100010110',
- 'Q': '110110100',
- 'R': '110110010',
- 'S': '110101100',
- 'T': '110100110',
- 'U': '110010110',
- 'V': '110011010',
- 'W': '101101100',
- 'X': '101100110',
- 'Y': '100110110',
- 'Z': '100111010',
- '-': '100101110',
- '.': '111010100',
- ' ': '111010010',
- '\$': '111001010',
- '/': '101101110',
- '+': '101110110',
- '%': '110101110',
- '(\$)': '100100110',
- '(/)': '111010110',
- '(+)': '100110010',
- '(%)': '111011010',
- };
- }
-
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues(value);
- final int barTotalLength = _getTotalLength(code);
- double left = module == null
- ? offset.dx
- : _getLeftPosition(barTotalLength, module, size.width, offset.dx);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- //Calculates the bar length based on number of individual bar codes
- final int singleModule = (size.width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (size.width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- const bool hasExtraHeight = false;
- final double barHeight = hasExtraHeight
- ? size.height + _textSize.height + textSpacing
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- //Draws the barcode when the corresponding bar value is one
- final bool canDraw = codeValue[j] == '1' ? true : false;
- if (canDraw &&
- (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
- left += ratio;
- }
- }
- if (showValue) {
- _drawText(canvas, offset, size, value, textStyle, textSpacing, textAlign);
- }
- }
-
- /// Represents the pattern collection based on the provided input
- List _getPatternCollection(String givenCharacter,
- Map codes, List encodingValue) {
- final List codeKey = codes.keys.toList();
- for (int i = 0; i < givenCharacter.length; i++) {
- final int index = codeKey.indexOf(givenCharacter[i]);
- encodingValue.add(codes.entries.elementAt(index).value);
- }
- return encodingValue;
- }
-
- /// Calculate total bar length from give input value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final int numberOfDigits = code[i].length;
- count += numberOfDigits;
- }
- return count;
- }
-
- /// Calculates the check sum value
- String _getCheckSum(String givenCharacter) {
- final String value = givenCharacter;
- int weightSum = 0;
- int j = 0;
- int moduleValue;
- String appendSymbol;
- final Map codes = _getCharacterWeight();
- final List codeKey = codes.keys.toList();
- for (int i = value.length; i > 0; i--) {
- final int index = codeKey.indexOf(value[j]);
- final int characterValue =
- int.parse(codes.entries.elementAt(index).value) * i;
- weightSum += characterValue;
- j++;
- }
- moduleValue = weightSum % 47;
- final List objectValue = codes.keys.toList();
- appendSymbol = objectValue[moduleValue];
- return appendSymbol;
- }
-
- /// Returns the encoded value
- List _getCodeValues(String value) {
- final Map codes = _getCodeValue();
- List encodingValue = [];
- String givenCharacter = value;
- const String startStopCharacter = '101011110';
- const String terminationBar = '1';
-
- givenCharacter += _getCheckSum(givenCharacter);
- givenCharacter += _getCheckSum(givenCharacter);
-
- encodingValue.add(startStopCharacter);
- encodingValue = _getPatternCollection(givenCharacter, codes, encodingValue);
- encodingValue.add(startStopCharacter);
- encodingValue.add(terminationBar);
- return encodingValue;
- }
-
- /// Retuns the supported input symbol
- String _getCode93Character() {
- const String code93Character =
- '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *\$/+%';
- return code93Character;
- }
+ Code93({int module}) : super(module: module);
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean13_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean13_symbology.dart
index 945b46aa5..4efa36b44 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean13_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean13_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The [EAN13] is based on the [UPCA] standard. As with [UPCA], it supports
/// only numeric characters.
@@ -24,297 +24,4 @@ class EAN13 extends Symbology {
/// automatically.
///
EAN13({int module}) : super(module: module);
-
- /// Represents the encoded input vale
- String _encodedValue;
-
- @override
- bool _getIsValidateInput(String value) {
- if (value.contains(RegExp(r'^(?=.*?[0-9]).{13}$'))) {
- if (int.parse(value[12]) == _getCheckSumData(value)) {
- _encodedValue = value;
- } else {
- throw 'Invalid check digit at the trailing end. '
- 'Provide the valid check digit or remove it. '
- 'Since, it has been calculated automatically.';
- }
- } else if (value.contains(RegExp(r'^(?=.*?[0-9]).{12}$'))) {
- _encodedValue = value + _getCheckSumData(value).toString();
- } else {
- throw 'EAN13 supports only numeric characters. '
- 'The provided value should have 12 digits (without check digit) or'
- ' with 13 digits.';
- }
- return true;
- }
-
- /// This is quite a large method. This method could not be
- /// refactored to a smaller methods, since it requires multiple parameters
- /// to be passed
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- /// _singleDigitValues[0] specifies left value of start digit
- /// _singleDigitValues[1] specifies width of start digit
- final List singleDigitValues = List(2);
-
- /// _positions[0] specifies end position of start bar
- /// _positions[1] specifies start position of middle bar
- /// _positions[2] specifies end position of middle bar
- /// _positions[3] specifies start position of end bar
- final List positions = List(4);
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues();
- final int barTotalLength = _getTotalLength(code);
- singleDigitValues[1] =
- showValue ? _measureText(_encodedValue[0], textStyle).width : 0;
- const int additionalWidth = 2;
- singleDigitValues[1] += additionalWidth;
- final double width = size.width - singleDigitValues[1];
- double left = module == null
- ? offset.dx + singleDigitValues[1]
- : _getLeftPosition(
- barTotalLength, module, width, offset.dx + singleDigitValues[1]);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- // Calculates the bar length based on number of individual bar codes
- final int singleModule = (width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- singleDigitValues[0] = left - singleDigitValues[1];
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- final bool hasExtraHeight = _getHasExtraHeight(i, code);
- final double additionalHeight = i == 2 ? 0.4 : 0.5;
- final double barHeight = hasExtraHeight
- ? size.height +
- (showValue
- ? (_textSize.height * additionalHeight) + textSpacing
- : 0)
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- // Draw the barcode when the current code value is 1
- final bool canDraw = codeValue[j] == '1' ? true : false;
- if (canDraw &&
- (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
- left += ratio;
- if (i == 0 && j == codeLength - 1) {
- // Checks the end position of first extra height bar
- positions[0] = left;
- } else if (i == 1 && j == codeLength - 1) {
- // Checks the start position of second extra height bar
- positions[1] = left;
- } else if (i == 2 && j == codeLength - 1) {
- // Checks the end position of second extra height bar
- positions[2] = left;
- } else if (i == 4 && j == codeLength - 1) {
- // Checks the start position of third extra height bar
- positions[3] = left;
- }
- }
- }
- if (showValue) {
- _paintText(canvas, offset, size, _encodedValue, textStyle, textSpacing,
- textAlign, positions, singleDigitValues);
- }
- }
-
- /// Returns the encoded value
- List _getCodeValues() {
- const String endBar = '101';
- const String middleBar = '01010';
- final Map structureValue = _getStructure();
- final String structure =
- structureValue.entries.elementAt(int.parse(_encodedValue[0])).value;
- final List code = [];
- code.add(endBar);
- String leftString = _encodedValue.substring(1, 7);
- code.add(_getLeftValue(true, structure, leftString));
- code.add(middleBar);
- leftString = _encodedValue.substring(7, 12);
- code.add(_getLeftValue(false, 'RRRRRR', leftString));
- leftString = _encodedValue[12];
- code.add(_getLeftValue(false, 'RRRRRR', leftString));
- code.add(endBar);
- return code;
- }
-
- /// To return the binary values of the supported input symbol
- Map> _getBinaries() {
- return >{
- 'L': [
- // The L (left) type of encoding
- '0001101', '0011001', '0010011', '0111101', '0100011',
- '0110001', '0101111', '0111011', '0110111', '0001011'
- ],
- 'G': [
- // The G type of encoding
- '0100111', '0110011', '0011011', '0100001', '0011101',
- '0111001', '0000101', '0010001', '0001001', '0010111'
- ],
- 'R': [
- // The R (right) type of encoding
- '1110010', '1100110', '1101100', '1000010', '1011100',
- '1001110', '1010000', '1000100', '1001000', '1110100'
- ],
- 'O': [
- // The O (odd) encoding for UPC-E
- '0001101', '0011001', '0010011', '0111101', '0100011',
- '0110001', '0101111', '0111011', '0110111', '0001011'
- ],
- 'E': [
- // The E (even) encoding for UPC-E
- '0100111', '0110011', '0011011', '0100001', '0011101',
- '0111001', '0000101', '0010001', '0001001', '0010111'
- ]
- };
- }
-
- /// Calculate total bar length from give input value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final int numberOfDigits = code[i].length;
- count += numberOfDigits;
- }
- return count;
- }
-
- /// Represents the structure of the supported input symbol
- Map _getStructure() {
- return {
- '0': 'LLLLLL',
- '1': 'LLGLGG',
- '2': 'LLGGLG',
- '3': 'LLGGGL',
- '4': 'LGLLGG',
- '5': 'LGGLLG',
- '6': 'LGGGLL',
- '7': 'LGLGLG',
- '8': 'LGLGGL',
- '9': 'LGGLGL'
- };
- }
-
- /// Method to calculate the check sum digit
- int _getCheckSumData(String value) {
- final int sum1 = 3 *
- (int.parse(value[11]) +
- int.parse(value[9]) +
- int.parse(value[7]) +
- int.parse(value[5]) +
- int.parse(value[3]) +
- int.parse(value[1]));
- final int sum2 = int.parse(value[10]) +
- int.parse(value[8]) +
- int.parse(value[6]) +
- int.parse(value[4]) +
- int.parse(value[2]) +
- int.parse(value[0]);
- final int checkSumValue = sum1 + sum2;
- final int checkSumDigit = (10 - checkSumValue) % 10;
- return checkSumDigit;
- }
-
- /// Method to calculate the left value
- String _getLeftValue(bool isLeft, String structure, String leftString) {
- String code;
- List tempCodes;
- final Map> codes = _getBinaries();
- for (int i = 0; i < leftString.length; i++) {
- if (structure[i] == 'L') {
- tempCodes = codes.entries.elementAt(0).value;
- } else if (structure[i] == 'G') {
- tempCodes = codes.entries.elementAt(1).value;
- } else if (structure[i] == 'R') {
- tempCodes = codes.entries.elementAt(2).value;
- } else if (structure[i] == 'O') {
- tempCodes = codes.entries.elementAt(3).value;
- } else if (structure[i] == 'E') {
- tempCodes = codes.entries.elementAt(4).value;
- }
-
- final int currentValue = int.parse(leftString[i]);
- if (i == 0) {
- code = tempCodes[currentValue];
- } else {
- code += tempCodes[currentValue];
- }
- }
- return code;
- }
-
- /// Method to render the input value of the barcode
- void _paintText(
- Canvas canvas,
- Offset offset,
- Size size,
- String value,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- List positions,
- List singleDigitValues) {
- final String value1 = value[0];
- final String value2 = value.substring(1, 7);
- final String value3 = value.substring(7, 13);
- final double secondTextWidth = positions[1] - positions[0];
- final double thirdTextWidth = positions[3] - positions[2];
-
- // Renders the first digit of the input
- _drawText(
- canvas,
- Offset(singleDigitValues[0], offset.dy + size.height + textSpacing),
- Size(singleDigitValues[1], size.height),
- value1,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
-
- // Renders the first six digits of encoded text
- _drawText(
- canvas,
- Offset(positions[0], offset.dy),
- Size(secondTextWidth, size.height),
- value2,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
-
- // Renders the second six digits of encoded text
- _drawText(
- canvas,
- Offset(positions[2], offset.dy),
- Size(thirdTextWidth, size.height),
- value3,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean8_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean8_symbology.dart
index e8154addb..26ec9341c 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean8_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/ean8_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The [EAN8] is equivalent to the [UPCE] for small packaging details.
/// It is shorter than the [EAN13] barcode and longer than [UPCE].
@@ -21,236 +21,4 @@ class EAN8 extends Symbology {
/// automatically.
///
EAN8({int module}) : super(module: module);
-
- /// Represents the encoded input value
- String _encodedValue;
-
- @override
- bool _getIsValidateInput(String value) {
- if (value.contains(RegExp(r'^(?=.*?[0-9]).{8}$'))) {
- if (int.parse(value[7]) == _getCheckSumData(value)) {
- _encodedValue = value;
- } else {
- throw 'Invalid check digit at the trailing end. '
- 'Provide the valid check digit or remove it. '
- 'Since, it has been calculated automatically.';
- }
- } else if (value.contains(RegExp(r'^(?=.*?[0-9]).{7}$'))) {
- _encodedValue = value + _getCheckSumData(value).toString();
- } else {
- throw 'EAN8 supports only numeric characters.'
- ' The provided value should have 7 digits (without check digit)'
- ' or with 8 digits.';
- }
- return true;
- }
-
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- /// _positions[0] specifies end position of start bar
- /// _positions[1] specifies start position of middle bar
- /// _positions[2] specifies end position of middle bar
- /// _positions[3] specifies start position of end bar
- final List positions = List(4);
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues();
- final int barTotalLength = _getTotalLength(code);
- double left = module == null
- ? offset.dx
- : _getLeftPosition(barTotalLength, module, size.width, offset.dx);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
-
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- // Calculates the bar length based on number of individual bar codes
- final int singleModule = (size.width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (size.width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- final bool hasExtraHeight = _getHasExtraHeight(i, code);
- final double additionalHeight = i == 2 ? 0.4 : 0.5;
- final double barHeight = hasExtraHeight
- ? size.height +
- (showValue
- ? (_textSize.height * additionalHeight) + textSpacing
- : 0)
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- // Draw the barcode when the current code value is 1
- final bool canDraw = codeValue[j] == '1' ? true : false;
- if (canDraw &&
- (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
- left += ratio;
- if (i == 0 && j == codeLength - 1) {
- // Checks the end position of first extra height bar
- positions[0] = left;
- } else if (i == 1 && j == codeLength - 1) {
- // Checks the start position of second extra height bar
- positions[1] = left;
- } else if (i == 2 && j == codeLength - 1) {
- // Checks the end position of second extra height bar
- positions[2] = left;
- } else if (i == 3 && j == codeLength - 1) {
- // Checks the start position of third extra height bar
- positions[3] = left;
- }
- }
- }
- if (showValue) {
- _paintText(canvas, offset, size, _encodedValue, textStyle, textSpacing,
- textAlign, positions);
- }
- }
-
- /// Calculate total bar length from given input value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final int numberOfDigits = code[i].length;
- count += numberOfDigits;
- }
- return count;
- }
-
- /// Returns the encoded value
- List _getCodeValues() {
- const String endBars = '101';
- const String middleBar = '01010';
- Map codes = _getCodeValueRight(true);
- final List code = [];
- code.add(endBars);
- code.add(_getLeftValue(codes, true));
- code.add(middleBar);
- codes = _getCodeValueRight(false);
- code.add(_getLeftValue(codes, false));
- code.add(endBars);
- return code;
- }
-
- /// Represents the encoded value for the first 6 digits of the input value
- String _getLeftValue(Map codes, bool isLeft) {
- String code = '';
- for (int i = isLeft ? 0 : _encodedValue.length - 4;
- i < (isLeft ? _encodedValue.length - 4 : _encodedValue.length);
- i++) {
- final int currentValue = int.parse(_encodedValue[i]);
- if (i == 0 || i == 4) {
- code = codes.entries.elementAt(currentValue).value;
- } else {
- code += codes.entries.elementAt(currentValue).value;
- }
- }
- return code;
- }
-
- /// Method to calculate the input data
- int _getCheckSumData(String value) {
- for (int i = 0; i < value.length; i++) {
- final int sum1 =
- int.parse(value[1]) + int.parse(value[3]) + int.parse(value[5]);
- final int sum2 = 3 *
- (int.parse(value[0]) +
- int.parse(value[2]) +
- int.parse(value[4]) +
- int.parse(value[6]));
- final int checkSumValue = sum1 + sum2;
- final int checkSumDigit = (10 - checkSumValue) % 10;
- return checkSumDigit;
- }
- return 0;
- }
-
- /// Represents the encoded value for the last 6 digits of the input value
- Map _getCodeValueRight(bool isRight) {
- Map codes;
- if (isRight) {
- codes = {
- '0': '0001101',
- '1': '0011001',
- '2': '0010011',
- '3': '0111101',
- '4': '0100011',
- '5': '0110001',
- '6': '0101111',
- '7': '0111011',
- '8': '0110111',
- '9': '0001011',
- };
- } else {
- codes = {
- '0': '1110010',
- '1': '1100110',
- '2': '1101100',
- '3': '1000010',
- '4': '1011100',
- '5': '1001110',
- '6': '1010000',
- '7': '1000100',
- '8': '1001000',
- '9': '1110100'
- };
- }
- return codes;
- }
-
- /// Method to render the input value of the barcode
- void _paintText(
- Canvas canvas,
- Offset offset,
- Size size,
- String value,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- List positions) {
- final String value1 = value.substring(0, 4);
- final String value2 = value.substring(4, 8);
- final double firstTextWidth = positions[1] - positions[0];
- final double secondTextWidth = positions[3] - positions[2];
-
- // Renders the first four digits of input
- _drawText(
- canvas,
- Offset(positions[0], offset.dy),
- Size(firstTextWidth, size.height),
- value1,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
-
- // Renders the last four digits of input
- _drawText(
- canvas,
- Offset(positions[2], offset.dy),
- Size(secondTextWidth, size.height),
- value2,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upca_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upca_symbology.dart
index 49564254b..30d08fb58 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upca_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upca_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// The universal product code ([UPCA]) is a numeric symbology used in
/// worldwide retail applications.
@@ -22,301 +22,4 @@ class UPCA extends Symbology {
/// automatically.
///
UPCA({int module}) : super(module: module);
-
- /// Represents the encoded input value
- String _encodedValue;
-
- @override
- bool _getIsValidateInput(String value) {
- if (value.contains(RegExp(r'^(?=.*?[0-9]).{11}$'))) {
- _encodedValue = value + _getCheckSumData(value).toString();
- } else if (value.contains(RegExp(r'^(?=.*?[0-9]).{12}$'))) {
- if (int.parse(value[11]) == _getCheckSumData(value)) {
- _encodedValue = value;
- } else {
- throw 'Invalid check digit at the trailing end.'
- ' Provide the valid check digit or remove it.'
- ' Since, it has been calculated automatically.';
- }
- } else {
- throw 'UPCA supports only numeric characters. '
- 'The provided value should have 11 digits (without check digit) '
- 'or with 12 digits.';
- }
- return true;
- }
-
- /// This is quite a large method. This method could not be
- /// refactored to a smaller methods, since it requires multiple parameters
- /// to be passed
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues();
- final int barTotalLength = _getTotalLength(code);
- const int additionalWidth = 2;
-
- /// _singleDigitValues[0] specifies left value of start digit
- /// _singleDigitValues[1] specifies width of start digit
- /// _singleDigitValues[2] specifies left value of end digit
- /// _singleDigitValues[3] specifies width of end digit
- final List singleDigitValues = List(4);
-
- /// _positions[0] specifies end position of start bar
- /// _positions[1] specifies start position of middle bar
- /// _positions[2] specifies end position of middle bar
- /// _positions[3] specifies start position of end bar
- final List positions = List(4);
- if (showValue) {
- singleDigitValues[1] = _measureText(_encodedValue[0], textStyle).width;
- singleDigitValues[1] += additionalWidth;
- singleDigitValues[3] =
- _measureText(_encodedValue[_encodedValue.length - 1], textStyle)
- .width;
- singleDigitValues[3] += additionalWidth;
- } else {
- singleDigitValues[1] = singleDigitValues[3] = 0;
- }
- final double width =
- size.width - (singleDigitValues[1] + singleDigitValues[3]);
- double left = module == null
- ? offset.dx + singleDigitValues[1]
- : _getLeftPosition(
- barTotalLength, module, width, offset.dx + singleDigitValues[1]);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- //Calculates the bar length based on number of individual bar codes
- final int singleModule = (width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
-
- left = left.roundToDouble();
- positions[0] = left + ratio;
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- final bool hasExtraHeight = _getHasExtraHeight(i, code);
- final double additionalHeight = i == code.length - 4 ? 0.4 : 0.5;
- final double barHeight = hasExtraHeight
- ? size.height +
- (showValue
- ? (_textSize.height * additionalHeight) + textSpacing
- : 0)
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- final bool canDraw = codeValue[j] == '1' ? true : false;
- if (canDraw &&
- (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
- left += ratio;
-
- if (i == 0 && j == codeLength - 1) {
- // Calculates the left value for the first input digit
- singleDigitValues[0] = left - singleDigitValues[1];
- } else if (i == 1 && j == codeLength - 1) {
- // Finds the end position of first extra height bar
- positions[0] = left;
- } else if (i == 3 && j == 0) {
- // Finds the start position of second extra height bar
- positions[1] = left;
- } else if (i == 3 && j == codeLength - 1) {
- // Finds the end position of second extra height bar
- positions[2] = left;
- } else if (i == 4 && j == codeLength - 1) {
- // Finds the start position of third extra height bar
- positions[3] = left;
- } else if (i == 5 && j == codeLength - 1) {
- // Finds the end position of fourth extra height bar
- singleDigitValues[2] = left + additionalWidth;
- }
- }
- }
-
- if (showValue) {
- _paintText(canvas, offset, size, _encodedValue, textStyle, textSpacing,
- textAlign, positions, singleDigitValues);
- }
- }
-
- /// Calculate total bar length from give input value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final int numberOfDigits = code[i].length;
- count += numberOfDigits;
- }
- return count;
- }
-
- /// Returns the encoded value
- List _getCodeValues() {
- const String endDigits = '00000000';
- const String middleBar = '01010';
- final List code = [];
- code.add(endDigits);
- code.add('101' + _getLeftValue(true, 'L', _encodedValue[0]));
- code.add(_getLeftValue(true, 'LLLLL', _encodedValue.substring(1, 6)));
- code.add(middleBar);
- code.add(_getLeftValue(true, 'RRRRR', _encodedValue.substring(6, 11)));
- code.add(_getLeftValue(true, 'R', _encodedValue[11]) + '101');
- code.add(endDigits);
- return code;
- }
-
- /// Returns the binary values for the supported input symbol
- Map> _getBinaries() {
- final Map> codes = >{
- 'L': [
- '0001101',
- '0011001',
- '0010011',
- '0111101',
- '0100011',
- '0110001',
- '0101111',
- '0111011',
- '0110111',
- '0001011'
- ],
- 'R': [
- '1110010',
- '1100110',
- '1101100',
- '1000010',
- '1011100',
- '1001110',
- '1010000',
- '1000100',
- '1001000',
- '1110100'
- ]
- };
-
- return codes;
- }
-
- /// Returns the encoded value of digits present at left side
- String _getLeftValue(bool isLeft, String structure, String leftString) {
- String code;
- List tempValue;
- final Map> codes = _getBinaries();
- for (int i = 0; i < leftString.length; i++) {
- if (structure[i] == 'R') {
- tempValue = codes.entries.elementAt(1).value;
- } else {
- tempValue = codes.entries.elementAt(0).value;
- }
-
- final int currentValue = int.parse(leftString[i]);
- if (i == 0) {
- code = tempValue[currentValue];
- } else {
- code += tempValue[currentValue];
- }
- }
- return code;
- }
-
- /// Method to calculate the check sum digit
- int _getCheckSumData(String value) {
- final int sum1 = 3 *
- (int.parse(value[0]) +
- int.parse(value[2]) +
- int.parse(value[4]) +
- int.parse(value[6]) +
- int.parse(value[8]) +
- int.parse(value[10]));
- final int sum2 = int.parse(value[9]) +
- int.parse(value[7]) +
- int.parse(value[5]) +
- int.parse(value[3]) +
- int.parse(value[1]);
- final int checkSumValue = sum1 + sum2;
- return (10 - checkSumValue % 10) % 10;
- }
-
- /// Method to render the input value of the barcode
- void _paintText(
- Canvas canvas,
- Offset offset,
- Size size,
- String value,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- List positions,
- List singleDigitValues) {
- final String value1 = value[0];
- final String value2 = value.substring(1, 6);
- final String value3 = value.substring(6, 11);
-
- final double secondTextWidth = positions[1] - positions[0];
- final double thirdTextWidth = positions[3] - positions[2];
-
- // Renders the first digit of encoded value
- _drawText(
- canvas,
- Offset(singleDigitValues[0], offset.dy + size.height + textSpacing),
- Size(singleDigitValues[1], size.height),
- value1,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
-
- // Renders the first five digits of encoded input value
- _drawText(
- canvas,
- Offset(positions[0], offset.dy),
- Size(secondTextWidth, size.height),
- value2,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
-
- // Renders the second five digits of encoded input value
- _drawText(
- canvas,
- Offset(positions[2], offset.dy),
- Size(thirdTextWidth, size.height),
- value3,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
-
- // Renders the last digit of the encoded input value
- _drawText(
- canvas,
- Offset(singleDigitValues[2], offset.dy + size.height + textSpacing),
- Size(singleDigitValues[3], size.height),
- value[value.length - 1],
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upce_symbology.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upce_symbology.dart
index dff31bdb7..f97dbc34d 100644
--- a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upce_symbology.dart
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/one_dimensional/upce_symbology.dart
@@ -1,4 +1,4 @@
-part of barcodes;
+import '../base/symbology_base.dart';
/// As with [UPCA], the [UPCE] symbology supports only numeric characters.
///
@@ -17,313 +17,4 @@ class UPCE extends Symbology {
/// at the end along with 6 digits of the input product code.
///
UPCE({int module}) : super(module: module);
-
- /// Represents the encoded input value
- String _encodedValue;
-
- @override
- bool _getIsValidateInput(String value) {
- if (value.contains(RegExp(r'^(?=.*?[0-9]).{6}$'))) {
- return true;
- }
- throw 'UPCE supports only numeric characters. '
- 'The provided value should have 6 digits.';
- }
-
- /// This is quite a large method. This method could not be
- /// refactored to a smaller methods, since it requires multiple parameters
- /// to be passed
- @override
- void _renderBarcode(
- Canvas canvas,
- Size size,
- Offset offset,
- String value,
- Color foregroundColor,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- bool showValue) {
- final Paint paint = _getBarPaint(foregroundColor);
- final List code = _getCodeValues(value);
- final int barTotalLength = _getTotalLength(code);
-
- /// _singleDigitValues[0] specifies left value of start digit
- /// _singleDigitValues[1] specifies width of start digit
- /// _singleDigitValues[2] specifies left value of end digit
- /// _singleDigitValues[3] specifies width of end digit
- final List singleDigitValues = List(4);
-
- /// _positions[0] specifies end position of start bar
- /// _positions[1] specifies start position of end bar
- final List positions = List(2);
- const int additionalWidth = 2;
- if (showValue) {
- singleDigitValues[1] = _measureText('0', textStyle).width;
- singleDigitValues[1] += additionalWidth;
- singleDigitValues[3] =
- _measureText(_encodedValue[_encodedValue.length - 1], textStyle)
- .width;
- singleDigitValues[3] += additionalWidth;
- } else {
- singleDigitValues[1] = singleDigitValues[3] = 0;
- }
-
- final double width =
- size.width - (singleDigitValues[1] + singleDigitValues[3]);
- double left = module == null
- ? offset.dx
- : _getLeftPosition(
- barTotalLength, module, width, offset.dx + singleDigitValues[1]);
- final Rect barCodeRect = Rect.fromLTRB(
- offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
- double ratio = 0;
- if (module != null) {
- ratio = module.toDouble();
- } else {
- //Calculates the bar length based on number of individual bar codes
- final int singleModule = (width ~/ barTotalLength).toInt();
- ratio = singleModule.toDouble();
- final double leftPadding = (width - (barTotalLength * ratio)) / 2;
- left += leftPadding;
- }
- left = left.roundToDouble();
- for (int i = 0; i < code.length; i++) {
- final String codeValue = code[i];
- final bool hasExtraHeight = _getHasExtraHeight(i, code);
- final double barHeight = hasExtraHeight
- ? size.height +
- (showValue ? (_textSize.height * 0.5) + textSpacing : 0)
- : size.height;
- final int codeLength = codeValue.length;
- for (int j = 0; j < codeLength; j++) {
- final bool canDraw = codeValue[j] == '1' ? true : false;
- if (canDraw &&
- (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
- final Rect individualBarRect = Rect.fromLTRB(
- left, offset.dy, left + ratio, offset.dy + barHeight);
- canvas.drawRect(individualBarRect, paint);
- }
-
- left += ratio;
-
- // Calculates the left value for first digit
- if (i == 0 && j == codeLength - 1) {
- singleDigitValues[0] = left - singleDigitValues[1];
- } else if (i == 1 && j == codeLength - 1) {
- // Calculates the start position of intermediate bars
- positions[0] = left;
- } else if (i == 3 && j == 0) {
- // Calculates the end position of intermediate bars
- positions[1] = left;
- } else if (i == 3 && j == codeLength - 1) {
- // Calculates the left value of last digit
- singleDigitValues[2] = left + additionalWidth;
- }
- }
- }
- if (showValue) {
- _paintText(canvas, offset, size, _encodedValue, textStyle, textSpacing,
- textAlign, positions, singleDigitValues);
- }
- }
-
- /// Method to render the input value of the barcode
- void _paintText(
- Canvas canvas,
- Offset offset,
- Size size,
- String value,
- TextStyle textStyle,
- double textSpacing,
- TextAlign textAlign,
- List positions,
- List singleDigitValues) {
- const String value1 = '0';
- final String value2 = value.substring(1, 7);
-
- final double secondTextWidth = positions[1] - positions[0];
-
- // Renders the first digit of encoded value
- _drawText(
- canvas,
- Offset(singleDigitValues[0], offset.dy + size.height + textSpacing),
- Size(singleDigitValues[1], size.height),
- value1,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
- //Renders the middle six digits of encoded value
- _drawText(
- canvas,
- Offset(positions[0], offset.dy),
- Size(secondTextWidth, size.height),
- value2,
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
- // Renders the last digit of encoded value
- _drawText(
- canvas,
- Offset(singleDigitValues[2], offset.dy + size.height + textSpacing),
- Size(singleDigitValues[3], size.height),
- value[value.length - 1],
- textStyle,
- textSpacing,
- textAlign,
- offset,
- size);
- }
-
- /// Calculate the total length from given value
- int _getTotalLength(List code) {
- int count = 0;
- for (int i = 0; i < code.length; i++) {
- final int numberOfDigits = code[i].length;
- count += numberOfDigits;
- }
- return count;
- }
-
- /// Method to calculate the check sum value
- num _getCheckSum(String value) {
- num result = 0;
- for (int i = 1; i < 11; i += 2) {
- result += int.parse(value[i]);
- }
- for (int i = 0; i < 11; i += 2) {
- result += int.parse(value[i]) * 3;
- }
- return (10 - (result % 10)) % 10;
- }
-
- /// Returns the supported symbol and its pattern value
- Map _getStructure() {
- final Map upceSymbology = {
- '0': 'EEEOOO',
- '1': 'EEOEOO',
- '2': 'EEOOEO',
- '3': 'EEOOOE',
- '4': 'EOEEOO',
- '5': 'EOOEEO',
- '6': 'EOOOEE',
- '7': 'EOEOEO',
- '8': 'EOEOOE',
- '9': 'EOOEOE'
- };
- return upceSymbology;
- }
-
- /// Returns the byte value for the supported symbol
- List _getValue() {
- return [
- 'XX00000XXX',
- 'XX10000XXX',
- 'XX20000XXX',
- 'XXX00000XX',
- 'XXXX00000X',
- 'XXXXX00005',
- 'XXXXX00006',
- 'XXXXX00007',
- 'XXXXX00008',
- 'XXXXX00009'
- ];
- }
-
- /// Returns the value for the last digit
- String _getExpansion(String lastDigit) {
- final List value = _getValue();
- final int index = int.parse(lastDigit);
- return value[index];
- }
-
- /// Returns the calculated UPC value
- String _getUPCValue(String value) {
- final String lastDigit = value[value.length - 1];
- final String expansionValue = _getExpansion(lastDigit);
- String result = '';
- num index = 0;
- for (int i = 0; i < expansionValue.length; i++) {
- final String actualValue = expansionValue[i];
- if (actualValue == 'X') {
- result += value[index++];
- } else {
- result += actualValue;
- }
- }
- result = '0' + result;
- String encodingValue = '' + result;
- final String checkSumValue = _getCheckSum(result).toString();
- encodingValue += checkSumValue;
- _encodedValue = '0' + value + checkSumValue;
- return encodingValue;
- }
-
- /// Returns the binary values of the supported symbol
- Map> _getBinaries() {
- return >{
- 'O': [
- '0001101',
- '0011001',
- '0010011',
- '0111101',
- '0100011',
- '0110001',
- '0101111',
- '0111011',
- '0110111',
- '0001011'
- ],
- 'E': [
- // The E (even) encoding for UPC-E
- '0100111', '0110011', '0011011', '0100001', '0011101',
- '0111001', '0000101', '0010001', '0001001', '0010111'
- ]
- };
- }
-
- /// Returns the encoded input value
- String _encoding(String upceValue, String value, String structure) {
- String code = '';
- List tempValue;
- final Map> codes = _getBinaries();
- for (int i = 0; i < value.length; i++) {
- if (structure[i] == 'E') {
- tempValue = codes.entries.elementAt(1).value;
- } else {
- tempValue = codes.entries.elementAt(0).value;
- }
- if (i == 0) {
- final int index = int.parse(value[i]);
- code = tempValue[index];
- } else {
- final int index = int.parse(value[i]);
- code += tempValue[index];
- }
- }
- return code;
- }
-
- /// Returns the encoded value
- List _getCodeValues(String value) {
- const String endBars = '101';
- const String middleBar = '010101';
- const String endDigits = '00000000';
- final List code = [];
- final String upceValue = _getUPCValue(value);
- final Map structureValue = _getStructure();
- final int actualValue = int.parse(upceValue[upceValue.length - 1]);
- final String structure =
- structureValue.entries.elementAt(actualValue).value;
- code.add(endDigits);
- code.add(endBars);
- code.add(_encoding(upceValue, value, structure));
- code.add(middleBar);
- code.add(endDigits);
- return code;
- }
}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/renderers/one_dimensional/codabar_renderer.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/renderers/one_dimensional/codabar_renderer.dart
new file mode 100644
index 000000000..5b1072cc7
--- /dev/null
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/renderers/one_dimensional/codabar_renderer.dart
@@ -0,0 +1,143 @@
+import 'dart:ui';
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import '../../base/symbology_base.dart';
+import 'symbology_base_renderer.dart';
+
+/// Represents codabar renderer
+class CodabarRenderer extends SymbologyRenderer {
+ /// Creates codabar renderer class
+ CodabarRenderer({Symbology symbology}) : super(symbology: symbology) {
+ _codeBarMap = {
+ '0': '101010011',
+ '1': '101011001',
+ '2': '101001011',
+ '3': '110010101',
+ '4': '101101001',
+ '5': '110101001',
+ '6': '100101011',
+ '7': '100101101',
+ '8': '100110101',
+ '9': '110100101',
+ '-': '101001101',
+ '\$': '101100101',
+ ':': '1101011011',
+ '/': '1101101011',
+ '.': '1101101101',
+ '+': '101100110011',
+ 'A': '1011001001',
+ 'B': '1001001011',
+ 'C': '1010010011',
+ 'D': '1010011001'
+ };
+ }
+
+ /// Represents the supported symbol and its byte value
+ Map _codeBarMap;
+
+ @override
+ bool getIsValidateInput(String value) {
+ for (int i = 0; i < value.length; i++) {
+ if (!_codeBarMap.containsKey(value[i]) ||
+ value[i] == 'A' ||
+ value[i] == 'B' ||
+ value[i] == 'C' ||
+ value[i] == 'D') {
+ throw 'The provided input cannot be encoded : ' + value[i];
+ }
+ }
+ return true;
+ }
+
+ @override
+ void renderBarcode(
+ Canvas canvas,
+ Size size,
+ Offset offset,
+ String value,
+ Color foregroundColor,
+ TextStyle textStyle,
+ double textSpacing,
+ TextAlign textAlign,
+ bool showValue) {
+ final Paint paint = getBarPaint(foregroundColor);
+ final List code = _getCodeValues(value);
+ final int barTotalLength = _getTotalLength(code);
+ double left = symbology.module == null
+ ? offset.dx
+ : getLeftPosition(
+ barTotalLength, symbology.module, size.width, offset.dx);
+ final Rect barCodeRect = Rect.fromLTRB(
+ offset.dx, offset.dy, offset.dx + size.width, offset.dy + size.height);
+ double ratio = 0;
+ if (symbology.module != null) {
+ ratio = symbology.module.toDouble();
+ } else {
+ // Calculates the bar length based on number of individual bar codes
+ final int singleModule = (size.width ~/ barTotalLength).toInt();
+ ratio = singleModule.toDouble();
+ final double leftPadding = (size.width - (barTotalLength * ratio)) / 2;
+ left += leftPadding;
+ }
+ left = left.roundToDouble();
+ for (int i = 0; i < code.length; i++) {
+ final String codeValue = code[i];
+ const bool hasExtraHeight = false;
+ final double barHeight = hasExtraHeight
+ ? size.height + textSize.height + textSpacing
+ : size.height;
+ final int codeLength = codeValue.length;
+ for (int j = 0; j < codeLength; j++) {
+ final bool canDraw = codeValue[j] == '1' ? true : false;
+
+ // Draws the barcode when the corresponding bar value is one
+ if (canDraw &&
+ (left >= barCodeRect.left && left + ratio < barCodeRect.right)) {
+ final Rect individualBarRect = Rect.fromLTRB(
+ left, offset.dy, left + ratio, offset.dy + barHeight);
+ canvas.drawRect(individualBarRect, paint);
+ }
+ left += ratio;
+ }
+ if (i < code.length - 1) {
+ left += ratio;
+ }
+ }
+ if (showValue) {
+ drawText(canvas, offset, size, value, textStyle, textSpacing, textAlign);
+ }
+ }
+
+ /// Calculate total bar length from give input value
+ int _getTotalLength(List code) {
+ int count = 0;
+ for (int i = 0; i < code.length; i++) {
+ final int numberOfDigits = code[i].length;
+ count += numberOfDigits;
+ }
+ count += code.length - 1;
+ return count;
+ }
+
+ /// Method to append the start and the stop symbol
+ String _getValueWithStartAndStopSymbol(String value) {
+ return 'A' + value + 'A';
+ }
+
+ /// Returns the encoded value of the provided input value
+ List _getCodeValues(String value) {
+ valueWithStartAndStopSymbol = _getValueWithStartAndStopSymbol(value);
+ final List codeBarValues =
+ List(valueWithStartAndStopSymbol.length);
+ for (int i = 0; i < valueWithStartAndStopSymbol.length; i++) {
+ for (int j = 0; j < _codeBarMap.length; j++) {
+ if (valueWithStartAndStopSymbol[i] ==
+ _codeBarMap.entries.elementAt(j).key) {
+ codeBarValues[i] = _codeBarMap.entries.elementAt(j).value;
+ break;
+ }
+ }
+ }
+ return codeBarValues;
+ }
+}
diff --git a/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/renderers/one_dimensional/code128_renderer.dart b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/renderers/one_dimensional/code128_renderer.dart
new file mode 100644
index 000000000..a70e5adf9
--- /dev/null
+++ b/packages/syncfusion_flutter_barcodes/lib/src/barcode_generator/renderers/one_dimensional/code128_renderer.dart
@@ -0,0 +1,689 @@
+import 'dart:ui';
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import '../../base/symbology_base.dart';
+import '../../one_dimensional/code128b_symbology.dart';
+import '../../one_dimensional/code128c_symbology.dart';
+import '../../utils/enum.dart';
+import 'symbology_base_renderer.dart';
+
+/// Represents the code128 renderer class
+class Code128Renderer extends SymbologyRenderer {
+ /// Creates the code128 renderer
+ Code128Renderer({Symbology symbology}) : super(symbology: symbology) {
+ code128ACharacterSets = [];
+
+ code128ACharacterSets.add(' ');
+ code128ACharacterSets.add('!');
+ code128ACharacterSets.add('"');
+ code128ACharacterSets.add('#');
+ code128ACharacterSets.add('\$');
+ code128ACharacterSets.add('%');
+ code128ACharacterSets.add('&');
+ code128ACharacterSets.add('\'');
+ code128ACharacterSets.add('(');
+ code128ACharacterSets.add(')');
+ code128ACharacterSets.add('*');
+ code128ACharacterSets.add('+');
+ code128ACharacterSets.add(',');
+ code128ACharacterSets.add('-');
+ code128ACharacterSets.add('.');
+ code128ACharacterSets.add('/');
+ code128ACharacterSets.add('0');
+ code128ACharacterSets.add('1');
+ code128ACharacterSets.add('2');
+ code128ACharacterSets.add('3');
+ code128ACharacterSets.add('4');
+ code128ACharacterSets.add('5');
+ code128ACharacterSets.add('6');
+ code128ACharacterSets.add('7');
+ code128ACharacterSets.add('8');
+ code128ACharacterSets.add('9');
+ code128ACharacterSets.add(':');
+ code128ACharacterSets.add(';');
+ code128ACharacterSets.add('<');
+ code128ACharacterSets.add('=');
+ code128ACharacterSets.add('>');
+ code128ACharacterSets.add('?');
+ code128ACharacterSets.add('@');
+ code128ACharacterSets.add('A');
+ code128ACharacterSets.add('B');
+ code128ACharacterSets.add('C');
+ code128ACharacterSets.add('D');
+ code128ACharacterSets.add('E');
+ code128ACharacterSets.add('F');
+ code128ACharacterSets.add('G');
+ code128ACharacterSets.add('H');
+ code128ACharacterSets.add('I');
+ code128ACharacterSets.add('J');
+ code128ACharacterSets.add('K');
+ code128ACharacterSets.add('L');
+ code128ACharacterSets.add('M');
+ code128ACharacterSets.add('N');
+ code128ACharacterSets.add('O');
+ code128ACharacterSets.add('P');
+ code128ACharacterSets.add('Q');
+ code128ACharacterSets.add('R');
+ code128ACharacterSets.add('S');
+ code128ACharacterSets.add('T');
+ code128ACharacterSets.add('U');
+ code128ACharacterSets.add('V');
+ code128ACharacterSets.add('W');
+ code128ACharacterSets.add('X');
+ code128ACharacterSets.add('Y');
+ code128ACharacterSets.add('Z');
+ code128ACharacterSets.add('[');
+ code128ACharacterSets.add('\\');
+ code128ACharacterSets.add(']');
+ code128ACharacterSets.add('^');
+ code128ACharacterSets.add('_');
+ code128ACharacterSets.add('\0');
+ code128ACharacterSets.add('\u0001');
+ code128ACharacterSets.add('\u0002');
+ code128ACharacterSets.add('\u0003');
+ code128ACharacterSets.add('\u0004');
+ code128ACharacterSets.add('\u0005');
+ code128ACharacterSets.add('\u0006');
+ code128ACharacterSets.add('\a');
+ code128ACharacterSets.add('\b');
+ code128ACharacterSets.add('\t');
+ code128ACharacterSets.add('\n');
+ code128ACharacterSets.add('\v');
+ code128ACharacterSets.add('\f');
+ code128ACharacterSets.add('\r');
+ code128ACharacterSets.add('\u000e');
+ code128ACharacterSets.add('\u000f');
+ code128ACharacterSets.add('\u0010');
+ code128ACharacterSets.add('\u0011');
+ code128ACharacterSets.add('\u0012');
+ code128ACharacterSets.add('\u0013');
+ code128ACharacterSets.add('\u0014');
+ code128ACharacterSets.add('\u0015');
+ code128ACharacterSets.add('\u0016');
+ code128ACharacterSets.add('\u0017');
+ code128ACharacterSets.add('\u0018');
+ code128ACharacterSets.add('\u0019');
+ code128ACharacterSets.add('\u001a');
+ code128ACharacterSets.add('\u001b');
+ code128ACharacterSets.add('\u001c');
+ code128ACharacterSets.add('\u001d');
+ code128ACharacterSets.add('\u001e');
+ code128ACharacterSets.add('\u001f');
+ code128ACharacterSets.add('ù');
+ code128ACharacterSets.add('ø');
+ code128ACharacterSets.add('û');
+ code128ACharacterSets.add('ö');
+ code128ACharacterSets.add('õ');
+ code128ACharacterSets.add('ú');
+ code128ACharacterSets.add('÷');
+ code128ACharacterSets.add('ü');
+ code128ACharacterSets.add('ý');
+ code128ACharacterSets.add('þ');
+ code128ACharacterSets.add('ÿ');
+
+ code128BCharacterSets = [];
+ code128BCharacterSets.add(' ');
+ code128BCharacterSets.add('!');
+ code128BCharacterSets.add('"');
+ code128BCharacterSets.add('#');
+ code128BCharacterSets.add('\$');
+ code128BCharacterSets.add('%');
+ code128BCharacterSets.add('&');
+ code128BCharacterSets.add('\'');
+ code128BCharacterSets.add('(');
+ code128BCharacterSets.add(')');
+ code128BCharacterSets.add('*');
+ code128BCharacterSets.add('+');
+ code128BCharacterSets.add(',');
+ code128BCharacterSets.add('-');
+ code128BCharacterSets.add('.');
+ code128BCharacterSets.add('/');
+ code128BCharacterSets.add('0');
+ code128BCharacterSets.add('1');
+ code128BCharacterSets.add('2');
+ code128BCharacterSets.add('3');
+ code128BCharacterSets.add('4');
+ code128BCharacterSets.add('5');
+ code128BCharacterSets.add('6');
+ code128BCharacterSets.add('7');
+ code128BCharacterSets.add('8');
+ code128BCharacterSets.add('9');
+ code128BCharacterSets.add(':');
+ code128BCharacterSets.add(';');
+ code128BCharacterSets.add('<');
+ code128BCharacterSets.add('=');
+ code128BCharacterSets.add('>');
+ code128BCharacterSets.add('?');
+ code128BCharacterSets.add('@');
+ code128BCharacterSets.add('A');
+ code128BCharacterSets.add('B');
+ code128BCharacterSets.add('C');
+ code128BCharacterSets.add('D');
+ code128BCharacterSets.add('E');
+ code128BCharacterSets.add('F');
+ code128BCharacterSets.add('G');
+ code128BCharacterSets.add('H');
+ code128BCharacterSets.add('I');
+ code128BCharacterSets.add('J');
+ code128BCharacterSets.add('K');
+ code128BCharacterSets.add('L');
+ code128BCharacterSets.add('M');
+ code128BCharacterSets.add('N');
+ code128BCharacterSets.add('O');
+ code128BCharacterSets.add('P');
+ code128BCharacterSets.add('Q');
+ code128BCharacterSets.add('R');
+ code128BCharacterSets.add('S');
+ code128BCharacterSets.add('T');
+ code128BCharacterSets.add('U');
+ code128BCharacterSets.add('V');
+ code128BCharacterSets.add('W');
+ code128BCharacterSets.add('X');
+ code128BCharacterSets.add('Y');
+ code128BCharacterSets.add('Z');
+ code128BCharacterSets.add('[');
+ code128BCharacterSets.add('\\');
+ code128BCharacterSets.add(']');
+ code128BCharacterSets.add('^');
+ code128BCharacterSets.add('_');
+ code128BCharacterSets.add('`');
+ code128BCharacterSets.add('a');
+ code128BCharacterSets.add('b');
+ code128BCharacterSets.add('c');
+ code128BCharacterSets.add('d');
+ code128BCharacterSets.add('e');
+ code128BCharacterSets.add('f');
+ code128BCharacterSets.add('g');
+ code128BCharacterSets.add('h');
+ code128BCharacterSets.add('i');
+ code128BCharacterSets.add('j');
+ code128BCharacterSets.add('k');
+ code128BCharacterSets.add('l');
+ code128BCharacterSets.add('m');
+ code128BCharacterSets.add('n');
+ code128BCharacterSets.add('o');
+ code128BCharacterSets.add('p');
+ code128BCharacterSets.add('q');
+ code128BCharacterSets.add('r');
+ code128BCharacterSets.add('s');
+ code128BCharacterSets.add('t');
+ code128BCharacterSets.add('u');
+ code128BCharacterSets.add('v');
+ code128BCharacterSets.add('w');
+ code128BCharacterSets.add('x');
+ code128BCharacterSets.add('y');
+ code128BCharacterSets.add('z');
+ code128BCharacterSets.add('{');
+ code128BCharacterSets.add('|');
+ code128BCharacterSets.add('}');
+ code128BCharacterSets.add('~');
+ code128BCharacterSets.add('\u007f');
+ code128BCharacterSets.add('ù');
+ code128BCharacterSets.add('ø');
+ code128BCharacterSets.add('û');
+ code128BCharacterSets.add('ö');
+ code128BCharacterSets.add('ú');
+ code128BCharacterSets.add('ô');
+ code128BCharacterSets.add('÷');
+ code128BCharacterSets.add('ü');
+ code128BCharacterSets.add('ý');
+ code128BCharacterSets.add('þ');
+ code128BCharacterSets.add('ÿ');
+
+ code128CCharacterSets = [];
+ code128CCharacterSets.add('0');
+ code128CCharacterSets.add('1');
+ code128CCharacterSets.add('2');
+ code128CCharacterSets.add('3');
+ code128CCharacterSets.add('4');
+ code128CCharacterSets.add('5');
+ code128CCharacterSets.add('6');
+ code128CCharacterSets.add('7');
+ code128CCharacterSets.add('8');
+ code128CCharacterSets.add('9');
+ code128CCharacterSets.add('õ');
+ code128CCharacterSets.add('ô');
+ code128CCharacterSets.add('÷');
+ code128CCharacterSets.add('ü');
+ code128CCharacterSets.add('ý');
+ code128CCharacterSets.add('þ');
+ code128CCharacterSets.add('ÿ');
+ }
+
+ /// Represents the start symbol of code128A
+ static const int _codeAStartSymbol = 103;
+
+ /// Represents the start symbol for Code128B
+ static const int _codeBStartSymbol = 104;
+
+ /// Represents the start symbol for Code128C
+ static const int _codeCStartSymbol = 105;
+
+ /// Specifies the value for code128A
+ static const int _codeA = 101;
+
+ /// Specifies the value for code128B
+ static const int _codeB = 100;
+
+ /// Specifies the value for code128C
+ static const int _codeC = 99;
+
+ /// Specifies the stop symbol
+ static const int _codeStopSymbol = 106;
+
+ /// Represents the index value of FNC1 special character
+ static const int _codeFNC1 = 102;
+
+ /// Represents the index value of FNC2 special character
+ static const int _codeFNC2 = 97;
+
+ /// Represents the index value of FNC3 special character
+ static const int _codeFNC3 = 96;
+
+ /// Represents the index value of FNC4A special character
+ static const int _codeFNC4A = 101;
+
+ /// Represents the index value of FNC4B special character
+ static const int _codeFNC4B = 100;
+
+ /// Represents the FNC1 special character
+ static const String _fnc1 = '\u00f1';
+
+ /// Represents the FNC2 special character
+ static const String _fnc2 = '\u00f2';
+
+ /// Represents the FNC3 special character
+ static const String _fnc3 = '\u00f3';
+
+ /// Represents the FNC4 special character
+ static const String _fnc4 = '\u00f4';
+
+ /// Represents the supported symbol character of code128A
+ List code128ACharacterSets;
+
+ /// Represents the supported symbol character of code128B
+ List