2020-11-14 10:08:13 +01:00
|
|
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
2020-11-14 08:54:26 +01:00
|
|
|
import 'package:flushbar/flushbar_helper.dart';
|
2020-10-28 10:56:24 +01:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2020-09-08 10:55:32 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-10-28 18:13:04 +01:00
|
|
|
import 'package:flutter/foundation.dart';
|
2020-10-03 13:11:07 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-10-28 10:56:24 +01:00
|
|
|
import 'package:sentry/sentry.dart';
|
2020-10-13 12:20:13 +02:00
|
|
|
|
|
|
|
import 'famedlysdk_store.dart';
|
2020-11-07 12:00:41 +01:00
|
|
|
import '../config/setting_keys.dart';
|
2020-09-08 10:55:32 +02:00
|
|
|
|
|
|
|
abstract class SentryController {
|
|
|
|
static Future<void> toggleSentryAction(BuildContext context) async {
|
2020-11-14 10:08:13 +01:00
|
|
|
final enableSentry = await showOkCancelAlertDialog(
|
|
|
|
context: context,
|
|
|
|
title: L10n.of(context).sendBugReports,
|
|
|
|
message: L10n.of(context).sentryInfo,
|
|
|
|
okLabel: L10n.of(context).ok,
|
|
|
|
cancelLabel: L10n.of(context).no,
|
|
|
|
) ==
|
|
|
|
OkCancelResult.ok;
|
2020-10-25 16:59:55 +01:00
|
|
|
final storage = Store();
|
2020-11-07 12:00:41 +01:00
|
|
|
await storage.setItem(SettingKeys.sentry, enableSentry.toString());
|
2020-11-14 10:08:13 +01:00
|
|
|
// ignore: unawaited_futures
|
|
|
|
FlushbarHelper.createSuccess(message: L10n.of(context).changesHaveBeenSaved)
|
2020-11-14 08:54:26 +01:00
|
|
|
.show(context);
|
2020-09-08 10:55:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Future<bool> getSentryStatus() async {
|
2020-10-25 16:59:55 +01:00
|
|
|
final storage = Store();
|
2020-11-07 12:00:41 +01:00
|
|
|
return await storage.getItemBool(SettingKeys.sentry);
|
2020-09-08 10:55:32 +02:00
|
|
|
}
|
2020-10-28 10:56:24 +01:00
|
|
|
|
|
|
|
static final sentry = SentryClient(dsn: AppConfig.sentryDsn);
|
|
|
|
|
|
|
|
static void captureException(error, stackTrace) async {
|
|
|
|
debugPrint(error.toString());
|
|
|
|
debugPrint(stackTrace.toString());
|
2020-10-28 18:13:04 +01:00
|
|
|
if (!kDebugMode && await getSentryStatus()) {
|
2020-10-28 10:56:24 +01:00
|
|
|
await sentry.captureException(
|
|
|
|
exception: error,
|
|
|
|
stackTrace: stackTrace,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-09-08 10:55:32 +02:00
|
|
|
}
|