flutter_open_library
A modern, type-safe, and comprehensive Flutter package for the Open Library API.
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:
- Type Safety: No more checking
runtimeType. - Modern Patterns: Pattern matching on
OLResult(Success/Failure). - URL-based Resource Handling: Get URLs for covers instead of raw bytes, allowing for better caching.
License
MIT
Libraries
- flutter_open_library
- A modern, type-safe Flutter package for the Open Library API.