Documentation
Search…
⌃K

Quickstart

Flutter Quickstart
Estimated time: 20 minutes
This guide will go over:
  • Conditions and minimum requirements
  • Installation
    📦
  • Configuration
  • Initialization
  • Attaching
    🔗
flutter_apm on pub.dev : pub.dev

Conditions and minimum requirements

Minimum Flutter version : 2.2.3 Minimum Dart version : 2.13.4
Minimum Android version: 4.1 (API 16) Minimum iOS version : 10.0 Minimum XCode version : 10

I. Installation

Download the flutter dependency:
flutter pub add flutter_apm
flutter pub get

II. Configuration

iOS
Android
ios/Podfile Add platform to minimum 10.0 and add sources
platform :ios, '10.0'
source 'https://gitlab.appsmiles.eu/appsmiles/APMSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
Launch command pod install on folder ios
pod install
android/build.gradle
//You can set login and password in env variables
def mavenAppsmilesUsername = System.getenv("APPSMILES_ARTIFACTORY_LOGIN") ?: ''
def mavenAppsmilesPassword = System.getenv("APPSMILES_ARTIFACTORY_PASSWORD") ?: ''
//Or in local.properties
def folder = new File( 'local.properties' )
if( folder.exists() ) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
mavenAppsmilesUsername = properties.getProperty("maven_appsmiles.username") ?: mavenAppsmilesUsername
mavenAppsmilesPassword = properties.getProperty("maven_appsmiles.password") ?: mavenAppsmilesPassword
}
allprojects {
repositories {
//...
maven {
url 'https://artifactory.appsmiles.eu/artifactory/list/appsmiles/'
credentials {
username = mavenAppsmilesUsername
password = mavenAppsmilesPassword
}
}
}
}
android/local.properties If you use a file local.properties, add maven_appsmiles.username and maven_appsmiles.password with your credentials
maven_appsmiles.username=USERNAME
maven_appsmiles.password=PASSWORD

III. Initialization

MainApplication.kt Init the SDK on main thread of your application
import android.app.Application
import com.moonmiles.apm.sdk.APM
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
APM.sharedInstance(this) //First init in main thread
}
}
main.dart Initialize the SDK with the keys we provided to you (partnerID, partnerSecret, baseUrl), your app's package name (appId). Add also a instance of APMNavigatorObserver in MaterialApp.navigationObservers
import 'package:flutter/material.dart';
import 'package:flutter_apm/apm_module.dart';
import 'package:flutter_apm/apm_navigator_observer.dart';
void main() {
runApp(MyApp());
}
APMNavigatorObserver<PageRoute> apmObserver = APMNavigatorObserver<PageRoute>();
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
APMModule.initAppWithAppID('<PARTNER_ID>', '<PARTNER_SECRET>', '<APP_ID>');
APMModule.setDebugMode(true);
APMModule.setBaseUrl('<BASE_URL>');
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
navigatorObservers: [apmObserver],
);
}
}

IV. Attaching

Attach the refresh of the SDK with the lifecycle of your screen

Android

MainActivity.kt

kotlin
java
import android.content.Intent
import android.os.Bundle
import com.moonmiles.apm.sdk.activity.APMClientActivityUtils
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
APMClientActivityUtils.onCreate(this)
}
override fun onResume() {
super.onResume()
APMClientActivityUtils.onResume(this)
}
override fun onPause() {
super.onPause()
APMClientActivityUtils.onPause(this)
}
override fun onDestroy() {
super.onDestroy()
APMClientActivityUtils.onDestroy(this)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
APMClientActivityUtils.onNewIntent(this, intent)
}
}
TODO
Launch the app, you can see appears the badge