// Author: fengshengxiong
// Date: 2024/6/26
// Description: firebase_crashlytics管理

import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_translate/common/utils/log_utils.dart';

class FirebaseCrashlyticsManager {
  static Future<void> setEnabled() async {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(kReleaseMode);
  }

  static void recordFlutterError() {
    FlutterError.onError = (errorDetails) {
      Log.d(errorDetails.exception);
      FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
    };
  }

  static void recordError() {
    PlatformDispatcher.instance.onError = (error, stack) {
      Log.d(error);
      FirebaseCrashlytics.instance.recordError(error, stack);
      return true;
    };
  }
}
