youversion_sdk 0.0.3
youversion_sdk: ^0.0.3 copied to clipboard
A production-ready, open-source Dart/Flutter SDK for the YouVersion REST API. This package provides a clean and idiomatic way to fetch Bibles, Books, Chapters, and Verses in Dart and Flutter applications.
// ignore_for_file: avoid_print
import 'dart:io';
import 'package:youversion_sdk/youversion_sdk.dart';
void main() async {
// 1. You need a Developer Token from YouVersion to use the API.
// For testing, you can either hardcode it here or pass it as an environment variable.
final token =
Platform.environment['YOUVERSION_TOKEN'] ?? 'YOUR_DEVELOPER_TOKEN_HERE';
if (token == 'YOUR_DEVELOPER_TOKEN_HERE') {
print(
'⚠️ Please replace "YOUR_DEVELOPER_TOKEN_HERE" with your actual token.',
);
print(
' Or run the script like this: YOUVERSION_TOKEN="my_token" dart run example.dart',
);
return;
}
print('Initializing YouVersion SDK...');
final client = YouVersionClient(developerToken: token, language: 'en');
try {
print('\nFetching Bibles...');
final bibles = await client.bibles.list();
if (bibles.isEmpty) {
print('No bibles found.');
return;
}
print('✅ Successfully fetched ${bibles.length} bibles!');
// Try to find a Bible that contains the Book of John, otherwise pick the first one
final firstBible = bibles.firstWhere(
(b) => b.books.contains('JHN'),
orElse: () => bibles.first,
);
print('First Bible: ${firstBible.title} (${firstBible.abbreviation})');
print('\nFetching Books for ${firstBible.abbreviation}...');
final books = await client.bibles.listBooks(firstBible.id);
if (books.isNotEmpty) {
final firstBook = books.first;
print('✅ Successfully fetched ${books.length} books!');
print('First Book: ${firstBook.fullTitle} (${firstBook.id})');
}
print('\nFetching Passage (John 3:16) for ${firstBible.abbreviation}...');
final passage = await client.bibles.getPassage(firstBible.id, 'JHN.3.16');
print('✅ Reference: ${passage.reference}');
print('Content: ${passage.content}');
} on YouVersionAuthException catch (e) {
print('❌ Authentication Failed: Your token might be invalid.');
print('Details: ${e.message}');
} on YouVersionException catch (e) {
print('❌ SDK Error: ${e.message}');
} catch (e) {
print('❌ Unexpected Error: $e');
}
}