dev

Should Fixing Bluetooth Printing In Flutter Take 3 Days?

Recently I faced the issue of Bluetooth printing in Flutter. But finally solved after 3 days and of course, I take a...

· 2 min read >
qarao.com-58mm-thermal-printer

Recently I faced the issue of Bluetooth printing in Flutter. But finally solved after 3 days and of course, I take a break to get inspiration, and here is the story.

I used 2 printing libraries, esc_pos_utils and esc_pos_bluetooth to solve the printing problem.

So I tried running a sample project from its repository and connected it to the printer successfully.

But there was something wrong while integrating the package into my Android project. There are no error messages, no warning, no useful information for debugging, so in other words, no hints or clues.

At first, I thought the issue came from plugin dependency. After two days of trial and error, and finally on the next day, found the issue came from targetSdkVersion in Android Gradle.

Journey

Okay, it seems a little dramatic 😀 but here are my steps to solve this problem. On my way to finding solutions, I spent a lot of time researching to get the best results that fit my project.

Another story  Rest API Tutorial Php: Creating Standalone And Simple API For Beginner

At least until published this story, there are no new compatible versions of these plugins yet.

Day #1

Researching some bluetooth plugins to connect and print. And found bluetooth_printblue_thermal_printeresc_pos_bluetooth, and esc_pos_utils.

The last two was my choice. Testing sample from its repository, the result is passed, it worked!

Then, Integrate into my project, and.. it failed! So I tried to copy the repo into a local project and got the log below

Because mywidget depends on esc_pos_bluetooth 0.2.8 
which depends on esc_pos_utils ^0.3.6, 
esc_pos_utils ^0.3.6 is required. 
So, because mywidget depends on esc_pos_utils ^1.0.0, 
version solving failed.

Day #2

I downgrade library version from version esc_pos_utils: 1.0.0 to esc_pos_utils: 0.3.6. While version esc_pos_bluetooth: 0.2.8 is no change.

Another story  How To Manage My Amazon Ebooks On Kindle And iPhone Better In Less Time

I got an amazing thing, actually, no errors but also no printers found LOL! You know if everything seems fine but isn’t really working, it’s hard to debug because there’s no clue.

And … of course, I’ve made sure the printer and Bluetooth are on and connected to my phone.

Day #3

Analyzing a sample project, wondering if it went well in just the sample project? I’m looking for the file what is the cause of this problem.

After several attempts with unsuccessful results as none of the files had any significant differences, I searched Google and saw if anyone else had this problem and resolved it, but I didn’t find the same problem.

So in the end, I manage to open up two Gradle files android/app/build.gradle from the sample and the other from my project. 

Another story  Simple Guidance For You In Connecting Android Emulator To Localhost

And… after inspecting carefully, found the targetSdkVersion 28 (from the sample) and version 29 from my project, maybe it was the default value from flutter-create command result.

Result

Finally, I downgrade the target to 28, and the problem solved! So I continued to design receipts and this is the result.

Success

Receipt printed successfully via Bluetooth thermal printer. Here are 58mm thermal printer and the receipt.

qarao.com-receipt-bluetooh-printing-in-flutter
Here is the result after 3 days LOL!

Maybe next time I’ll tell you this receipt design process 🙂 but I’m wondering how to print vertical text for labels. There is an optional parameter in esc_pos_utils that change 90 degrees for the text but no effect.

Thank you all

And the important thing is.. thanks all for those plugins creator for Bluetooth printing in Flutter. All of you so wonderful.

One Reply to “Should Fixing Bluetooth Printing In Flutter Take 3 Days?”

  1. hi, I am also facing the same issue while searching the Bluetooth printer in my flutter app. The solution which you provided I tired, but not worked for me. Can you please chare the project folder if you can.

Leave a Reply

Your email address will not be published. Required fields are marked *

Right Menu Icon