forked from eatvio/eatvio_app
76 lines
2.8 KiB
Dart
76 lines
2.8 KiB
Dart
import 'dart:io' as io;
|
||
import 'package:eatvio_app/core/app_config.dart';
|
||
import 'package:eatvio_app/core/env_config.dart';
|
||
import 'package:eatvio_app/core/locator_service.dart' as di;
|
||
import 'package:eatvio_app/core/locator_service.dart';
|
||
import 'package:eatvio_app/firebase_options.dart';
|
||
import 'package:firebase_core/firebase_core.dart';
|
||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||
import 'package:appmetrica_plugin/appmetrica_plugin.dart';
|
||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||
|
||
/// Класс для инициализации приложения
|
||
class AppInitializer {
|
||
/// Инициализация всех сервисов приложения
|
||
static Future<void> initialize({required AppBuildType buildType}) async {
|
||
await _initializeEnvironment();
|
||
await _initializeDependencyInjection(buildType: buildType);
|
||
await _initializeSentry();
|
||
await _initializeFirebase();
|
||
await _initializeDebugMode();
|
||
await _initializeAnalytics();
|
||
}
|
||
|
||
/// Инициализация Sentry
|
||
static Future<void> _initializeSentry() async {
|
||
final widgetsBinding = SentryWidgetsFlutterBinding.ensureInitialized();
|
||
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
||
}
|
||
|
||
/// Загрузка переменных окружения
|
||
static Future<void> _initializeEnvironment() async {
|
||
await dotenv.load(fileName: ".env");
|
||
}
|
||
|
||
/// Инициализация Firebase
|
||
static Future<void> _initializeFirebase() async {
|
||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||
if (sl<AppConfig>().buildType == AppBuildType.prod) {
|
||
await FirebaseMessaging.instance.requestPermission();
|
||
}
|
||
}
|
||
|
||
/// Инициализация системы внедрения зависимостей
|
||
static Future<void> _initializeDependencyInjection({required AppBuildType buildType}) async {
|
||
await di.init(buildType: buildType);
|
||
}
|
||
|
||
/// Настройка режима отладки
|
||
static Future<void> _initializeDebugMode() async {
|
||
if (kDebugMode) {
|
||
io.HttpClient.enableTimelineLogging = true;
|
||
}
|
||
}
|
||
|
||
/// Инициализация аналитики
|
||
static Future<void> _initializeAnalytics() async {
|
||
AppMetrica.activate(AppMetricaConfig(EnvConfig.appMetricaApiKey));
|
||
AppMetrica.reportEvent('Application started');
|
||
}
|
||
|
||
/// Запуск приложения с Sentry
|
||
static Future<void> runAppWithSentry(VoidCallback appRunner) async {
|
||
await SentryFlutter.init((options) {
|
||
options.dsn = EnvConfig.sentryDsn;
|
||
options.tracesSampleRate = 1.0;
|
||
options.debug = false;
|
||
}, appRunner: appRunner);
|
||
}
|
||
}
|
||
|
||
enum AppBuildType { prod, tests, dev }
|