Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Enums for simplify the use of Size and Alignment #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions example/lib/printerenum.dart

This file was deleted.

35 changes: 18 additions & 17 deletions example/lib/testprint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:blue_thermal_printer_example/printerenum.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'package:blue_thermal_printer/blue_thermal_printer.dart';
import 'package:blue_thermal_printer/enums/enums_export.dart';
import 'dart:io';
import 'package:http/http.dart' as http;

Expand Down Expand Up @@ -35,44 +36,44 @@ class TestPrint {
bluetooth.isConnected.then((isConnected) {
if (isConnected == true) {
bluetooth.printNewLine();
bluetooth.printCustom("HEADER", Size.boldMedium.val, Align.center.val);
bluetooth.printCustom("HEADER", Size.boldMedium, Align.center);
bluetooth.printNewLine();
bluetooth.printImage(file.path); //path of your image/logo
bluetooth.printNewLine();
bluetooth.printImageBytes(imageBytesFromAsset); //image from Asset
bluetooth.printNewLine();
bluetooth.printImageBytes(imageBytesFromNetwork); //image from Network
bluetooth.printNewLine();
bluetooth.printLeftRight("LEFT", "RIGHT", Size.medium.val);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.bold.val);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.bold.val,
bluetooth.printLeftRight("LEFT", "RIGHT", Size.medium);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.bold);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.bold,
format:
"%-15s %15s %n"); //15 is number off character from left or right
bluetooth.printNewLine();
bluetooth.printLeftRight("LEFT", "RIGHT", Size.boldMedium.val);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.boldLarge.val);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.extraLarge.val);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.boldMedium);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.boldLarge);
bluetooth.printLeftRight("LEFT", "RIGHT", Size.extraLarge);
bluetooth.printNewLine();
bluetooth.print3Column("Col1", "Col2", "Col3", Size.bold.val);
bluetooth.print3Column("Col1", "Col2", "Col3", Size.bold.val,
bluetooth.print3Column("Col1", "Col2", "Col3", Size.bold);
bluetooth.print3Column("Col1", "Col2", "Col3", Size.bold,
format:
"%-10s %10s %10s %n"); //10 is number off character from left center and right
bluetooth.printNewLine();
bluetooth.print4Column("Col1", "Col2", "Col3", "Col4", Size.bold.val);
bluetooth.print4Column("Col1", "Col2", "Col3", "Col4", Size.bold.val,
bluetooth.print4Column("Col1", "Col2", "Col3", "Col4", Size.bold);
bluetooth.print4Column("Col1", "Col2", "Col3", "Col4", Size.bold,
format: "%-8s %7s %7s %7s %n");
bluetooth.printNewLine();
bluetooth.printCustom("čĆžŽšŠ-H-ščđ", Size.bold.val, Align.center.val,
bluetooth.printCustom("čĆžŽšŠ-H-ščđ", Size.bold, Align.center,
charset: "windows-1250");
bluetooth.printLeftRight("Številka:", "18000001", Size.bold.val,
bluetooth.printLeftRight("Številka:", "18000001", Size.bold,
charset: "windows-1250");
bluetooth.printCustom("Body left", Size.bold.val, Align.left.val);
bluetooth.printCustom("Body right", Size.medium.val, Align.right.val);
bluetooth.printCustom("Body left", Size.bold, Align.left);
bluetooth.printCustom("Body right", Size.medium, Align.right);
bluetooth.printNewLine();
bluetooth.printCustom("Thank You", Size.bold.val, Align.center.val);
bluetooth.printCustom("Thank You", Size.bold, Align.center);
bluetooth.printNewLine();
bluetooth.printQRcode(
"Insert Your Own Text to Generate", 200, 200, Align.center.val);
"Insert Your Own Text to Generate", 200, 200, Align.center);
bluetooth.printNewLine();
bluetooth.printNewLine();
bluetooth
Expand Down
19 changes: 10 additions & 9 deletions lib/blue_thermal_printer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:typed_data';
import 'enums/enums_export.dart';

import 'package:flutter/services.dart';

Expand Down Expand Up @@ -90,12 +91,12 @@ class BlueThermalPrinter {
_channel.invokeMethod('writeBytes', {'message': message});

///printCustom(String message, int size, int align,{String? charset})
Future<dynamic> printCustom(String message, int size, int align,
Future<dynamic> printCustom(String message, Size size, Align align,
{String? charset}) =>
_channel.invokeMethod('printCustom', {
'message': message,
'size': size,
'align': align,
'size': size.value,
'align': align.value,
'charset': charset
});

Expand Down Expand Up @@ -130,39 +131,39 @@ class BlueThermalPrinter {
});

///printLeftRight(String string1, String string2, int size,{String? charset, String? format})
Future<dynamic> printLeftRight(String string1, String string2, int size,
Future<dynamic> printLeftRight(String string1, String string2, Size size,
{String? charset, String? format}) =>
_channel.invokeMethod('printLeftRight', {
'string1': string1,
'string2': string2,
'size': size,
'size': size.value,
'charset': charset,
'format': format
});

///print3Column(String string1, String string2, String string3, int size,{String? charset, String? format})
Future<dynamic> print3Column(
String string1, String string2, String string3, int size,
String string1, String string2, String string3, Size size,
{String? charset, String? format}) =>
_channel.invokeMethod('print3Column', {
'string1': string1,
'string2': string2,
'string3': string3,
'size': size,
'size': size.value,
'charset': charset,
'format': format
});

///print4Column(String string1, String string2, String string3,String string4, int size,{String? charset, String? format})
Future<dynamic> print4Column(String string1, String string2, String string3,
String string4, int size,
String string4, Size size,
{String? charset, String? format}) =>
_channel.invokeMethod('print4Column', {
'string1': string1,
'string2': string2,
'string3': string3,
'string4': string4,
'size': size,
'size': size.value,
'charset': charset,
'format': format
});
Expand Down
9 changes: 9 additions & 0 deletions lib/enums/align_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum Align{
left(0), //ESC_ALIGN_LEFT
center(1), //ESC_ALIGN_CENTER
right(2), //ESC_ALIGN_RIGHT

const Align(this.value)

final int value;
}
2 changes: 2 additions & 0 deletions lib/enums/enums_export.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'size_enum.dart';
export 'align_enum.dart';
11 changes: 11 additions & 0 deletions lib/enums/size_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum Size{
medium(0), //normal size text
bold(1), //only bold text
boldMedium(2), //bold with medium
boldLarge(3), //bold with large
extraLarge(4) //extra large

const Size(this.value);

final int value;
}