#4 moor background isolate
This commit is contained in:
parent
939a3cedb2
commit
7a48a16569
2 changed files with 9 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:moor/isolate.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
|
||||
import 'domain/repositories/audio_repository.dart';
|
||||
import 'domain/repositories/music_data_repository.dart';
|
||||
|
@ -18,6 +20,8 @@ import 'system/repositories/music_data_repository_impl.dart';
|
|||
final GetIt getIt = GetIt.instance;
|
||||
|
||||
Future<void> setupGetIt() async {
|
||||
print('setupGetIt');
|
||||
|
||||
// stores
|
||||
getIt.registerFactory<MusicDataStore>(
|
||||
() {
|
||||
|
@ -60,8 +64,10 @@ Future<void> setupGetIt() async {
|
|||
);
|
||||
|
||||
// data sources
|
||||
// TODO: start background isolate here
|
||||
getIt.registerLazySingleton<MusicDataSource>(() => MoorMusicDataSource());
|
||||
final MoorIsolate moorIsolate = await createMoorIsolate();
|
||||
final DatabaseConnection databaseConnection = await moorIsolate.connect();
|
||||
final MoorMusicDataSource moorMusicDataSource = MoorMusicDataSource.connect(databaseConnection);
|
||||
getIt.registerLazySingleton<MusicDataSource>(() => moorMusicDataSource);
|
||||
getIt.registerLazySingleton<LocalMusicFetcher>(
|
||||
() => LocalMusicFetcherImpl(
|
||||
getIt(),
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'presentation/widgets/injection_widget.dart';
|
|||
import 'presentation/widgets/navbar.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await setupGetIt();
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue