ITADN

App crash when update data inside realm

#1860Openchakracha1 创建于 2025-06-12
O-CommunityT-BugSDK-Use:Local
C
chakracha1commented
### What happened? The first time I insert data, it works successfully in Realm. But when I try to update it, the app crashes. It data large. size of data from model `listOfConfigM: 2 record, activeConfig: 38 record, paramsActive: 629 record ` ### Repro steps 1. Convert json to Realm Model 2. Call realm.addAll($realmObject, update: true); inside realm.writeAsync 3. Data saved in realm 4. Repeat it again from step 1, 2 5. App crash ### Version realm: ^20.1.1, Flutter 3.32.2, Dart 3.8.1 ### What Atlas Services are you using? Local Database only ### What type of application is this? Flutter Application ### Client OS and version iOs 18.3 ### Code snippets ```dart @RealmModel() class $ConfigurationSchema { @PrimaryKey() late String name; late ConfigurationType? configType; late DateTime? lastModified; late DateTime? lastUpdated; } @RealmModel(ObjectType.embeddedObject) class $ConfigurationType { late String? type; late MyConfituration? myConfiguration; } @RealmModel(ObjectType.embeddedObject) class $MyConfituration { late List<$ConfigM> listOfConfigM; } @RealmModel(ObjectType.embeddedObject) class $ConfigM { late String id; late String? name; late List<$ActiveConfig> activeConfig; } @RealmModel(ObjectType.embeddedObject) class $ActiveConfig { late String id; late String? name; late String? type; late List<$PararamActive> paramsActive; } @RealmModel(ObjectType.embeddedObject) class $PararamActive { late String id; late String? name; late RealmValue value; } var simpleConfigJson = ''' { "name": "simpleConfig", "configType": { "type": "myConfiguration", "myConfiguration": { "listOfConfigM": [ { "id": "1", "name": "Config1", "activeConfig": [ { "id": "1.1", "name": "ActiveConfig1", "type": "TypeA", "paramsActive": [ { "id": "1.1.1", "name": "Param1", "value": {"stringValue": "Value1"} }, { "id": "1.1.2", "name": "Param2", "value": false }, { "id": "1.1.3", "name": "Param3", "value": ["hello", "world"] } ] } ] }, { "id": "2", "name": "Config2", "activeConfig": [ { "id": "2.1", "name": "ActiveConfig2", "type": "TypeB", "paramsActive": [ { "id": "2.1.1", "name": "Param2", "value": 0 } ] } ] } ] } }, "lastModified": "${DateTime.now().toIso8601String()}", "lastUpdated": "${DateTime.now().toIso8601String()}" } '''; var confMap = jsonDecode(simpleConfigJson); var configurationSchema = ConfigurationSchema( name: confMap['name'], configType: ConfigurationType( type: confMap['configType']['type'], myConfiguration: MyConfituration( listOfConfigM: (confMap['configType']['myConfiguration']['listOfConfigM'] as List) .map((item) => ConfigM( id: item['id'], name: item['name'], activeConfig: (item['activeConfig'] as List) .map((activeItem) => ActiveConfig( id: activeItem['id'], name: activeItem['name'], type: activeItem['type'], paramsActive: (activeItem['paramsActive'] as List) .map((param) => PararamActive( id: param['id'], name: param['name'], value: RealmValue.fromJson(param['value']) )).toList() )).toList() )).toList() ) ), lastModified: DateTime.parse(confMap['lastModified']), lastUpdated: DateTime.parse(confMap['lastUpdated']) ); realm.writeAsync(() { realm.addAll([configurationSchema], update: true); }); ``` ### Stacktrace of the exception/crash you're getting ```shell - ``` ### Relevant log output ```shell - ```
3 条评论