Ever wonder how you can leverage those built-in barcode scanner or sometimes it is called as PDA handheld scanners that runs on Android operating system in your Flutter app?
You are in luck! This guide introduce you the flutter_pda_scanner_v2 package which is designed to help you to integrate into your Flutter app and operate the barcode scanner.
Before we dive right in, I have to first clarify that the package is originally fork or reference it from flutter_pda_scanner and pda_scanner.
Due to the lack of update and response from the predecessor, therefore I choose to separate out the repository to include certain new enhancement such as supporting Android V2 Embedding and also include a wider range of compatibility with the latest Android PDA device models.
There are also other viable alternatives that work in similar fashion, hence you can still choose whatever that best fits you.
- https://pub.dev/packages/flutter_warehouse_pda_scanner
- https://pub.dev/packages/flutter_plugin_pda_scanner
The installation process is pretty straightforward.
Firstly, add the package into your dependencies. Version may vary as time goes on, please check with the latest version.
dependencies:
flutter_pda_scanner_v2: ^0.0.5
Go to your main.dart file or the one that contains your main method, include the package import and then add await PdaScanner.instance.initialize(); into the main method right after the WidgetFlutterBinding.ensureInitialized();
/// Import package of `flutter_pda_scanner_v2.dart`
import 'package:flutter_pda_scanner_v2/flutter_pda_scanner_v2.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the PdaScanner.
await PdaScanner.instance.initialize();
runApp(const MyApp());
}
After that, go to your respective screen or widget that you want to include to listen to the scanning capability. Make sure you import the package. Finally, add both @override method of onEvent and onError
/// Import package of `flutter_pda_scanner_v2.dart`
import 'package:flutter_pda_scanner_v2/flutter_pda_scanner_v2.dart';
class ScreenExampleState extends State<ScreenExample> with PdaListenerMixin<ScreenExample> {
var _code;
@override
Widget build(BuildContext context) {
return null;
// Or return your own widget.
}
// Add these @override methods to listen to scanner events.
@override
void onEvent(Object event) {
// Process the value of the `event.toString()` here.
}
@override
void onError(Object error) {
// Process the value of the `error.toString()` here such as show toast or dialog.
}
}
There you have it! When you tap on the proprietary barcode scanning button, it should flash out a placeholder in order to find and capture the barcode. Once it captured the correct input, it should make a “beep” sound.
|
|
The device that shown in the GIF above is using SEUIC AutoID Q9 that runs on Android 10
What do you think? Please share your thought and your feedback down below on how flutter_pda_scanner_v2 package is enhancing your development experience.
If it does, a simple👏🏻 to this post would be appreciated!
Thank you for taking the time to read!
*Original post from Medium which is also my own post: https://medium.com/@michaelchiew/guide-to-leverage-the-built-in-barcode-scanners-on-android-pdas-with-flutter-13fc49116e8a
Top comments (0)