2020-06-07 18:22:10 +02:00
|
|
|
import 'dart:ui';
|
|
|
|
|
2020-05-27 21:54:33 +02:00
|
|
|
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
|
|
|
import 'package:get_it/get_it.dart';
|
2020-06-03 20:32:59 +02:00
|
|
|
import 'package:moor/isolate.dart';
|
|
|
|
import 'package:moor/moor.dart';
|
2020-05-27 21:54:33 +02:00
|
|
|
|
|
|
|
import 'domain/repositories/audio_repository.dart';
|
|
|
|
import 'domain/repositories/music_data_repository.dart';
|
|
|
|
import 'presentation/state/audio_store.dart';
|
|
|
|
import 'presentation/state/music_data_store.dart';
|
|
|
|
import 'presentation/state/navigation_store.dart';
|
2020-10-21 20:58:55 +02:00
|
|
|
import 'system/audio/audio_manager.dart';
|
|
|
|
import 'system/audio/audio_manager_contract.dart';
|
2020-05-27 21:54:33 +02:00
|
|
|
import 'system/datasources/local_music_fetcher.dart';
|
|
|
|
import 'system/datasources/local_music_fetcher_contract.dart';
|
|
|
|
import 'system/datasources/moor_music_data_source.dart';
|
|
|
|
import 'system/datasources/music_data_source_contract.dart';
|
|
|
|
import 'system/repositories/audio_repository_impl.dart';
|
|
|
|
import 'system/repositories/music_data_repository_impl.dart';
|
|
|
|
|
|
|
|
final GetIt getIt = GetIt.instance;
|
|
|
|
|
|
|
|
Future<void> setupGetIt() async {
|
2020-06-03 20:32:59 +02:00
|
|
|
print('setupGetIt');
|
|
|
|
|
2020-05-27 21:54:33 +02:00
|
|
|
// stores
|
|
|
|
getIt.registerFactory<MusicDataStore>(
|
|
|
|
() {
|
|
|
|
final musicDataStore = MusicDataStore(
|
|
|
|
musicDataRepository: getIt(),
|
|
|
|
);
|
2020-09-19 19:55:14 +02:00
|
|
|
musicDataStore.init();
|
2020-05-27 21:54:33 +02:00
|
|
|
return musicDataStore;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
getIt.registerFactory<AudioStore>(
|
|
|
|
() {
|
|
|
|
final audioStore = AudioStore(
|
|
|
|
audioRepository: getIt(),
|
2020-11-15 16:36:50 +01:00
|
|
|
musicDataRepository: getIt(),
|
2020-05-27 21:54:33 +02:00
|
|
|
);
|
|
|
|
return audioStore;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
getIt.registerFactory<NavigationStore>(
|
|
|
|
() {
|
|
|
|
final navigationStore = NavigationStore();
|
|
|
|
return navigationStore;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
// repositories
|
|
|
|
getIt.registerLazySingleton<MusicDataRepository>(
|
|
|
|
() => MusicDataRepositoryImpl(
|
|
|
|
localMusicFetcher: getIt(),
|
|
|
|
musicDataSource: getIt(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
getIt.registerLazySingleton<AudioRepository>(
|
|
|
|
() => AudioRepositoryImpl(
|
|
|
|
getIt(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
// data sources
|
2020-06-03 20:32:59 +02:00
|
|
|
final MoorIsolate moorIsolate = await createMoorIsolate();
|
2020-06-07 18:22:10 +02:00
|
|
|
IsolateNameServer.registerPortWithName(moorIsolate.connectPort, MOOR_ISOLATE);
|
|
|
|
|
2020-06-03 20:32:59 +02:00
|
|
|
final DatabaseConnection databaseConnection = await moorIsolate.connect();
|
|
|
|
final MoorMusicDataSource moorMusicDataSource = MoorMusicDataSource.connect(databaseConnection);
|
|
|
|
getIt.registerLazySingleton<MusicDataSource>(() => moorMusicDataSource);
|
2020-05-27 21:54:33 +02:00
|
|
|
getIt.registerLazySingleton<LocalMusicFetcher>(
|
|
|
|
() => LocalMusicFetcherImpl(
|
|
|
|
getIt(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
getIt.registerLazySingleton<AudioManager>(() => AudioManagerImpl());
|
|
|
|
|
|
|
|
// external
|
|
|
|
getIt.registerLazySingleton<FlutterAudioQuery>(() => FlutterAudioQuery());
|
|
|
|
}
|