|
/

使用GetMaterialApp的时候如何接入UmengApmSdk

Uuni***@come56.com
发布于 8 个月前
7792来自广东省
应用性能监控 U-APM
SDK集成与升级

UmengApmSdk(
name: '名称',
bver: '版本号',
flutterVersion: 'flutterVersion',
engineVersion: 'engineVersion',
enableLog: true,
initFlutterBinding: MyApmWidgetsFlutterBinding.ensureInitialized,
).init(appRunner: (observer) {
return MyApp(observer);
});

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

NavigatorObserver? _navigatorObserver;
LocalStorage l = LocalStorage();

@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'App名称',
enableLog: kDebugMode,
transitionDuration: Duration(milliseconds: 250),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
// supportedLocales: [
// const Locale.fromSubtags(
// languageCode: 'zh', countryCode: 'CN', scriptCode: 'Hans')
// ],

navigatorObservers: <NavigatorObserver>[
_navigatorObserver ?? ApmNavigatorObserver.singleInstance
],
onInit: () {
print("cshoiaa");
},
home: l.token == null ? LoginPage() : MainPage(),
);
}
}

7个回答
 
8 个月前
来自北京

_debugInitializedType == null“ 这个错误是因为操作依赖ensureInitialized初始化行为,需将依赖的代码放进appRunner回调中

void main() {
final UmengApmSdk umengApmSdk = UmengApmSdk(
name: '',
bver: '1.0.0+9',
flutterVersion: '3.10.0',
engineVersion: 'd44b5a94c9',
enableLog: true,
enableTrackingPageFps: true,
enableTrackingPagePerf: true,
errorFilter: {
"mode": "ignore",
// "rules": [RegExp('RangeError')],
"rules": [],
},
initFlutterBinding: MyApmWidgetsFlutterBinding.ensureInitialized,
// onError: (exception, stack) {},
);
umengApmSdk.init(appRunner: (observer) async {
// 确保去掉原有的WidgetsFlutterBinding.ensureInitialized() ,以免出现重复初始化绑定的异常造成无法正常初始化,
// SDK内部已通过initFlutterBinding入参带入继承的WidgetsFlutterBinding实现初始化操作
// 依赖ensureInitialized()初始化的代码可在此调用


// 如 final version_info = await getPlatformInfo();


// 需要异步获取设置应用名称和版本号可在此回调中操作
// SDK实例化的设置可先将name和bver 为 "",然后通过以下方式进行设置
// 如:umengApmSdk.name = 'app_demo';
// 如:umengApmSdk.bver = '1.2.0+1';
umengApmSdk.name = 'app_demo';
return MyApp(observer);
});
}

 
8 个月前
来自浙江省

你好,你这边原生接入是安卓还是ios呢?

 
8 个月前
来自广东省

MyApmWidgetsFlutterBinding就是class MyApmWidgetsFlutterBinding extends ApmWidgetsFlutterBinding {
@override
void handleAppLifecycleStateChanged(AppLifecycleState state) {
// 添加自己的实现逻辑
print('AppLifecycleState changed to $state');
super.handleAppLifecycleStateChanged(state);
}

static WidgetsBinding? ensureInitialized() {
MyApmWidgetsFlutterBinding();
return WidgetsBinding.instance;
}
}

 
8 个月前
来自广东省

报错为==========APM SDK 异常============

I/flutter (10618): [UMENG-FLUTTER-APM]--[Error]:'package:flutter/src/foundation/binding.dart': Failed assertion: line 146 pos 12: '_debugInitializedType == null': is not true.

I/flutter (10618): [UMENG-FLUTTER-APM]--[Error]:#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)

I/flutter (10618): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)

I/flutter (10618): #2 new BindingBase (package:flutter/src/foundation/binding.dart:146:12)

I/flutter (10618): #3 new _WidgetsFlutterBinding&BindingBase&GestureBinding (package:flutter/src/widgets/binding.dart)

I/flutter (10618): #4 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding (package:flutter/src/widgets/binding.dart)

I/flutter (10618): #5 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding (package:flutter/src/widgets/binding.dart)

I/flutter (10618): #6 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding (package:flutter/src/widgets/binding.dart)

I/flutter (10618): #7 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerBinding&ServicesBinding&PaintingBinding&SemanticsBinding (package:flutter/src/widgets/binding.dart)

I/flutter (10618): #8 new _WidgetsFlutterBinding&BindingBase&GestureBinding&SchedulerB

I/flutter (10618): [UMENG-FLUTTER-APM]--[Error]:==================================

Loading ...
登录社区,分享你的经验