import 'dart:ui'; import 'package:bluetooth_print_plus/bluetooth_print_plus.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mobile_pos/generated/l10n.dart' as lang; final labelPrinterProvider = ChangeNotifierProvider((ref) => ThermalPrinter()); class ThermalPrinter extends ChangeNotifier { @override void addListener(VoidCallback listener) async { // TODO: implement addListener super.addListener(listener); await BluetoothPrintPlus.startScan(timeout: Duration(seconds: 10)); } List availableBluetoothDevices = []; bool isBluetoothConnected = false; // Future getBluetooth() async { // availableBluetoothDevices = await BluetoothPrintPlus.scanResults; // isBluetoothConnected = await PrintBluetoothThermal.connectionStatus; // notifyListeners(); // } // // Future setConnect(String mac) async { // bool status = false; // final bool result = await PrintBluetoothThermal.connect(macPrinterAddress: mac); // if (result == true) { // isBluetoothConnected = true; // status = true; // } // notifyListeners(); // return status; // } Future listOfBluDialog({required BuildContext context}) async { // begin scan // final _scanResultsSubscription = BluetoothPrintPlus.scanResults.listen((event) { // print('${event.length}'); // // if (mounted) { // // setState(() { // // _scanResults = event; // // }); // // } // }); return showCupertinoDialog( context: context, builder: (_) { return WillPopScope( onWillPop: () async => false, child: BackdropFilter( filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5), child: CupertinoAlertDialog( insetAnimationCurve: Curves.bounceInOut, // content: Container( // height: availableBluetoothDevices.isNotEmpty ? (availableBluetoothDevices.length * 80).toDouble() : 150, // width: double.maxFinite, // child: StreamBuilder( // stream: FlutterBluetoothPrinter.discovery, // builder: (context, snapshot){ // // // // final List hh = snapshot.data as List; // print('this is it--------->$snapshot'); // return ListView.builder( // itemCount: 0, // itemBuilder: (context, index){ // // final device = hh.elementAt(index); // return ListTile( // // title: Text(device.name ?? 'No Name'), // // subtitle: Text(device.address), // onTap: (){ // // do anything // // FlutterBluetoothPrinter.printImage( // // address: device.address, // // image: // some image // // ); // } // ); // } // ); // } // )), title: Text( 'Connect Your Device', textAlign: TextAlign.start, ), actions: [ CupertinoDialogAction( child: Text( lang.S.of(context).cancel, textAlign: TextAlign.center, style: TextStyle(color: Colors.red), ), onPressed: () async { Future.delayed(const Duration(milliseconds: 100), () { Navigator.pop(context); }); }, ), ], ), ), ); }, ); } // Future printSalesThermalInvoiceNow({required PrintSalesTransactionModel transaction, required List? productList, required BuildContext context}) async { // await getBluetooth(); // isBluetoothConnected ? SalesThermalPrinterInvoice().printSalesTicket(printTransactionModel: transaction, productList: productList) : listOfBluDialog(context: context); // } }