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

Revert "Fixes for new flutter verion" #36

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
14 changes: 0 additions & 14 deletions .whitesource

This file was deleted.

4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group 'com.peoplewareinnovations.bluetooth_thermal_printer'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.5.20'
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,7 @@ class BluetoothThermalPrinterPlugin: FlutterPlugin, MethodCallHandler{
}
}
}
}else if (call.method == "disconnectPrinter") {
GlobalScope.launch(Dispatchers.Main) {
if(outputStream != null) {
outputStream = disconnect()?.also {
//result.success("true")
//Toast.makeText(this@MainActivity, "Connected to printer", Toast.LENGTH_SHORT).show()
}.apply {
result.success("true")
//Log.d(TAG, "finished: Connection state:$state")
}
}
}
} else if (call.method == "writeBytes") {
}else if (call.method == "writeBytes") {

var lista: List<Int> = call.arguments as List<Int>
var bytes: ByteArray = "\n".toByteArray()
Expand Down Expand Up @@ -242,40 +230,6 @@ class BluetoothThermalPrinterPlugin: FlutterPlugin, MethodCallHandler{
}
}

private suspend fun disconnect(): OutputStream? {
state = "false"
return withContext(Dispatchers.IO) {
var outputStream: OutputStream? = outputStream
val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
if (bluetoothAdapter != null && bluetoothAdapter.isEnabled) {
try {
if(mac.length>0) {
val bluetoothAddress = mac
val bluetoothDevice = bluetoothAdapter.getRemoteDevice(bluetoothAddress)
var bluetoothSocket = bluetoothDevice.createRfcommSocketToServiceRecord(
UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")
)
bluetoothSocket.close()
//bluetoothSocket=null
}
Log.d(TAG, "Disconnected: ")
outputStream?.close()
outputStream=null
} catch (e: Exception){
state = "false"
var code:Int = e.hashCode() //1535159 off //
Log.d(TAG, "connect: ${e.message} code $code")
outputStream?.close()
}
}else{
state = "false"
outputStream=null
Log.d(TAG, "Adapter problem")
}
outputStream
}
}

private fun getLinkedDevices():List<String>{

val listItems: MutableList<String> = mutableListOf()
Expand Down Expand Up @@ -373,3 +327,4 @@ class BluetoothThermalPrinterPlugin: FlutterPlugin, MethodCallHandler{
channel.setMethodCallHandler(null)
}
}

4 changes: 2 additions & 2 deletions example/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 31
compileSdkVersion 29

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.peoplewareinnovations.bluetooth_thermal_printer_example"
minSdkVersion 16
targetSdkVersion 31
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
6 changes: 2 additions & 4 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
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. -->

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="bluetooth_thermal_printer_example"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -16,8 +15,7 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:exported="true">
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
Expand Down
6 changes: 3 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

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

tasks.register("clean", Delete) {
task clean(type: Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
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-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
12 changes: 6 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:bluetooth_thermal_printer/bluetooth_thermal_printer.dart';
import 'package:esc_pos_utils_plus/esc_pos_utils.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:flutter/material.dart';

void main() {
Expand All @@ -23,15 +23,15 @@ class _MyAppState extends State<MyApp> {
List availableBluetoothDevices = [];

Future<void> getBluetooth() async {
final List? bluetooths = await BluetoothThermalPrinter.getBluetooths;
final List bluetooths = await BluetoothThermalPrinter.getBluetooths;
print("Print $bluetooths");
setState(() {
availableBluetoothDevices = bluetooths!;
availableBluetoothDevices = bluetooths;
});
}

Future<void> setConnect(String mac) async {
final String? result = await BluetoothThermalPrinter.connect(mac);
final String result = await BluetoothThermalPrinter.connect(mac);
print("state conneected $result");
if (result == "true") {
setState(() {
Expand All @@ -41,7 +41,7 @@ class _MyAppState extends State<MyApp> {
}

Future<void> printTicket() async {
String? isConnected = await BluetoothThermalPrinter.connectionStatus;
String isConnected = await BluetoothThermalPrinter.connectionStatus;
if (isConnected == "true") {
List<int> bytes = await getTicket();
final result = await BluetoothThermalPrinter.writeBytes(bytes);
Expand All @@ -52,7 +52,7 @@ class _MyAppState extends State<MyApp> {
}

Future<void> printGraphics() async {
String? isConnected = await BluetoothThermalPrinter.connectionStatus;
String isConnected = await BluetoothThermalPrinter.connectionStatus;
if (isConnected == "true") {
List<int> bytes = await getGraphicsTicket();
final result = await BluetoothThermalPrinter.writeBytes(bytes);
Expand Down
Loading