1

I have a flutter food delivery app. Apart from that, I have a separate restaurant app where I accept and decline orders. I have been trying for a long time to be able to do something so that when the restaurant accepts the order, an automatic receipt will come out in a Bluetooth thermal printer. I found a lot of codes but I don't understand how I can enter these codes in an existing project.

E.g. In lib / view / screens I have the command page screen which is this:

              if(orderModel.orderStatus == 'pending' && (orderModel.orderType == 'take_away'
              || Get.find<SplashController>().configModel.orderConfirmationModel != 'deliveryman'))  {
            Get.dialog(ConfirmationDialog(
              icon: Images.warning, title: 'are_you_sure_to_confirm'.tr, description: 'you_want_to_confirm_this_order'.tr,
              onYesPressed: () {
                orderController.updateOrderStatus(orderModel.id, 'confirmed', back: true).then((success) {
                  if(success) {
                    Get.find<AuthController>().getProfile();
                    Get.find<OrderController>().getCurrentOrders();
                  }
                });
              },

I would like here, when the user presses the Confirm button, to enter a code that will send the automatic receipt to the thermal printer via bluetooth. ((onYesPressed))

I've seen a lot of github, but I don't understand where to add that code. Because that's a new project, but I want to add these codes to my current application. Can someone please explain to me in detail how I should proceed?

Thank you very much,

1 Answers1

0
  1. First, you need to add the plugin for the Bluetooth thermal printer to your existing Flutter project. You can do this by adding the following dependency to your pubspec.yaml file.
dependencies: 
  flutter_bluetooth_thermal_printer: ^1.0.0
  1. Import the plugin in your project:
import 'package:[PACKAGE_NAME].dart';
  1. Create a saperate window to search available printers & after that, you can use the plugin to connect to and print from the Bluetooth thermal printer. For example, you can use the following steps to connect to the printer and print a simple text:

  2. First check the bluetooth is On or Off. You can check bluetooth device using system_shortcuts package.

// it return true if already bluetooth is turned on
var isOn = SystemShortcuts.checkBluetooth;
if (!isOn){
 // it turn-on the bluetooth
 await SystemShortcuts.bluetooth();
}
  1. Scan the device & connect to the printer:

eg.

// Connect to the printer 
FlutterBluetoothThermalPrinter.connect('MY_PRINTER_ID').then((printer) { 
  // Print text 
  printer.printString('Hello World!'); 
});
  1. Now use the print method to print the data on any screen.

Note that this is just a general outline of the process for integrating a Bluetooth thermal printer into a Flutter project. You will need to consult the documentation for the Flutter Bluetooth package and the specific documentation for your printer in order to complete the integration.
Find the compatible SDK from here
Here is the list of some flutter SDK which I used previously:

ankushlokhande
  • 870
  • 5
  • 20