From 0c2561c89da6349a385b17f75b00d953307866c9 Mon Sep 17 00:00:00 2001 From: pierre Date: Sun, 18 Sep 2022 22:37:42 +0200 Subject: [PATCH 1/2] fix macos + downgrade version --- macos/Classes/BlueThermalPrinterPlugin.m | 12 ++++++++++-- macos/Classes/SwiftBlueThermalPrinterPlugin.swift | 13 ------------- macos/blue_thermal_printer.podspec | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) delete mode 100644 macos/Classes/SwiftBlueThermalPrinterPlugin.swift diff --git a/macos/Classes/BlueThermalPrinterPlugin.m b/macos/Classes/BlueThermalPrinterPlugin.m index 50155ef..f12aaeb 100644 --- a/macos/Classes/BlueThermalPrinterPlugin.m +++ b/macos/Classes/BlueThermalPrinterPlugin.m @@ -1,8 +1,16 @@ #import "BlueThermalPrinterPlugin.h" -#import + +static NSString *const CHANNEL_NAME = @"plugins.kzaki.com/blue_thermal_printer"; + @implementation BlueThermalPrinterPlugin + (void)registerWithRegistrar:(NSObject*)registrar { - [SwiftBlueThermalPrinterPlugin registerWithRegistrar:registrar]; + FlutterMethodChannel* channel = [FlutterMethodChannel + methodChannelWithName:CHANNEL_NAME + binaryMessenger:[registrar messenger]]; + BlueThermalPrinterPlugin* instance = [[BlueThermalPrinterPlugin alloc] init]; + [registrar addMethodCallDelegate:instance channel:channel]; } + @end + diff --git a/macos/Classes/SwiftBlueThermalPrinterPlugin.swift b/macos/Classes/SwiftBlueThermalPrinterPlugin.swift deleted file mode 100644 index ffb0f6b..0000000 --- a/macos/Classes/SwiftBlueThermalPrinterPlugin.swift +++ /dev/null @@ -1,13 +0,0 @@ -#if canImport(FlutterMacOS) - import Cocoa - import FlutterMacOS -#endif - -public class AssetsAudioPlayer: NSObject, FlutterPlugin { - public static func register(with registrar: FlutterPluginRegistrar) { - - } - public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - - } -} diff --git a/macos/blue_thermal_printer.podspec b/macos/blue_thermal_printer.podspec index f5a74a9..9142de4 100644 --- a/macos/blue_thermal_printer.podspec +++ b/macos/blue_thermal_printer.podspec @@ -16,7 +16,7 @@ A new Flutter plugin for connecting to thermal printer vie bluetooth s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'FlutterMacOS' - s.platform = :osx, '10.13' + s.platform = :osx, '10.11' s.framework = 'CoreBluetooth' end From 654c42e2662f361fce08352f007d822388681401 Mon Sep 17 00:00:00 2001 From: pierre Date: Sun, 18 Sep 2022 22:38:27 +0200 Subject: [PATCH 2/2] fix example/main + provide tip on permission crash --- example/lib/main.dart | 151 +++++++++++++++++++++--------------------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 70ef359..ca44a51 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -26,6 +26,19 @@ class _MyAppState extends State { } Future initPlatformState() async { + // TODO here add a permission request using permission_handler + // if permission is not granted, kzaki's thermal print plugin will ask for location permission + // which will invariably crash the app even if user agrees so we'd better ask it upfront + + // var statusLocation = Permission.location; + // if (await statusLocation.isGranted != true) { + // await Permission.location.request(); + // } + // if (await statusLocation.isGranted) { + // ... + // } else { + // showDialogSayingThatThisPermissionIsRequired()); + // } bool? isConnected = await bluetooth.isConnected; List devices = []; try { @@ -107,82 +120,72 @@ class _MyAppState extends State { appBar: AppBar( title: Text('Blue Thermal Printer'), ), - body: Container( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: ListView( - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - SizedBox( - width: 10, - ), - Text( - 'Device:', - style: TextStyle( - fontWeight: FontWeight.bold, - ), - ), - SizedBox( - width: 30, - ), - Expanded( - child: DropdownButton( - items: _getDeviceItems(), - onChanged: (BluetoothDevice? value) => - setState(() => _device = value), - value: _device, - ), - ), - ], - ), - SizedBox( - height: 10, - ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - ElevatedButton( - style: ElevatedButton.styleFrom(primary: Colors.brown), - onPressed: () { - initPlatformState(); - }, - child: Text( - 'Refresh', - style: TextStyle(color: Colors.white), - ), - ), - SizedBox( - width: 20, + body: Padding( + padding: const EdgeInsets.all(8.0), + child: ListView( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const SizedBox(width: 10), + const Text( + 'Device:', + style: TextStyle( + fontWeight: FontWeight.bold, ), - ElevatedButton( - style: ElevatedButton.styleFrom( - primary: _connected ? Colors.red : Colors.green), - onPressed: _connected ? _disconnect : _connect, - child: Text( - _connected ? 'Disconnect' : 'Connect', - style: TextStyle(color: Colors.white), - ), + ), + const SizedBox(width: 30), + Expanded( + child: DropdownButton( + items: _getDeviceItems(), + onChanged: (BluetoothDevice? value) => + setState(() => _device = value), + value: _device, ), - ], - ), - Padding( - padding: - const EdgeInsets.only(left: 10.0, right: 10.0, top: 50), - child: ElevatedButton( + ), + ], + ), + const SizedBox(height: 10), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + ElevatedButton( style: ElevatedButton.styleFrom(primary: Colors.brown), onPressed: () { - testPrint.sample(); + initPlatformState(); }, - child: Text('PRINT TEST', - style: TextStyle(color: Colors.white)), + child: const Text( + 'Refresh', + style: TextStyle(color: Colors.white), + ), ), + const SizedBox(width: 20), + ElevatedButton( + style: ElevatedButton.styleFrom( + primary: _connected ? Colors.red : Colors.green), + onPressed: _connected ? _disconnect : _connect, + child: Text( + _connected ? 'Disconnect' : 'Connect', + style: TextStyle(color: Colors.white), + ), + ), + ], + ), + Padding( + padding: + const EdgeInsets.only(left: 10.0, right: 10.0, top: 50), + child: ElevatedButton( + style: ElevatedButton.styleFrom(primary: Colors.brown), + onPressed: () { + testPrint.sample(); + }, + child: const Text('PRINT TEST', + style: TextStyle(color: Colors.white)), ), - ], - ), + ), + ], ), ), ), @@ -209,7 +212,7 @@ class _MyAppState extends State { void _connect() { if (_device != null) { bluetooth.isConnected.then((isConnected) { - if (isConnected == true) { + if (isConnected == false) { bluetooth.connect(_device!).catchError((error) { setState(() => _connected = false); }); @@ -232,12 +235,10 @@ class _MyAppState extends State { }) async { await new Future.delayed(new Duration(milliseconds: 100)); ScaffoldMessenger.of(context).showSnackBar( - new SnackBar( - content: new Text( + SnackBar( + content: Text( message, - style: new TextStyle( - color: Colors.white, - ), + style: const TextStyle(color: Colors.white), ), duration: duration, ),