flutter_open_library 0.1.0 copy "flutter_open_library: ^0.1.0" to clipboard
flutter_open_library: ^0.1.0 copied to clipboard

A modern, type-safe, and comprehensive Flutter package for the Open Library API, featuring high-level models and clean networking with Dio.

flutter_open_library #

A modern, type-safe, and comprehensive Flutter package for the Open Library API.

pub package License: MIT

Features #

  • Modern Dart 3+ Architecture: Utilizes sealed classes for API results and Freezed for immutable models.
  • Comprehensive API Coverage:
    • Search: Search by title, author, or general query.
    • Books (ISBN): Get detailed metadata by ISBN.
    • Authors: Fetch author bios and bibliography.
    • Works & Editions: Differentiate between abstract works and physical editions.
    • Subjects: Browse books by category.
  • Improved Cover Handling: Provides direct URLs for small, medium, and large covers for easy integration with libraries like cached_network_image.
  • Dio Powered: Efficient networking with support for custom interceptors and error handling.

Getting Started #

Add the dependency to your pubspec.yaml:

dependencies:
  flutter_open_library: ^0.1.0

Usage #

Initialize the Client #

import 'package:flutter_open_library/flutter_open_library.dart';

final client = OpenLibraryClient(
  userAgent: 'my_awesome_app (https://github.com/user/repo)',
);

Search for Books #

final result = await client.search(title: 'the lord of the rings');

if (result is OLSuccess<SearchResponse>) {
  final books = result.data.books;
  for (var book in books) {
    print('Found: ${book.title} by ${book.authorNames?.join(', ')}');
  }
} else if (result is OLFailure) {
  print('Error: ${result.message}');
}

Fetch a Specific Book by ISBN #

final result = await client.getBookByIsbn('9780140328721');

if (result is OLSuccess<Book>) {
  print('Title: ${result.data.title}');
  print('Publish Date: ${result.data.publishDate}');
}

Fetch Author Details #

final result = await client.getAuthor('OL26320A');

if (result is OLSuccess<Author>) {
  print('Name: ${result.data.name}');
  print('Bio: ${result.data.bio}');
}

Why this package? #

The original open_library package was last updated years ago. This version provides:

  1. Type Safety: No more checking runtimeType.
  2. Modern Patterns: Pattern matching on OLResult (Success/Failure).
  3. URL-based Resource Handling: Get URLs for covers instead of raw bytes, allowing for better caching.

License #

MIT

1
likes
160
points
144
downloads

Publisher

unverified uploader

Weekly Downloads

A modern, type-safe, and comprehensive Flutter package for the Open Library API, featuring high-level models and clean networking with Dio.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dio, flutter, freezed_annotation, json_annotation

More

Packages that depend on flutter_open_library