-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
What happened?
Did a Setup of realm db in my flutter app.
Repro steps
Import the realm package and call the instance on main.dart.
Then try to call the config method of my code
GetIt.I.registerSingletonAsync<InventoryRealmConfiguration>( () async { final inventoryRealmConfiguration = InventoryRealmConfiguration(); await inventoryRealmConfiguration.config(); return InventoryRealmConfiguration(); }, ); It will execute my code, and i got the stacktrace mentioned below.
Version
Flutter version: 3.22.3
What Atlas Services are you using?
Local Database only with the data fetching from my mongodb
What type of application is this?
Flutter Application
Client OS and version
realm version 3.4.1 and flutter 3.22.3
Code snippets
import 'package:flutter/material.dart';
import 'package:realm/realm.dart';
import 'package:team_appcommon/team_appcommon.dart';
import 'package:team_inventory/src/common/realm/realm_models/realm_models.dart';
import 'package:team_inventory/src/common/secure_storage/secure_storage_constants.dart';
/// Class to handle the Realm Configuration
class RealmConfiguration {
late App _app;
User? _user;
/// Constructor
InventoryRealmConfiguration();
Future<void> config() async {
const appId = "teaminvrealm-xsfakll";
final secureStorageManager = SecureStorageManager();
// Store the API Key securely (only if it is not already stored) await secureStorageManager.setString( key: SecureStorageConstants.realmKey, value: "***********************************************", );
final apiKey = await secureStorageManager.getString( key: SecureStorageConstants.realmKey); if (apiKey == null || apiKey.isEmpty) { throw Exception("API Key not found in secure storage."); }
final appConfig = AppConfiguration(appId);
_app = App(appConfig);
/// Handling errors while Realm login try { _user = await _app.logIn(Credentials.apiKey(apiKey)); print("Successfully logged in to Realm"); print("DATA FETCHING STARTED..."); final itemData = await getItemData(); print('itemData --- $itemData'); final invBalanceData = await getInvBalanceData(); print('invBalanceData --- $invBalanceData'); final invCostData = await getInvCostData(); print('invCostData --- $invCostData'); final inventoryData = await getInventoryData(); print('inventoryData --- $inventoryData'); final reserveData = await getInvReserveData(); print('reserveData --- $reserveData'); print("DATA END..."); } catch (e, s) { print("Failed to log in to Realm: $e $s"); rethrow; }
}
/// Open the realm db
Realm openRealm(Configuration config)
/// Method to get inventory data from MongoDB
List<Inventory> getInventoryData() {
if (_user == null) throw Exception("User is not logged in");
try { final inventoryConfig = Configuration.flexibleSync(_user!, [Inventory.schema]); final inventoryRealm = openRealm(inventoryConfig);
// Add subscription for the Inventory collection inventoryRealm.subscriptions.update((mutableSubscriptions) { mutableSubscriptions .add(inventoryRealm.query<Inventory>("TRUEPREDICATE")); });
final inventoryData = inventoryRealm.all<Inventory>(); return inventoryData.toList(); } catch (e, s) { debugPrint(e.toString()); debugPrint(s.toString()); return []; }
}
/// Method to get inventory Balance data from MongoDB
List<Invbalance> getInvBalanceData() {
if (_user == null) throw Exception("User is not logged in");
try { final invBalanceConfig = Configuration.flexibleSync( _user!, [Invbalance.schema], ); final invBalanceRealm = openRealm(invBalanceConfig);
// Add subscription for the Invbalance collection invBalanceRealm.subscriptions.update((mutableSubscriptions) { mutableSubscriptions .add(invBalanceRealm.query<Invbalance>("TRUEPREDICATE")); }); final invBalanceData = invBalanceRealm.all<Invbalance>(); return invBalanceData.toList(); } catch (e, s) { debugPrint(e.toString()); debugPrint('Error while fetching invBalanceData'); debugPrint(s.toString()); return []; }
}
/// Method to get inventory Cost Data from MongoDB
List<Invcost> getInvCostData() {
if (_user == null) throw Exception("User is not logged in");
try { final invCostConfig = Configuration.flexibleSync(_user!, [Invcost.schema]); final invCostRealm = openRealm(invCostConfig);
// Add subscription for the Invcost collection invCostRealm.subscriptions.update((mutableSubscriptions) { mutableSubscriptions.add(invCostRealm.query<Invcost>("TRUEPREDICATE")); }); final invCostData = invCostRealm.all<Invcost>(); return invCostData.toList(); } catch (e, s) { debugPrint(e.toString()); debugPrint('Error while fetching invCostData'); debugPrint(s.toString()); return []; }
}
/// Method to get inventory Item Data from MongoDB
List<Item> getItemData() {
if (_user == null) throw Exception("User is not logged in");
try { final ItemConfig = Configuration.flexibleSync(_user!, [Item.schema]); final itemRealm = openRealm(ItemConfig); // Add subscription for the Item collection itemRealm.subscriptions.update((mutableSubscriptions) { mutableSubscriptions.add(itemRealm.query<Item>("TRUEPREDICATE")); }); final itemData = itemRealm.all<Item>(); return itemData.toList(); } catch (e, s) { debugPrint(e.toString()); debugPrint('Error while fetching invItemData'); debugPrint(s.toString()); return []; }
}
/// Method to get inventory Item Data from MongoDB
List<Invreserve> getInvReserveData() {
if (_user == null) throw Exception("User is not logged in");
try { final InvReserveConfig = Configuration.flexibleSync( _user!, [Invreserve.schema], ); final invReserveRealm = openRealm(InvReserveConfig);
// Add subscription for the Invreserve collection invReserveRealm.subscriptions.update((mutableSubscriptions) { mutableSubscriptions .add(invReserveRealm.query<Invreserve>("TRUEPREDICATE")); }); final invReserveData = invReserveRealm.all<Invreserve>(); return invReserveData.toList(); } catch (e, s) { debugPrint(e.toString()); debugPrint('Error while fetching invReserveData'); debugPrint(s.toString()); return []; }
}
}
Stacktrace of the exception/crash you're getting
I/flutter (26327): RealmException: Unsupported instruction. Error code: 1000. I/flutter (26327): #0 _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9) I/flutter (26327): #1 using (package:ffi/src/arena.dart:124:31) I/flutter (26327): #2 _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3) I/flutter (26327): #3 PointerEx.raiseLastErrorIfNull (package:realm_dart/src/handles/native/error_handling.dart:16:7) I/flutter (26327): #4 new RealmHandle.open (package:realm_dart/src/handles/native/realm_handle.dart:50:10) I/flutter (26327): #5 Realm._openRealm (package:realm_dart/src/realm_class.dart:206:24) I/flutter (26327): #6 new Realm._ (package:realm_dart/src/realm_class.dart:143:98) I/flutter (26327): #7 new Realm (package:realm_dart/src/realm_class.dart:141:38) I/flutter (26327): #8 InventoryRealmConfiguration.openRealm (package:team_inventory/src/common/realm/realm_configuration.dart:58:12) I/flutter (26327): #9 InventoryRealmConfiguration.getInventoryData (package:team_inventory/src/common/realm/realm_configuration.dart:68:30) I/flutter (26327): #10 InventoryRealmConfiguration.config (package:team_inventory/src/common/realm/realm_configuration.dart:45:35) I/flutter (26327): <asynchronous suspension> I/flutter (26327): #11 setupDependencies.<anonymous closure> (package:team_inventory/locator.dart:34:9) I/flutter (26327): <asynchronous suspension> I/flutter (26327): #12 _GetItImplementation._register.<anonymous closure>.<anonymous closure> (package:get_it/get_it_impl.dart:1258:44) I/flutter (26327): <asynchronous suspension> I/flutter (26327): #13 FutureGroup.add.<anonymous closure> (package:async/src/future_group.dart:79:15) I/flutter (26327): <asynchronous suspension>
Relevant log output
2 I/flutter ( 9312): Successfully logged in to Realm I/flutter ( 9312): DATA FETCHING STARTED... I/flutter ( 9312): itemData --- [Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance of 'Item', Instance I/flutter ( 9312): RealmException: Name too long: . Error code: 3010. I/flutter ( 9312): Error while fetching invBalanceData I/flutter ( 9312): #0 _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9) I/flutter ( 9312): #1 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #2 _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3) I/flutter ( 9312): #3 PointerEx.raiseLastErrorIfNull (package:realm_dart/src/handles/native/error_handling.dart:16:7) I/flutter ( 9312): #4 new RealmHandle.open (package:realm_dart/src/handles/native/realm_handle.dart:50:10) I/flutter ( 9312): #5 Realm._openRealm (package:realm_dart/src/realm_class.dart:206:24) I/flutter ( 9312): #6 new Realm._ (package:realm_dart/src/realm_class.dart:143:98) I/flutter ( 9312): #7 new Realm (package:realm_dart/src/realm_class.dart:141:38) I/flutter ( 9312): #8 InventoryRealmConfiguration.openRealm (package:team_inventory/src/common/realm/realm_configuration.dart:58:12) I/flutter ( 9312): #9 InventoryRealmConfiguration.getInvBalanceData (package:team_inventory/src/common/realm/realm_configuration.dart:94:31) I/flutter ( 9312): #10 InventoryRealmConfiguration.config (package:team_inventory/src/common/realm/realm_configuration.dart:41:36) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #11 setupDependencies.<anonymous closure> (package:team_inventory/locator.dart:34:9) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #12 _GetItImplementation._register.<anonymous closure>.<anonymous closure> (package:get_it/get_it_impl.dart:1258:44) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #13 FutureGroup.add.<anonymous closure> (package:async/src/future_group.dart:79:15) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): I/flutter ( 9312): invBalanceData --- [] I/flutter ( 9312): RealmException: No such table exists. Error code: 3020. I/flutter ( 9312): Error while fetching invCostData I/flutter ( 9312): #0 _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9) I/flutter ( 9312): #1 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #2 _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3) I/flutter ( 9312): #3 BoolEx.raiseLastErrorIfFalse (package:realm_dart/src/handles/native/error_handling.dart:25:7) I/flutter ( 9312): #4 RealmHandle._getPropertiesMetadata (package:realm_dart/src/handles/native/realm_handle.dart:460:87) I/flutter ( 9312): #5 RealmHandle.getObjectMetadata.<anonymous closure> (package:realm_dart/src/handles/native/realm_handle.dart:454:61) I/flutter ( 9312): #6 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #7 RealmHandle.getObjectMetadata (package:realm_dart/src/handles/native/realm_handle.dart:449:12) I/flutter ( 9312): #8 Realm._populateMetadata.<anonymous closure> (package:realm_dart/src/realm_class.dart:211:58) I/flutter ( 9312): #9 MappedIterator.moveNext (dart:_internal/iterable.dart:403:20) I/flutter ( 9312): #10 new RealmMetadata._ (package:realm_dart/src/realm_class.dart:873:28) I/flutter ( 9312): #11 Realm._populateMetadata (package:realm_dart/src/realm_class.dart:211:31) I/flutter ( 9312): #12 new Realm._ (package:realm_dart/src/realm_class.dart:144:5) I/flutter ( 9312): #13 new Realm (package:realm_dart/src/realm_class.dart:141:38) I/flutter ( 9312): #14 InventoryRealmConfiguration.openRealm (package:team_inventory/src/common/realm/realm_configuration.dart:58:12) I/flutter ( 9312): #15 InventoryRealmConfiguration.getInvCostData (package:team_inventory/src/common/realm/realm_configuration.dart:118:28) I/flutter ( 9312): #16 InventoryRealmConfiguration.config (package:team_inventory/src/common/realm/realm_configuration.dart:43:33) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #17 setupDependencies.<anonymous closure> (package:team_inventory/locator.dart:34:9) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #18 _GetItImplementation._register.<anonymous closure>.<anonymous closure> (package:get_it/get_it_impl.dart:1258:44) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #19 FutureGroup.add.<anonymous closure> (package:async/src/future_group.dart:79:15) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): I/flutter ( 9312): invCostData --- [] I/flutter ( 9312): RealmException: No such table exists. Error code: 3020. I/flutter ( 9312): #0 _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9) I/flutter ( 9312): #1 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #2 _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3) I/flutter ( 9312): #3 BoolEx.raiseLastErrorIfFalse (package:realm_dart/src/handles/native/error_handling.dart:25:7) I/flutter ( 9312): #4 RealmHandle._getPropertiesMetadata (package:realm_dart/src/handles/native/realm_handle.dart:460:87) I/flutter ( 9312): #5 RealmHandle.getObjectMetadata.<anonymous closure> (package:realm_dart/src/handles/native/realm_handle.dart:454:61) I/flutter ( 9312): #6 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #7 RealmHandle.getObjectMetadata (package:realm_dart/src/handles/native/realm_handle.dart:449:12) I/flutter ( 9312): #8 Realm._populateMetadata.<anonymous closure> (package:realm_dart/src/realm_class.dart:211:58) I/flutter ( 9312): #9 MappedIterator.moveNext (dart:_internal/iterable.dart:403:20) I/flutter ( 9312): #10 new RealmMetadata._ (package:realm_dart/src/realm_class.dart:873:28) I/flutter ( 9312): #11 Realm._populateMetadata (package:realm_dart/src/realm_class.dart:211:31) I/flutter ( 9312): #12 new Realm._ (package:realm_dart/src/realm_class.dart:144:5) I/flutter ( 9312): #13 new Realm (package:realm_dart/src/realm_class.dart:141:38) I/flutter ( 9312): #14 InventoryRealmConfiguration.openRealm (package:team_inventory/src/common/realm/realm_configuration.dart:58:12) I/flutter ( 9312): #15 InventoryRealmConfiguration.getInventoryData (package:team_inventory/src/common/realm/realm_configuration.dart:68:30) I/flutter ( 9312): #16 InventoryRealmConfiguration.config (package:team_inventory/src/common/realm/realm_configuration.dart:45:35) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #17 setupDependencies.<anonymous closure> (package:team_inventory/locator.dart:34:9) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #18 _GetItImplementation._register.<anonymous closure>.<anonymous closure> (package:get_it/get_it_impl.dart:1258:44) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #19 FutureGroup.add.<anonymous closure> (package:async/src/future_group.dart:79:15) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): I/flutter ( 9312): inventoryData --- [] I/flutter ( 9312): RealmException: No such table exists. Error code: 3020. I/flutter ( 9312): Error while fetching invReserveData I/flutter ( 9312): #0 _raiseLastError.<anonymous closure> (package:realm_dart/src/handles/native/error_handling.dart:59:9) I/flutter ( 9312): #1 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #2 _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48:3) I/flutter ( 9312): #3 BoolEx.raiseLastErrorIfFalse (package:realm_dart/src/handles/native/error_handling.dart:25:7) I/flutter ( 9312): #4 RealmHandle._getPropertiesMetadata (package:realm_dart/src/handles/native/realm_handle.dart:460:87) I/flutter ( 9312): #5 RealmHandle.getObjectMetadata.<anonymous closure> (package:realm_dart/src/handles/native/realm_handle.dart:454:61) I/flutter ( 9312): #6 using (package:ffi/src/arena.dart:124:31) I/flutter ( 9312): #7 RealmHandle.getObjectMetadata (package:realm_dart/src/handles/native/realm_handle.dart:449:12) I/flutter ( 9312): #8 Realm._populateMetadata.<anonymous closure> (package:realm_dart/src/realm_class.dart:211:58) I/flutter ( 9312): #9 MappedIterator.moveNext (dart:_internal/iterable.dart:403:20) I/flutter ( 9312): #10 new RealmMetadata._ (package:realm_dart/src/realm_class.dart:873:28) I/flutter ( 9312): #11 Realm._populateMetadata (package:realm_dart/src/realm_class.dart:211:31) I/flutter ( 9312): #12 new Realm._ (package:realm_dart/src/realm_class.dart:144:5) I/flutter ( 9312): #13 new Realm (package:realm_dart/src/realm_class.dart:141:38) I/flutter ( 9312): #14 InventoryRealmConfiguration.openRealm (package:team_inventory/src/common/realm/realm_configuration.dart:58:12) I/flutter ( 9312): #15 InventoryRealmConfiguration.getInvReserveData (package:team_inventory/src/common/realm/realm_configuration.dart:164:31) I/flutter ( 9312): #16 InventoryRealmConfiguration.config (package:team_inventory/src/common/realm/realm_configuration.dart:47:33) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #17 setupDependencies.<anonymous closure> (package:team_inventory/locator.dart:34:9) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #18 _GetItImplementation._register.<anonymous closure>.<anonymous closure> (package:get_it/get_it_impl.dart:1258:44) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): #19 FutureGroup.add.<anonymous closure> (package:async/src/future_group.dart:79:15) I/flutter ( 9312): <asynchronous suspension> I/flutter ( 9312): I/flutter ( 9312): reserveData --- [] I/flutter ( 9312): DATA END...