Integration in a flutter project
The integration with flutter can be done by using a native view controller that you'll present over the flutter view controller.
It means you'll have to customize it in the native part.
Here are the steps :
-
Create a communication channel for flutter to communicate with the app. Examples are easy to find. Here is the official documentation : https://flutter.dev/docs/development/platform-integration/platform-channels
-
In the native part you can copy code of the sample. Copy the full scanner class and the storyboard related view controller into your project.
-
Modify the declaration of the class to add
//import the module
@import Flutter;
//add strong reference to store the callback block
@property (strong,nonatomic)FlutterResult result;
- In your app delegate you'll need to display this view controller when the method is called
if ([call.method isEqualToString:@"scanItem"])
{
//create the VC
FLUScanVC* scvc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"FLUScanVC"];
//assign the result block
scvc.result = result;
//Display the VC
[controller presentViewController:scvc animated:YES completion:nil];
}
else
{
result(FlutterMethodNotImplemented);
}
- To return something when the scanner found a code you can just add a few line in the scanner view controller's SmartScannerFoundCode method
//call the result block with the code
self->_result(aCode);
//Dismisse the scanner VC
[self dismissViewControllerAnimated:YES completion:nil];