remove item from list
MODIFY
packages/isar/lib/src/isar_connect.dart
packages/isar/lib/src/isar_connect.dart
@@ -16,6 +16,7 @@ abstract class _IsarConnect {
ConnectAction.exportJson: _exportJson,
ConnectAction.editProperty: _editProperty,
ConnectAction.addInList: _addInList,
+ ConnectAction.removeFromList: _removeFromList,
};
static bool _initialized = false;
@@ -280,6 +281,27 @@ abstract class _IsarConnect {
await collection.isar.writeTxn(() async => collection.importJson(objects));
}
+ static Future<void> _removeFromList(Map<String, dynamic> params) async {
+ final cEdit = ConnectEdit.fromJson(params);
+ final collection = Isar.getInstance(cEdit.instance)!
+ .getCollectionByNameInternal(cEdit.collection)!;
+
+ final query = collection.buildQuery<dynamic>(
+ whereClauses: [IdWhereClause.equalTo(value: cEdit.id)],
+ );
+
+ final objects = await query.exportJson();
+
+ if (objects.isEmpty ||
+ !objects[0].containsKey(cEdit.property) ||
+ objects[0][cEdit.property] is! List) {
+ throw IsarError('Cant get object or property is wrong for remove');
+ }
+
+ (objects[0][cEdit.property] as List).removeAt(cEdit.index!);
+ await collection.isar.writeTxn(() async => collection.importJson(objects));
+ }
+
static Query<dynamic> _getQuery(ConnectQuery query) {
final collection = Isar.getInstance(query.instance)!
.getCollectionByNameInternal(query.collection)!;

MODIFY
packages/isar/lib/src/isar_connect_api.dart
packages/isar/lib/src/isar_connect_api.dart
@@ -13,7 +13,8 @@ enum ConnectAction {
exportQuery('ext.isar.exportQuery'),
exportJson('ext.isar.exportJson'),
editProperty('ext.isar.editProperty'),
- addInList('ext.isar.addInList');
+ addInList('ext.isar.addInList'),
+ removeFromList('ext.isar.removeFromList');
const ConnectAction(this.method);

MODIFY
packages/isar_inspector/lib/query_table.dart
packages/isar_inspector/lib/query_table.dart
@@ -23,9 +23,11 @@ typedef Editor = void Function(
String property,
int? index,
dynamic value,
- bool editing,
+ EditorType editing,
);
+enum EditorType { add, edit, remove }
+
class QueryTable extends ConsumerWidget {
const QueryTable({super.key});
@@ -67,10 +69,20 @@ class QueryTable extends ConsumerWidget {
value: value,
);
- if (editing) {
- ref.read(isarConnectPod.notifier).editProperty(edit);
- } else {
+ switch (editing) {
+ case EditorType.add:
ref.read(isarConnectPod.notifier).addInList(edit);
+ break;
+
+ case EditorType.edit:
+ ref.read(isarConnectPod.notifier).editProperty(edit);
+ break;
+
+ case EditorType.remove:
+ ref
+ .read(isarConnectPod.notifier)
+ .removeFromList(edit);
+ break;
}
},
),
@@ -360,6 +372,19 @@ class _TableItemState extends State<TableItem> {
: 'Edit property',
),
),
+ if (widget.data is PropertyHelper &&
+ !(widget.data as PropertyHelper).subLink &&
+ widget.data.index != null)
+ PopupMenuItem<dynamic>(
+ onTap: _removeListItem,
+ child: PopUpMenuRow(
+ icon: const Icon(
+ Icons.delete,
+ size: PopUpMenuRow.iconSize,
+ ),
+ text: 'Remove item ${widget.data.index!}',
+ ),
+ ),
if (widget.data is PropertyHelper &&
!(widget.data as PropertyHelper).subLink &&
(widget.data as PropertyHelper).property.type.isList &&
@@ -495,7 +520,7 @@ class _TableItemState extends State<TableItem> {
property.name,
index,
result['value'],
- false,
+ EditorType.add,
);
}
}
@@ -550,7 +575,17 @@ class _TableItemState extends State<TableItem> {
(widget.data as PropertyHelper).property.name,
widget.data.index,
value,
- true,
+ EditorType.edit,
+ );
+ }
+
+ Future<void> _removeListItem() async {
+ widget.editor(
+ widget.objectId,
+ (widget.data as PropertyHelper).property.name,
+ widget.data.index,
+ null,
+ EditorType.remove,
);
}

MODIFY
packages/isar_inspector/lib/state/isar_connect_state_notifier.dart
packages/isar_inspector/lib/state/isar_connect_state_notifier.dart
@@ -189,6 +189,14 @@ class IsarConnectStateNotifier
);
}
+ Future<void> removeFromList(ConnectEdit edit) async {
+ await _call<dynamic>(
+ ConnectAction.removeFromList,
+ args: edit.toJson(),
+ timeout: kLongTimeout,
+ );
+ }
+
Future<void> disconnect() async {
await state.value?.vmService.dispose();
}

remove item from list