Flutter Isar linkproperty.add() issue

566 Views Asked by At

I am creating a user (collection element) to be stored in my chat (collection element). chat contains IsarLinks<user>. I create a user and save it (which it correctly does). but when I add it this error pops up.

enter image description here

And this is the line where error arises

final _chat = chat()
  ..users.add(store)
  ..chatname = _user.name;

further this is where I save the chat

Future<void> MakeChatwithUserAsync(chat _chat)async{
  final isar = await db;

  var isarCollection = isar.chats;
  await isar.writeTxn(() async {
    isar.chats.putSync(_chat);
    // _chat.users.loadSync();
    await _chat.users.save();
  });
  print("chat saved");
}

Isar version used is isar-3.0.0-dev.7 and flutter doctor shows everything fine How can this be fixed?

I expected it to work perfectly as I followed the docs, but this did not happen. I tried exploring the function definitions and scrolled on the internet but it was of no use. I want to complete my project of making WhatsApp like app with flutter

1

There are 1 best solutions below

0
On

You have to save User data before calling .save() function. in that way, users object will be linked with Isar Object

await isar.writeTxn(() async {
    isar.users.putAll(_chat.users);
    isar.chats.putSync(_chat);
    await _chat.users.save();
  });