lexicon 0.2.4
lexicon: ^0.2.4 copied to clipboard
Core library for parsing Lexicon in the AT Protocol standard.
Core library for parsing Lexicon in the AT Protocol standard 🦋
1. Guide 🌎 #
This library provides the easiest way to use Lexicon supported by AT Protocol in Dart and Flutter apps.
1.1. Getting Started ⚡ #
1.1.1. Install Library #
With Dart:
dart pub add lexicon
Or With Flutter:
flutter pub add lexicon
1.1.2. Import #
import 'package:lexicon/lexicon.dart';
1.1.3. Implementation #
import 'package:lexicon/docs.dart' as docs;
import 'package:lexicon/lexicon.dart';
void main() {
//* Easy to parse lexicon from JSON.
final appBskyFeedLike = LexiconDoc.fromJson({
'lexicon': 1,
'id': 'app.bsky.feed.like',
'defs': {
'main': {
'type': 'record',
'description': 'A declaration of a like.',
'key': 'tid',
'record': {
'type': 'object',
'required': ['subject', 'createdAt'],
'properties': {
'subject': {'type': 'ref', 'ref': 'com.atproto.repo.strongRef'},
'createdAt': {'type': 'string', 'format': 'datetime'}
}
}
}
}
});
print(appBskyFeedLike.id);
print(appBskyFeedLike.description);
print(appBskyFeedLike.defs);
//* Or you can use prepared official lexicons.
final appBskyFeedPost = LexiconDoc.fromJson(docs.appBskyFeedPost);
print(appBskyFeedPost);
//* Also you can see all official lexicons.
for (final lexicon in docs.lexicons) {
final lexiconDoc = LexiconDoc.fromJson(lexicon);
print(lexiconDoc.id);
print(lexiconDoc.description);
print(lexiconDoc.defs);
}
}