Skip to content
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
4 changes: 2 additions & 2 deletions example/blue/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.blue"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
33 changes: 31 additions & 2 deletions example/blue/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.blue">
xmlns:tools="http://schemas.android.com/tools"
package="com.example.blue" >
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->

<!-- required for API 18 - 30 -->
<uses-permission
android:name="android.permission.BLUETOOTH"
/>
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
/>

<!-- required for API 23 - 30 -->
<uses-permission-sdk-23
android:name="android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission-sdk-23
android:name="android.permission.ACCESS_FINE_LOCATION"
/>

<!-- API 31+ -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
/>
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="blue"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- <meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/> -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.example.blue

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
6 changes: 3 additions & 3 deletions example/blue/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.8.0'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
101 changes: 36 additions & 65 deletions example/blue/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:intl/intl.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -51,7 +52,13 @@ class _MyHomePageState extends State<MyHomePage> {
});
}

void _startScanDevices() {
void _startScanDevices() async {
await [
Permission.location,
Permission.bluetooth,
Permission.bluetoothConnect,
Permission.bluetoothScan,
].request();
setState(() {
_devices = [];
});
Expand All @@ -62,8 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {
printerManager.stopScan();
}

Future<List<int>> demoReceipt(
PaperSize paper, CapabilityProfile profile) async {
Future<List<int>> demoReceipt(PaperSize paper, CapabilityProfile profile) async {
final Generator ticket = Generator(paper, profile);
List<int> bytes = [];

Expand All @@ -81,56 +87,42 @@ class _MyHomePageState extends State<MyHomePage> {
),
linesAfter: 1);

bytes += ticket.text('889 Watson Lane',
styles: PosStyles(align: PosAlign.center));
bytes += ticket.text('New Braunfels, TX',
styles: PosStyles(align: PosAlign.center));
bytes += ticket.text('Tel: 830-221-1234',
styles: PosStyles(align: PosAlign.center));
bytes += ticket.text('Web: www.example.com',
styles: PosStyles(align: PosAlign.center), linesAfter: 1);
bytes += ticket.text('889 Watson Lane', styles: PosStyles(align: PosAlign.center));
bytes += ticket.text('New Braunfels, TX', styles: PosStyles(align: PosAlign.center));
bytes += ticket.text('Tel: 830-221-1234', styles: PosStyles(align: PosAlign.center));
bytes += ticket.text('Web: www.example.com', styles: PosStyles(align: PosAlign.center), linesAfter: 1);

bytes += ticket.hr();
bytes += ticket.row([
PosColumn(text: 'Qty', width: 1),
PosColumn(text: 'Item', width: 7),
PosColumn(
text: 'Price', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: 'Total', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: 'Price', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: 'Total', width: 2, styles: PosStyles(align: PosAlign.right)),
]);

bytes += ticket.row([
PosColumn(text: '2', width: 1),
PosColumn(text: 'ONION RINGS', width: 7),
PosColumn(
text: '0.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '1.98', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '0.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '1.98', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
bytes += ticket.row([
PosColumn(text: '1', width: 1),
PosColumn(text: 'PIZZA', width: 7),
PosColumn(
text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '3.45', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
bytes += ticket.row([
PosColumn(text: '1', width: 1),
PosColumn(text: 'SPRING ROLLS', width: 7),
PosColumn(
text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '2.99', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
bytes += ticket.row([
PosColumn(text: '3', width: 1),
PosColumn(text: 'CRUNCHY STICKS', width: 7),
PosColumn(
text: '0.85', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(
text: '2.55', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '0.85', width: 2, styles: PosStyles(align: PosAlign.right)),
PosColumn(text: '2.55', width: 2, styles: PosStyles(align: PosAlign.right)),
]);
bytes += ticket.hr();

Expand All @@ -155,35 +147,21 @@ class _MyHomePageState extends State<MyHomePage> {
bytes += ticket.hr(ch: '=', linesAfter: 1);

bytes += ticket.row([
PosColumn(
text: 'Cash',
width: 7,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(
text: '\$15.00',
width: 5,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(text: 'Cash', width: 7, styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(text: '\$15.00', width: 5, styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
]);
bytes += ticket.row([
PosColumn(
text: 'Change',
width: 7,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(
text: '\$4.03',
width: 5,
styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(text: 'Change', width: 7, styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
PosColumn(text: '\$4.03', width: 5, styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
]);

bytes += ticket.feed(2);
bytes += ticket.text('Thank you!',
styles: PosStyles(align: PosAlign.center, bold: true));
bytes += ticket.text('Thank you!', styles: PosStyles(align: PosAlign.center, bold: true));

final now = DateTime.now();
final formatter = DateFormat('MM/dd/yyyy H:m');
final String timestamp = formatter.format(now);
bytes += ticket.text(timestamp,
styles: PosStyles(align: PosAlign.center), linesAfter: 2);
bytes += ticket.text(timestamp, styles: PosStyles(align: PosAlign.center), linesAfter: 2);

// Print QR Code from image
// try {
Expand Down Expand Up @@ -213,28 +191,22 @@ class _MyHomePageState extends State<MyHomePage> {
return bytes;
}

Future<List<int>> testTicket(
PaperSize paper, CapabilityProfile profile) async {
Future<List<int>> testTicket(PaperSize paper, CapabilityProfile profile) async {
final Generator generator = Generator(paper, profile);
List<int> bytes = [];

bytes += generator.text(
'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');
bytes += generator.text('Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ');
// bytes += generator.text('Special 1: àÀ èÈ éÉ ûÛ üÜ çÇ ôÔ',
// styles: PosStyles(codeTable: PosCodeTable.westEur));
// bytes += generator.text('Special 2: blåbærgrød',
// styles: PosStyles(codeTable: PosCodeTable.westEur));

bytes += generator.text('Bold text', styles: PosStyles(bold: true));
bytes += generator.text('Reverse text', styles: PosStyles(reverse: true));
bytes += generator.text('Underlined text',
styles: PosStyles(underline: true), linesAfter: 1);
bytes +=
generator.text('Align left', styles: PosStyles(align: PosAlign.left));
bytes += generator.text('Align center',
styles: PosStyles(align: PosAlign.center));
bytes += generator.text('Align right',
styles: PosStyles(align: PosAlign.right), linesAfter: 1);
bytes += generator.text('Underlined text', styles: PosStyles(underline: true), linesAfter: 1);
bytes += generator.text('Align left', styles: PosStyles(align: PosAlign.left));
bytes += generator.text('Align center', styles: PosStyles(align: PosAlign.center));
bytes += generator.text('Align right', styles: PosStyles(align: PosAlign.right), linesAfter: 1);

bytes += generator.row([
PosColumn(
Expand Down Expand Up @@ -298,8 +270,7 @@ class _MyHomePageState extends State<MyHomePage> {
// await printerManager.printTicket(await testTicket(paper));

// DEMO RECEIPT
final PosPrintResult res =
await printerManager.printTicket((await demoReceipt(paper, profile)));
final PosPrintResult res = await printerManager.printTicket((await demoReceipt(paper, profile)));

showToast(res.msg);
}
Expand Down
15 changes: 7 additions & 8 deletions example/blue/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
charset_converter: ^2.0.0
cupertino_icons: ^1.0.3
oktoast: ^3.0.0
image: ^3.0.2
esc_pos_bluetooth:
path: ../../
esc_pos_utils: ^1.1.0
# esc_pos_utils:
# path: ../../../esc_pos_utils
charset_converter: ^2.0.0
flutter:
sdk: flutter
image: ^3.0.2
intl: ^0.17.0
qr_flutter: ^4.0.0
oktoast: ^3.0.0
path_provider: ^2.0.2
permission_handler: ^10.4.3
qr_flutter: ^4.0.0

dev_dependencies:
flutter_test:
Expand Down