ve_apm 3.1.0 copy "ve_apm: ^3.1.0" to clipboard
ve_apm: ^3.1.0 copied to clipboard

A flutter plugin for veMars APM.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:ve_apm/ve_apm.dart';

import 'common/router.dart';
import 'pages/home_page.dart';

void main() {
  // runAppWithoutTrace 调用之后,不会上报性能监控日志
  runAppWithoutTrace((NavigatorObserver observer) {
    HttpOverrides.global = ApmHttpOverrides();
    enableVeApmLog(true);  // 控制台日志开关,默认为 true
    return MyApp(observer);
  }, bindingInitHandler: CustomFlutterBinding.ensureInitialized);

  // startVeApmTrace 调用之后,会开始上报性能监控日志
  startVeApmTrace();

  // 初始化 Native SDK,如果已经在项目的 native 代码中完成了初始化,请不要调用
  final VeApmNativeConfig config = VeApmNativeConfig('233805', '4f16428f37ab45f088b6316dab561767');
  config.channel = 'flutter';
  config.enableConsoleLog = true;
  final VeApmNativeHelper nativeHelper = VeApmNativeHelper(config);
  nativeHelper.start();
  nativeHelper.setUserID('userID');
  // (仅iOS)如果需要调用此方法设置自定义 deviceID,请配置 VeApmNativeHelper.config.iosConfig.deviceIDSource 设置为 user
  // nativeHelper.setDeviceID('deviceID');
}

mixin MixinFlutterBinding on ApmWidgetsFlutterBinding {
  @override
  void initInstances() {
    super.initInstances();
    print('MixinFlutterBinding initInstances');
  }

  @override
  void handleAppLifecycleStateChanged(AppLifecycleState state) {
    super.handleAppLifecycleStateChanged(state);
    print('MixinFlutterBinding handleAppLifecycleStateChanged');
  }
}

class CustomFlutterBinding extends ApmWidgetsFlutterBinding
    with MixinFlutterBinding {
  static WidgetsBinding? ensureInitialized() {
    // if (WidgetsBinding.instance == null) {
      CustomFlutterBinding();
    // }
    return WidgetsBinding.instance;
  }
}

class MyApp extends StatefulWidget {
  const MyApp([this._navigatorObserver]);

  final NavigatorObserver? _navigatorObserver;

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: HomePage(),
      navigatorObservers: <NavigatorObserver>[
        widget._navigatorObserver ?? ApmNavigatorObserver.instance
      ],
      routes: generateRoutes(),
    );
  }
}
0
likes
110
pub points
43%
popularity

Publisher

verified publishervolcengine.com

A flutter plugin for veMars APM.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter, mockito

More

Packages that depend on ve_apm