diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f2b2058..30ae7ec 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,10 @@ + + + - diff --git a/example/lib/main.dart b/example/lib/main.dart index 2ad7592..7b28f3a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -36,8 +36,8 @@ class _MyAppState extends State { if (!pers) { Permission.locationWhenInUse.request(); } - DjPrinter.init(); - DjPrinter.addDiscoveryListen(onReceive: (data) { + DjPrinter().init(); + DjPrinter().addDiscoveryListen(onReceive: (data) { var js = json.decode(data.toString()); devices.add(Device( name: js['name'], address: js['address'], isPaired: js['isPaired'])); @@ -46,9 +46,9 @@ class _MyAppState extends State { print("————————————————————————"); }, onFinish: () { print('——————————————————————————————'); - DjPrinter.cancelDiscovery(); + DjPrinter().cancelDiscovery(); }); - DjPrinter.addConnectListen(onConnect: () { + DjPrinter().addConnectListen(onConnect: () { print("connected"); }, onDisconnect: () { print('disconnected'); @@ -68,7 +68,7 @@ class _MyAppState extends State { TextButton( onPressed: () { devices.clear(); - DjPrinter.startSearch; + DjPrinter().startSearch; }, child: const Text('扫描设备')), // TextButton(onPressed: () {}, child: const Text('打印')), @@ -78,7 +78,7 @@ class _MyAppState extends State { ...devices .map((e) => TextButton( onPressed: () { - DjPrinter.connect(e.address); + DjPrinter().connect(e.address); }, child: Text(e.name))) .toList(), @@ -87,7 +87,7 @@ class _MyAppState extends State { ), TextButton( onPressed: () { - DjPrinter.print( + DjPrinter().print( code: 'ASSZ2022012500010002', channel: 'cosco定提-月达-卡派', country: '美国', diff --git a/example/pubspec.lock b/example/pubspec.lock index e52ea86..e4f64fe 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -102,6 +102,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.2" meta: dependency: transitive description: @@ -204,7 +211,7 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.3" + version: "0.4.8" typed_data: dependency: transitive description: diff --git a/lib/dj_printer.dart b/lib/dj_printer.dart index afe9805..d8f8c07 100644 --- a/lib/dj_printer.dart +++ b/lib/dj_printer.dart @@ -12,9 +12,9 @@ class DjPrinter { static const MethodChannel _channel = MethodChannel('dj_printer'); static const EventChannel _deviceChannel = EventChannel("com.discovery.devices"); - static StreamSubscription? _discoveryStream; + StreamSubscription? _discoveryStream; - static Future addDiscoveryListen( + Future addDiscoveryListen( {required void Function(dynamic data) onReceive, void Function()? onStart, void Function()? onFinish}) async { @@ -33,7 +33,7 @@ class DjPrinter { } } - static void cancelDiscovery() { + void cancelDiscovery() { if (_discoveryStream != null) { _discoveryStream!.cancel(); _discoveryStream = null; @@ -41,9 +41,9 @@ class DjPrinter { } static const EventChannel _connectChannel = EventChannel("com.connect"); - static StreamSubscription? _connectStream; + StreamSubscription? _connectStream; - static Future addConnectListen( + Future addConnectListen( {required void Function() onConnect, required void Function() onDisconnect}) async { if (_connectStream == null) { @@ -59,24 +59,24 @@ class DjPrinter { } } - static void cancelConnect() { + void cancelConnect() { if (_connectStream != null) { _connectStream!.cancel(); _connectStream = null; } } - static Future get startSearch async { + Future get startSearch async { final res = await _channel.invokeMethod('startSearch'); return res; } - static Future connect(String address) async { + Future connect(String address) async { final res = await _channel.invokeMethod('connect', {'address': address}); return res; } - static Future init() async { + Future init() async { final res = await _channel.invokeMethod('init'); return res; } @@ -86,7 +86,7 @@ class DjPrinter { //2 paper empty //4 cover open //8 battery low - static Future getStatus() async { + Future getStatus() async { final res = await _channel.invokeMethod('getStatus'); switch (res) { case 0: @@ -104,7 +104,7 @@ class DjPrinter { } } - static Future print( + Future print( {required String code, required String channel, required String country, diff --git a/pubspec.lock b/pubspec.lock index aa6a371..3128254 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -81,6 +81,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.2" meta: dependency: transitive description: @@ -141,7 +148,7 @@ packages: name: test_api url: "https://pub.flutter-io.cn" source: hosted - version: "0.4.3" + version: "0.4.8" typed_data: dependency: transitive description: