forked from BuglyDevTeam/Bugly-Flutter-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
99 lines (85 loc) · 3.03 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:bugly_crash/bugly.dart';
import 'package:bugly_crash/buglyLog.dart';
//void main() => runApp(MyApp());
Map<String,String> extraInfo = {"key1":"value1","key2":"value2","key3":"value1"};
Future<Null> main() async {
//测试APP未捕获到的异常上报
FlutterError.onError = (FlutterErrorDetails details) async {
print("zone current print error");
Zone.current.handleUncaughtError(details.exception, details.stack);
};
runZoned<Future<Null>>(() async {
runApp(MyApp());
}, onError: (error, stackTrace) async {
String type = "flutter uncaught error";
await Bugly.postException(type:type,error: error.toString(),stackTrace: stackTrace.toString(),extraInfo:extraInfo);
});
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
Bugly.setAppVersion(appVersion:"1.9.2");
Bugly.setAppChannel(appChannel: "flutter_test");
Bugly.setAppPackage(appPackage: "com.bugly.flutter.test");
Bugly.setUserSceneTag(userSceneTag: 30);
Bugly.putUserData(userKey:"userkey1",userValue:"uservalue1");
Bugly.putUserData(userKey:"userkey2",userValue:"uservalue2");
BuglyLog.d(tag:"d",content:"value");
BuglyLog.i(tag:"i",content:"value");
BuglyLog.v(tag:"v",content:"value");
BuglyLog.w(tag:"w",content:"value");
BuglyLog.e(tag:"e",content:"value");
Bugly.setIsDevelopmentDevice(isDevelopmentDevice: true);
Bugly.initCrashReport(appId:"d562178d23",isDebug: true);
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await Bugly.platformVersion;
} on PlatformException{
platformVersion = 'Failed to get platform version.';
}
//测试APP自己捕获到的异常上报
try {
String s ;
s.trim();
} catch (e){
String type = "flutter caught error";
await Bugly.postException(type:type,error:"null exception",stackTrace:e.toString(),extraInfo:extraInfo);
}
//测试APP未捕获到的异常上报
throw 'bugly flutter uncaught error test';
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
),
),
);
}
}