52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_bugly_plugin/flutter_bugly_plugin.dart';
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
|
import 'package:star_lock/flavors.dart';
|
|
|
|
///
|
|
/// 错误日志监控
|
|
///
|
|
///
|
|
class BuglyTool {
|
|
static Future<void> init(Function on) async {
|
|
if (F.isProductionEnv) {
|
|
//生产
|
|
await FlutterBuglyPlugin.init(
|
|
appIdAndroid: '73c99cca00',
|
|
appIdiOS: 'b25632a54f',
|
|
);
|
|
} else {
|
|
//测试
|
|
await FlutterBuglyPlugin.init(
|
|
appIdAndroid: '02fb541c1c',
|
|
appIdiOS: '618ab9feeb',
|
|
);
|
|
}
|
|
|
|
//错误日志监控
|
|
FlutterError.onError = (FlutterErrorDetails details) async {
|
|
AppLog.log('error:${details.exception.toString()}',
|
|
stackTrace: details.stack, error: true);
|
|
Zone.current.handleUncaughtError(
|
|
details.exception, details.stack ?? StackTrace.empty);
|
|
};
|
|
|
|
//错误日志监控
|
|
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
|
|
FlutterBuglyPlugin.reportException(
|
|
exceptionName: error.toString(), reason: stack.toString());
|
|
AppLog.log('error:$error', stackTrace: stack, error: true);
|
|
return true;
|
|
};
|
|
|
|
//错误日志监控
|
|
runZonedGuarded<Future<void>>(() async => on(),
|
|
(Object error, StackTrace stackTrace) async {
|
|
AppLog.log('error:$error', stackTrace: stackTrace, error: true);
|
|
});
|
|
}
|
|
}
|