File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,12 +3,16 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
33import 'package:off_chat/src/app.dart' ;
44import 'package:off_chat/src/core/utils/watch_log.dart' ;
55import 'package:off_chat/src/core/notifications/notification_service.dart' ;
6+ import 'package:off_chat/src/core/database/isar_service.dart' ;
67
78void main () async {
89 WidgetsFlutterBinding .ensureInitialized ();
910
1011 // Setup hardened logging
1112 await WatchLog .initialize ();
13+
14+ // Initialize database
15+ await IsarService ().initialize ();
1216
1317 // Initialize notifications
1418 await NotificationService ().init ();
Original file line number Diff line number Diff line change @@ -6,12 +6,8 @@ import 'package:shared_preferences/shared_preferences.dart';
66part 'database_provider.g.dart' ;
77
88@Riverpod (keepAlive: true )
9- Future <Isar > isarDatabase (Ref ref) async {
10- final service = IsarService ();
11- if (! service.isOpen) {
12- await service.initialize ();
13- }
14- return service.db;
9+ Isar isarDatabase (Ref ref) {
10+ return IsarService ().db;
1511}
1612
1713@Riverpod (keepAlive: true )
Original file line number Diff line number Diff line change @@ -13,15 +13,9 @@ part 'chat_controller.g.dart';
1313class ChatController extends _$ChatController {
1414 @override
1515 Stream <List <Message >> build (String remoteDeviceId) {
16- // Ensure Isar is initialized
17- final isarAsync = ref.watch (isarDatabaseProvider);
18-
19- if (isarAsync.hasValue) {
20- final stableId = int .parse (remoteDeviceId);
21- return IsarService ().watchMessagesWithDevice (stableId);
22- }
23-
24- return const Stream .empty ();
16+ ref.watch (isarDatabaseProvider);
17+ final stableId = int .parse (remoteDeviceId);
18+ return IsarService ().watchMessagesWithDevice (stableId);
2519 }
2620
2721 Future <void > sendTextMessage (String text) async {
Original file line number Diff line number Diff line change @@ -10,15 +10,8 @@ part 'discovery_controller.g.dart';
1010class DiscoveryController extends _$DiscoveryController {
1111 @override
1212 Stream <List <FoundDevice >> build () {
13- // Watch the provider to ensure Isar is initialized
14- final isarAsync = ref.watch (isarDatabaseProvider);
15-
16- if (isarAsync.hasValue) {
17- return IsarService ().watchFoundDevices ();
18- }
19-
20- // Return empty stream while initializing
21- return const Stream .empty ();
13+ ref.watch (isarDatabaseProvider);
14+ return IsarService ().watchFoundDevices ();
2215 }
2316
2417 Future <void > manualRefresh () async {
You can’t perform that action at this time.
0 commit comments