I am trying to add sentry in my flutter project. From the documentation, i see I have to do it like this
runZonedGuarded(
() => runApp(MyApp(flutterI18nDelegate)),
(error, stackTrace) {
try {
sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
print('Error sent to sentry.io: $error');
} catch (e) {
print('Sending report to sentry.io failed: $e');
print('Original error: $error');
}
});
But I am getting this error
The function 'runZonedGuarded' isn't defined. Try importing the library that defines 'runZonedGuarded', correcting the name to the name of an existing function, or defining a function named
Thank you.
My dart and flutter version
Flutter 1.20.2 • channel beta • https://github.com/flutter/flutter.git
Framework • revision bbfbf1770c (8 weeks ago) • 2020-08-13 08:33:09 -0700
Engine • revision 9d5b21729f
Tools • Dart 2.9.1
runZonedGuarded
is defined on dart:async
.
The complete snippet is:
import 'dart:async';
// Wrap your 'runApp(MyApp())' as follows:
void main() async {
runZonedGuarded(
() => runApp(MyApp()),
(error, stackTrace) {
await sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
},
);
}