Quickstart

Estimated time: 20 minutes

This guide will go over:

  • Conditions and minimum requirements

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/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

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

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)
    }
}

Launch the app, you can see appears the badge

Last updated