For the complete documentation index, see llms.txt. This page is also available as Markdown.

Create AtCollection from Dart primitive

Learn how to create an AtCollection object that holds Dart primitives

Use dart primitives when you want to create a collection that is based on Dart primitives.

This is Path B from the Introduction. Use this when you just want to store a Map, String, Uint8List, or other type that Dart's jsonEncode already handles.

Unlike what is done in Create AtCollection from domain object, you do not need fromJson or typeTag. The SDK knows how to serialize and deserialize these natively.

Examples

Maps

final AtCollection<Map> maps = await atClient.collection<Map>(
  'maps.my_app',
  const Duration(days: 7),
);

Strings

final AtCollection<String> strings = await atClient.collection<String>(
  'strings.my_app',
  const Duration(days: 7),
);

await strings.create(
  obj: 'this is just a String',
  sharedWith: otherAtSigns,
);

Lists

Binary data (Uint8List)

Untyped (generic) collections

You can create a collection with no type parameter. This gives you an AtCollection<dynamic> that accepts any Dart primitive in the same collection. No fromJson, typeTag, or registerFactory call is needed - the SDK tags every primitive as 'n/a' internally and round-trips them through jsonDecode automatically.

You lose compile-time type safety on item.obj (it is dynamic), so cast when you read back:

You are ready to move onto AtCollection.create.

Last updated