@@ -24,35 +24,23 @@ class Crashlytics {
2424 static const MethodChannel channel =
2525 MethodChannel ('plugins.flutter.io/firebase_crashlytics' );
2626
27- /// Submits non-fatal crash report to Firebase Crashlytics.
28- Future <void > onError (FlutterErrorDetails details) async {
29- print ('Error caught by Crashlytics plugin:' );
27+ /// Submits report of a non-fatal error caught by the Flutter framework.
28+ /// to Firebase Crashlytics.
29+ Future <void > recordFlutterError (FlutterErrorDetails details) async {
30+ print ('Flutter error caught by Crashlytics plugin:' );
3031
31- bool inDebugMode = false ;
32- if (! enableInDevMode) {
33- assert (inDebugMode = true );
34- }
32+ _recordError (details.exceptionAsString (), details.stack,
33+ context: details.context);
34+ }
3535
36- if (inDebugMode && ! enableInDevMode) {
37- print (Trace .format (details.stack));
38- } else {
39- // Report error
40- final List <String > stackTraceLines =
41- Trace .format (details.stack).trimRight ().split ('\n ' );
42- final List <Map <String , String >> stackTraceElements =
43- getStackTraceElements (stackTraceLines);
44- await channel
45- .invokeMethod <dynamic >('Crashlytics#onError' , < String , dynamic > {
46- 'exception' : details.exceptionAsString (),
47- // FlutterErrorDetails.context has been migrated from a String to a
48- // DiagnosticsNode. Coerce it to a String here in a way that will work
49- // on both Strings and the new DiagnosticsNode values. See https://groups.google.com/forum/#!topic/flutter-announce/hp1RNIgej38
50- 'context' : '${details .context }' ,
51- 'stackTraceElements' : stackTraceElements,
52- 'logs' : _logs.toList (),
53- 'keys' : _prepareKeys (),
54- });
55- }
36+ /// Submits a report of a non-fatal error.
37+ ///
38+ /// For errors generated by the Flutter framework, use [recordFlutterError] instead.
39+ Future <void > recordError (dynamic exception, StackTrace stack,
40+ {dynamic context}) async {
41+ print ('Error caught by Crashlytics plugin <recordError>:' );
42+
43+ _recordError (exception, stack, context: context);
5644 }
5745
5846 void crash () {
@@ -196,4 +184,30 @@ class Crashlytics {
196184 }
197185 return elements;
198186 }
187+
188+ Future <void > _recordError (dynamic exception, StackTrace stack,
189+ {dynamic context}) async {
190+ bool inDebugMode = false ;
191+ if (! enableInDevMode) {
192+ assert (inDebugMode = true );
193+ }
194+
195+ if (inDebugMode && ! enableInDevMode) {
196+ print (Trace .format (stack));
197+ } else {
198+ // Report error
199+ final List <String > stackTraceLines =
200+ Trace .format (stack).trimRight ().split ('\n ' );
201+ final List <Map <String , String >> stackTraceElements =
202+ getStackTraceElements (stackTraceLines);
203+ await channel
204+ .invokeMethod <dynamic >('Crashlytics#onError' , < String , dynamic > {
205+ 'exception' : "${exception .toString ()}" ,
206+ 'context' : '$context ' ,
207+ 'stackTraceElements' : stackTraceElements,
208+ 'logs' : _logs.toList (),
209+ 'keys' : _prepareKeys (),
210+ });
211+ }
212+ }
199213}
0 commit comments