mopinion_flutter_integration_plugin 0.0.3 mopinion_flutter_integration_plugin: ^0.0.3 copied to clipboard
Plugin to integrate Mopinion Native Mobile SDKs into Flutter projects.
Mopinion Native SDK for Flutter #
This Flutter Integration SDK contains code to help you use our Android and/or iOS Native/Web SDKs from Flutter.
Installation #
- Edit the
pubspec.yml
in yourflutter
directory to define the Mopinion Plugin Dependency:
dependencies:
...
mopinion_flutter_integration_plugin: ^${latestVersion}
- Run the following command to get the package:
flutter pub get
Native set up #
Android #
- Open the Android project with Android Studio.
- Make sure that your
MainActivity.kt
extendsFlutterFragmentActivity
and theFlutterEngine
is registered as the following:import io.flutter.embedding.android.FlutterFragmentActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterFragmentActivity() { override fun configureFlutterEngine(flutterEngine: FlutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine) } }
- Make sure the min sdk is 21 in your
app
build.gradle
:
defaultConfig {
minSdkVersion 21
}
- In your
Project
build.gradle
include the Jitpack repoistory:maven { url 'https://www.jitpack.io' }
- Sync gradle.
- Make sure the app theme extends from a MaterialComponent theme. Please check the Android Native SDK readme, step 4 for more info.
iOS #
Install the Mopinion SDK for iOS to make it an available resource for the Flutter plugin.
- Open in the terminal the
ios
folder and runpod install
command. - Open your iOS project
Runner.xcworkspace
with Xcode. - Click on the
Pods
project. - Click on
File
option from XCode and click onAdd Package dependencies...
. - Search for the Mopinion iOS SDK:
https://github.com/Mopinion-com/mopinion-sdk-ios-swiftpm.git
It will appear with the name of:mopinion-sdk-ios-swiftpm
. - Remember to add it to the
Pods
project. - When the dialog of
Choose Package Products for mopinion-sdk-ios-swiftpm
is opened, select theAdd to Target
dropdown and from the options select the plugin target:mopinion_flutter_integration_plugin
. - Add the package.
- Add
Privacy - Camera Usage Description
andPrivacy - Photo Library Usage Description
into fileinfo.plist
.<key>NSCameraUsageDescription</key> <string>TEXT_FOR_END_USER</string> <key>NSPhotoLibraryUsageDescription</key> <string>TEXT_FOR_END_USER</string>
- Using
VSCode
, in the folderios
, open the filePodfile
and set the iOS Deployment Target to 11.0 or above. Uncomment or add platform :ios, '11.0' to the podfile.
# Uncomment this line to define a global platform for your project
platform :ios, '11.0'
- Finally run the project from XCode.
Flutter implementation #
In order to use Mopinion SDK for Flutter and start collecting your valuable user's feedback please follow the following steps:
Import the plugin #
Import the plugin class
import 'package:mopinion_flutter_integration_plugin/mopinion_flutter_integration_plugin.dart';
Initialise the SDK #
Initialise the SDK by calling:
MopinionFlutterIntegrationPlugin.initSdk("YOUR_KEY", log: true);
The parameter log
allows to activate the logging in the SDK.
It's recommended to initialise the SDK the earliest possible, an example of where to initialise the SDK:
@override
void initState() {
super.initState();
initialize();
}
Future<void> initialize() async {
try {
MopinionFlutterIntegrationPlugin.initSdk(YOUR_KEY, true);
} on PlatformException {
print("error");
}
}
Calling events #
In order to show your forms, call the function :
MopinionFlutterIntegrationPlugin.event(EVENT_NAME);
The MopinionFlutterIntegrationPlugin.event(EVENT_NAME)
function will also stream an Form State to show in which state the form is. To be able to listen to that callback you can call the function MopinionFlutterIntegrationPlugin.eventsData()
which returns an Stream
. Example of usage:
Stream stream;
try {
stream = await MopinionFlutterIntegrationPlugin.eventsData();
stream.listen(_setTextEventName, onError: _onError);
} on PlatformException {
print("Failed to get events stream.");
}
void _setTextEventName(event) {
setState(() => _yourState_ = event);
}
The Form State callback will be a String
, and these are the possible Form States:
- Loading
- FormOpened
- FormSent
- FormCanceled
- FormClosed
- Error
- HasNotBeenShown
More information about the Form States can be found in each readme of the Native SDKs:
iOS: 2.4.2 Callback variants of the event method Android: Implementing Form State callbacks
Adding Metadata #
Adding Metadata in the Mopinion SDK is easy, it's achieved by calling the function
MopinionFlutterIntegrationPlugin.data(Map);
This function will receive a Map<String, String>
variable which will contain the metadata you want to set in your events. Example of usage:
Map<String, String> map = {
"age": "29",
"name": "Manuel"
};
MopinionFlutterIntegrationPlugin.data(map);
MopinionFlutterIntegrationPlugin.event(yourEvent);
Deleting Metadata by key
When a key data from the Metadata Map<String, String>
provided to the SDK wants to be deleted then we should just pass the key
value as the following:
MopinionFlutterIntegrationPlugin.removeMetaData("name");
This will remove the key name
from the Metadata Map
provided.
Deleting all Metadata
When all Metadata wants to be deleted, it's even simplier, just call
MopinionFlutterIntegrationPlugin.removeAllMetaData();
And all Metadata will be deleted.