Crash reporting for Flutter apps
Before you begin, make sure that Apptics is integrated into your project by following the Integration Guide.
Add the SDK to your App
- Use the below method to enable automatic crash tracking.
Copiedimport 'package:apptics_flutter/crash_tracker/apptics_crash_tracker.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// Call the method autoCrashTracker to enable crash autoTracking.
AppticsCrashTracker.instance.autoCrashTracker();
// return your widget;
}
}
Mapping file
To get the stack trace of Java Script code, it is essential to generate and upload the Source Maps. Source Maps allow you to map a transformed file back to the original source. This helps in debugging and investigating issues from release builds.
Upload mapping file
- Zip the .map file.
- Navigate to Quality > Symbols & Mapping.
- Select Flutter mapping from the drop-down menu.
- Select the bundle id or package name for which you want to upload the source maps.
- Click on Upload and a pop-up will appear.
- Click on Choose File and select the zipped .map file.
- Click Upload and the .map file will be uploaded.
Get last crash info
- Use the below method to get the previous crash information as stringified JSONObject.
Copiedimport 'package:apptics_flutter/crash_tracker/apptics_crash_tracker.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// You can reliably obtain the previous crash information as a string.
String? lastCrash = AppticsCrashTracker.instance.getLastCrashInfo();
// return your widget;
}
}
Sample JSON structure
Copied{
"issuename": "divide by zero",
"message": "java.lang.ArithmeticException: divide by zero\n\tat com.zoho.apptics.MainActivity.onCreate$lambda$2(MainActivity.kt:42)",
"networkstatus": 0,
"serviceprovider": "T-Mobile",
"orientation": 0,
"batterystatus": 100,
"edge": "Unknown",
"ram": "2.9 GB",
"rom": "5.8 GB",
"sessionstarttime": 1711445408267,
"customproperties": {},
"screenname": "com.zoho.apptics.MainActivity",
"happenedat": 1711445420908,
"happenedcount": 1,
"listofhappenedtime": 1711445420908,
"errortype": "native"
}
Show consent pop-up to send last session crash info
- Use the below method to show a consent pop-up to send crash information from the last session.
Copiedimport 'package:apptics_flutter/crash_tracker/apptics_crash_tracker.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// Displaying a consent pop-up to allow the sending of crash information from previous sessions.
AppticsCrashTracker.instance.showLastSessionCrashedPopup();
// return your widget;
}
Handled exceptions
- In addition to automatically reporting your app's crashes, Apptics allows you to log handled exceptions as well. Use the below method to record the handled exceptions.
Copiedimport 'package:apptics_flutter/crash_tracker/apptics_crash_tracker.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
try {
int k = (1 / 0) as int;
}catch(e,s){
// Use the below method to record non-fatal.
AppticsCrashTracker.instance.sendNonFatalException(e, s);
}
// return your widget;
}
}
Add custom properties
Custom properties allow you to get the state of your app leading to the crash. JSONObject set using this method will be attached to the crash report, which may help you to understand and debug the crash better.
You can add custom properties for Crashes and handled exceptions.
Copiedimport 'package:apptics_flutter/crash_tracker/apptics_crash_tracker.dart';
class MyApp extends StatelessWidget {
const MyApp({super.key});
setCustomProperties() async {
Map<String, dynamic> _portaInfoMap = {
"name": "ABCD",
"domains": ["Data Science", "Mobile", "Web"],
};
// Implement the following method to set a Custom Property. You can pass the parameter [map].
await AppticsCrashTracker.instance.setCrashCustomProperty(_portaInfoMap);
}
@override
Widget build(BuildContext context) {
setCustomProperties();
// return your widget;
}