text
stringlengths 1
372
|
|---|
myErrorsHandler.onErrorDetails(details);
|
};
|
PlatformDispatcher.instance.onError = (error, stack) {
|
myErrorsHandler.onError(error, stack);
|
return true;
|
};
|
runApp(const MyApp());
|
}
|
class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
widget build(BuildContext context) {
|
return MaterialApp(
|
builder: (context, widget) {
|
widget error = const text('...rendering error...');
|
if (widget is scaffold || widget is navigator) {
|
error = scaffold(body: center(child: error));
|
}
|
ErrorWidget.builder = (errordetails) => error;
|
if (widget != null) return widget;
|
throw StateError('widget is null');
|
},
|
);
|
}
|
}
|
<code_end>
|
<topic_end>
|
<topic_start>
|
report errors to a service
|
while one always tries to create apps that are free of bugs,
|
they’re sure to crop up from time to time.
|
since buggy apps lead to unhappy users and customers,
|
it’s important to understand how often your users
|
experience bugs and where those bugs occur.
|
that way, you can prioritize the bugs with the
|
highest impact and work to fix them.
|
how can you determine how often your users experiences bugs?
|
whenever an error occurs, create a report containing the
|
error that occurred and the associated stacktrace.
|
you can then send the report to an error tracking
|
service, such as bugsnag, datadog,
|
firebase crashlytics, rollbar, or sentry.
|
the error tracking service aggregates all of the crashes your users
|
experience and groups them together. this allows you to know how often your
|
app fails and where the users run into trouble.
|
in this recipe, learn how to report errors to the
|
sentry crash reporting service using
|
the following steps:
|
<topic_end>
|
<topic_start>
|
1. get a DSN from sentry
|
before reporting errors to sentry, you need a “dsn” to uniquely identify
|
your app with the sentry.io service.
|
to get a DSN, use the following steps:
|
<topic_end>
|
<topic_start>
|
2. import the sentry package
|
import the sentry_flutter package into the app.
|
the sentry package makes it easier to send
|
error reports to the sentry error tracking service.
|
to add the sentry_flutter package as a dependency,
|
run flutter pub add:
|
<topic_end>
|
<topic_start>
|
3. initialize the sentry SDK
|
initialize the SDK to capture different unhandled errors automatically:
|
<code_start>
|
import 'package:flutter/widgets.dart';
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
future<void> main() async {
|
await SentryFlutter.init(
|
(options) => options.dsn = 'https://example@sentry.io/example',
|
appRunner: () => runApp(const MyApp()),
|
);
|
}
|
<code_end>
|
alternatively, you can pass the DSN to flutter using the dart-define tag:
|
<topic_end>
|
<topic_start>
|
what does that give me?
|
this is all you need for sentry to capture unhandled errors in dart and native layers.
|
this includes swift, Objective-C, c, and c++ on iOS, and java, kotlin, c, and c++ on android.
|
<topic_end>
|
<topic_start>
|
4. capture errors programmatically
|
besides the automatic error reporting that sentry generates by
|
importing and initializing the SDK,
|
you can use the API to report errors to sentry:
|
<code_start>
|
await Sentry.captureException(exception, stackTrace: stackTrace);
|
<code_end>
|
for more information, see the sentry API docs on pub.dev.
|
<topic_end>
|
<topic_start>
|
learn more
|
extensive documentation about using the sentry SDK can be found on sentry’s site.
|
<topic_end>
|
<topic_start>
|
complete example
|
to view a working example,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.