Commit 8d35d61e authored by Andrey's avatar Andrey

PosColumn : assert replaced by Exception. PosRowException replaced by generic Exception.

parent 315e90c1
...@@ -83,3 +83,4 @@ printer.printRow([ ...@@ -83,3 +83,4 @@ printer.printRow([
* Flutter example: print a demo receipt * Flutter example: print a demo receipt
* Flutter example: discover active Wi-Fi printers * Flutter example: discover active Wi-Fi printers
* USB, Bluetooth printers support * USB, Bluetooth printers support
* Add encoding commands
\ No newline at end of file
...@@ -7,6 +7,5 @@ ...@@ -7,6 +7,5 @@
library esc_pos_printer; library esc_pos_printer;
export './src/enums.dart'; export './src/enums.dart';
export './src/exceptions.dart';
export './src/pos_styles.dart'; export './src/pos_styles.dart';
export './src/printer.dart'; export './src/printer.dart';
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
/// Used by [Printer.printRow] method
class PosRowException implements Exception {
PosRowException(this._msg);
String _msg;
@override
String toString() => 'PosRowException: $_msg';
}
...@@ -14,7 +14,11 @@ class PosColumn { ...@@ -14,7 +14,11 @@ class PosColumn {
this.text = '', this.text = '',
this.width = 2, this.width = 2,
this.styles = const PosStyles(), this.styles = const PosStyles(),
}) : assert(width >= 1 && width <= 12); }) {
if (width < 1 || width > 12) {
throw Exception('Column width must be between 1..12');
}
}
String text; String text;
int width; int width;
......
...@@ -11,7 +11,6 @@ import 'dart:typed_data'; ...@@ -11,7 +11,6 @@ import 'dart:typed_data';
import 'package:hex/hex.dart'; import 'package:hex/hex.dart';
import 'commands.dart'; import 'commands.dart';
import 'enums.dart'; import 'enums.dart';
import 'exceptions.dart';
import 'pos_column.dart'; import 'pos_column.dart';
import 'pos_styles.dart'; import 'pos_styles.dart';
...@@ -99,7 +98,7 @@ class Printer { ...@@ -99,7 +98,7 @@ class Printer {
void printRow(List<PosColumn> cols) { void printRow(List<PosColumn> cols) {
final validSum = cols.fold(0, (int sum, col) => sum + col.width) == 12; final validSum = cols.fold(0, (int sum, col) => sum + col.width) == 12;
if (!validSum) { if (!validSum) {
throw PosRowException('Total columns width must be equal to 12'); throw Exception('Total columns width must be equal to 12');
} }
for (int i = 0; i < cols.length; ++i) { for (int i = 0; i < cols.length; ++i) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment