import 'dart:typed_data'; import 'package:aman_kassa_flutter/core/base/base_service.dart'; import 'package:bluetooth_print/bluetooth_print.dart'; import 'package:bluetooth_print/bluetooth_print_model.dart'; class BluePrintService extends BaseService { BluetoothPrint _bluetooth = BluetoothPrint.instance; BluetoothDevice? _device; Future scan() async { await _bluetooth.startScan(timeout: Duration(seconds: 4)); } Future stopScan() async { await _bluetooth.stopScan(); } Stream> get scanResult => _bluetooth.scanResults; Stream get isScanning => _bluetooth.isScanning; Stream get state => _bluetooth.state; set device(BluetoothDevice device) => _device = device; Future connect() async { bool response = false; if (_device == null) { response = false; } else { try { await _bluetooth.connect(_device!); await Future.delayed(Duration(seconds: 2)); response = true; } catch (e) { print('Error connect $e'); response = false; } } return response; } Future disconnect() async { bool response = false; try { await _bluetooth.disconnect(); response = true; } catch (e) { print('Error $e'); response = false; } return response; } Future printBytes(Uint8List bytes) async { Map config = Map(); return await _bluetooth.rawBytes(config, bytes); } }