Sharvan Kumaran
Sharvan Kumaran

Reputation: 15

How to add a nested list of strings to isar database in Flutter

I am trying to add a nested list of strings to an isar database, but I'm getting an Unsupported type error when trying to define the schema.

import 'package:isar/isar.dart';

part 'user.g.dart';

@Collection()
class User{
  Id? id;
  late String name;
  late String email;
  List<List<String>>? history;
  @Index()
  late String phone;
}

I tried creating a class with the embedded tag, but got the same error. Is there anyway to get around this?

Upvotes: 0

Views: 134

Answers (1)

salim.elkh
salim.elkh

Reputation: 83

As per Isar Documentation, Isar supports List but no List of List.

You can create nested embedded objects as for instance:

@Collection()
class User{
  Id? id;
  late String name;
  late String email;
  List<HistoryList>? historyList;
  late String phone;
}


@embedded
class HistoryList {
  List<String>? elements;
}

Upvotes: 0

Related Questions