Skip to content

Commit

Permalink
feat: move init dependency in a core file
Browse files Browse the repository at this point in the history
  • Loading branch information
LezdCS committed Nov 21, 2024
1 parent df19f6c commit a0591a3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ linter:
- avoid_bool_literals_in_conditional_expressions
# - avoid_catches_without_on_clauses
- avoid_catching_errors
- avoid_classes_with_only_static_members
# - avoid_classes_with_only_static_members
- avoid_double_and_int_checks
# - avoid_dynamic_calls
- avoid_empty_else
Expand Down
56 changes: 1 addition & 55 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ import 'package:get_storage/get_storage.dart';
import 'package:irllink/firebase_options.dart';
import 'package:irllink/routes/app_pages.dart';
import 'package:irllink/src/bindings/login_bindings.dart';
import 'package:irllink/src/core/depedency_injection.dart';
import 'package:irllink/src/core/resources/app_translations.dart';
import 'package:irllink/src/core/resources/themes.dart';
import 'package:irllink/src/core/services/app_info_service.dart';
import 'package:irllink/src/core/services/realtime_irl_task_handler.dart';
import 'package:irllink/src/core/services/settings_service.dart';
import 'package:irllink/src/core/services/store_service.dart';
import 'package:irllink/src/core/services/talker_service.dart';
import 'package:irllink/src/core/services/tts_service.dart';
import 'package:irllink/src/core/services/watch_service.dart';
import 'package:irllink/src/core/utils/talker_custom_logs.dart';
import 'package:irllink/src/data/repositories/settings_repository_impl.dart';
import 'package:irllink/src/data/repositories/twitch_repository_impl.dart';
import 'package:irllink/src/domain/usecases/settings/get_settings_usecase.dart';
import 'package:irllink/src/domain/usecases/settings/set_settings_usecase.dart';
import 'package:irllink/src/domain/usecases/twitch/get_twitch_local_usecase.dart';
import 'package:irllink/src/presentation/views/login_view.dart';
import 'package:kick_chat/kick_chat.dart';
import 'package:talker_flutter/talker_flutter.dart';
Expand All @@ -43,51 +34,6 @@ void main() async {
runApp(const Main());
}

Future<void> initializeDependencies() async {
await Get.putAsync(
() => TalkerService().init(),
permanent: true,
);

// Repositories
SettingsRepositoryImpl settingsRepository = SettingsRepositoryImpl();
TwitchRepositoryImpl twitchRepository = TwitchRepositoryImpl();

// Use cases
final getSettingsUseCase = GetSettingsUseCase(settingsRepository);
final setSettingsUseCase = SetSettingsUseCase(settingsRepository);
final getTwitchLocalUseCase = GetTwitchLocalUseCase(twitchRepository);

final settingsService = await Get.putAsync(
() => SettingsService(
getSettingsUseCase: getSettingsUseCase,
setSettingsUseCase: setSettingsUseCase,
).init(),
permanent: true,
);
if (!settingsService.settings.value.generalSettings.isDarkMode) {
Get.changeThemeMode(ThemeMode.light);
}

await Get.putAsync(
() => StoreService(
getTwitchLocalUseCase: getTwitchLocalUseCase,
talker: Get.find<TalkerService>().talker,
).init(),
permanent: true,
);

final ttsService = await Get.putAsync(
() => TtsService().init(),
permanent: true,
);
await ttsService.initTts(settingsService.settings.value);

await Get.putAsync(() => WatchService().init(), permanent: true);

await Get.putAsync(() => AppInfoService().init(), permanent: true);
}

// The callback function should always be a top-level function.
@pragma('vm:entry-point')
void startCallback() {
Expand Down
58 changes: 58 additions & 0 deletions lib/src/core/depedency_injection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:irllink/src/core/services/app_info_service.dart';
import 'package:irllink/src/core/services/settings_service.dart';
import 'package:irllink/src/core/services/store_service.dart';
import 'package:irllink/src/core/services/talker_service.dart';
import 'package:irllink/src/core/services/tts_service.dart';
import 'package:irllink/src/core/services/watch_service.dart';
import 'package:irllink/src/data/repositories/settings_repository_impl.dart';
import 'package:irllink/src/data/repositories/twitch_repository_impl.dart';
import 'package:irllink/src/domain/usecases/settings/get_settings_usecase.dart';
import 'package:irllink/src/domain/usecases/settings/set_settings_usecase.dart';
import 'package:irllink/src/domain/usecases/twitch/get_twitch_local_usecase.dart';

Future<void> initializeDependencies() async {
await Get.putAsync(
() => TalkerService().init(),
permanent: true,
);

// Repositories
SettingsRepositoryImpl settingsRepository = SettingsRepositoryImpl();
TwitchRepositoryImpl twitchRepository = TwitchRepositoryImpl();

// Use cases
final getSettingsUseCase = GetSettingsUseCase(settingsRepository);
final setSettingsUseCase = SetSettingsUseCase(settingsRepository);
final getTwitchLocalUseCase = GetTwitchLocalUseCase(twitchRepository);

final settingsService = await Get.putAsync(
() => SettingsService(
getSettingsUseCase: getSettingsUseCase,
setSettingsUseCase: setSettingsUseCase,
).init(),
permanent: true,
);
if (!settingsService.settings.value.generalSettings.isDarkMode) {
Get.changeThemeMode(ThemeMode.light);
}

await Get.putAsync(
() => StoreService(
getTwitchLocalUseCase: getTwitchLocalUseCase,
talker: Get.find<TalkerService>().talker,
).init(),
permanent: true,
);

final ttsService = await Get.putAsync(
() => TtsService().init(),
permanent: true,
);
await ttsService.initTts(settingsService.settings.value);

await Get.putAsync(() => WatchService().init(), permanent: true);

await Get.putAsync(() => AppInfoService().init(), permanent: true);
}

0 comments on commit a0591a3

Please sign in to comment.