Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

dart - How to Store a BluetoothDevice Object to Shared Preferences in my flutter App( BluetoothDevice object type not supported)

My flutter app is using the flutter_bluetooth_basic: ^0.1.5 and blue_thermal_printer: ^1.1.1 packages to connect to a Bluetooth printer and print receipts, but my problem is I want users to be able to connect to a Bluetooth printer and have it saved under shared preferences so every time they open the login, my app will try to connect to the Bluetooth printer automatically so they don't have to connect every time but have a Bluetooth device saved, but when trying to save it to shared preferences, I cant set it because it doesn't support the type of BluetoothDevice, how can save BluetoothDevive objects locally? any thoughts, please


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can encode that object to a string then save it, and whenever you want it back just restore that string and decode it to you the original type here is a full documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...