Mobile integration
Flutter SDK Integration
In this section you will find information on how to integrate the MobSur SDK in your mobile Flutter project.
Prerequisites
- Available only for iOS and Android
- Android minimum SDK version: 32
Installation Guide
- Install the package by executing the following command in the terminal in the project folder:
flutter pub add mobsur_flutter_sdk
This will automatically add the dependency in the pubspec.yaml
file.
- Import the package to the file where it is going to be used.
import 'package:mobsur_flutter_sdk/mobsur_flutter_sdk.dart';
- Call the setup method:
App ID!
You can get the App ID from the MobSur Dashboard.
More information is available here
The client id is defined by you and it is used to distinguish different users answering the surveys.
void main() {
WidgetsFlutterBinding.ensureInitialized();
// You can call this method somewhere else in the app instead,
// but it should not be right before an event, that should trigger a survey
MobSurSDK().setup('appId', 'clientId');
runApp(const MyApp());
}
- To start a survey, call the event method. For example:
TextButton(
onPressed: () {
MobSurSDK().logEvent('myevent', context);
},
child: const Text('Start survey')
)
- If you need to change the userId or you do not know it during initialization, call the updateClientId method:
Important
For the Android platform, we have minimum SDK version requirements. If you need to use the app on a lower version than 32, please contact us.
// android/app/build.gradle:
...
android {
compileSdkVersion 32 // or higher
...
defaultConfig {
...
minSdkVersion 32 // or higher
...
}
}
Recommendation
Call the event method in a wrapper class that manages your events. If you already have events in the app, it's a good idea to call the method for all the events, and then, the correct one will be selected in the dashboard.
Sample project
A sample project can be found in our GitHub repository.