youversion_sdk 0.0.3 copy "youversion_sdk: ^0.0.3" to clipboard
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.

example/example.dart

// 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');
  }
}
0
likes
150
points
12
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

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.

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

dio, flutter, freezed_annotation, json_annotation

More

Packages that depend on youversion_sdk