v1.0.0+1cosmos_epub
Feature-rich EPUB reader package for Flutter with page flip animations, text highlighting, hyphenation, infinite nested chapters, image support, RTL languages, customizable themes and fonts.
EPUB reader package with great UI, easy customization and awesome features
{"sdk":"flutter"}^4.0.0^0.15.4^1.1.0^3.3.2^3.3.2^2.1.1^2.1.3^5.9.0^2.2.3^4.1.1^1.0.1^8.2.5{"sdk":"flutter"}^2.0.0^3.3.2^2.4.9English project snapshot. Visit GitHub for the latest content.
A feature-rich EPUB reader package for Flutter with page flip animations, text highlighting, hyphenation, infinite nested chapters, image support, RTL languages, customizable themes and fonts.
banner
Add the dependency:
dependencies:
cosmos_epub: ^1.0.0
flutter pub get
Call initialize() once before using any other method (preferably in main.dart):
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await CosmosEpub.initialize();
runApp(MyApp());
}
// From assets
await CosmosEpub.openAssetBook(
assetPath: 'assets/book.epub',
context: context,
bookId: 'my_book_1',
accentColor: Colors.indigoAccent,
onPageFlip: (currentPage, totalPages) {
print('Page $currentPage of $totalPages');
},
onLastPage: (lastPageIndex) {
print('Reached last page');
},
);
// From local file
await CosmosEpub.openLocalBook(
localPath: '/path/to/book.epub',
context: context,
bookId: 'my_book_2',
);
// From URL
await CosmosEpub.openURLBook(
urlPath: 'https://example.com/book.epub',
context: context,
bookId: 'my_book_3',
);
// From bytes
await CosmosEpub.openFileBook(
bytes: myUint8List,
context: context,
bookId: 'my_book_4',
);
// Get current progress
BookProgressModel progress = CosmosEpub.getBookProgress('my_book_1');
print('Chapter: ${progress.currentChapterIndex}');
print('Page: ${progress.currentPageIndex}');
// Set progress manually
await CosmosEpub.setCurrentChapterIndex('my_book_1', 5);
await CosmosEpub.setCurrentPageIndex('my_book_1', 3);
// Delete progress
await CosmosEpub.deleteBookProgress('my_book_1');
await CosmosEpub.deleteAllBooksProgress();
// Get all highlights for a book
List<HighlightModel> highlights = CosmosEpub.getBookHighlights('my_book_1');
// Remove a specific highlight
CosmosEpub.removeHighlight(highlights.first.id);
// Remove all highlights for a book
CosmosEpub.removeAllHighlights('my_book_1');
await CosmosEpub.clearThemeCache();
| Parameter | Type | Default | Description |
|---|---|---|---|
assetPath / localPath / urlPath / bytes |
String / Uint8List |
required | EPUB source |
context |
BuildContext |
required | Build context for navigation |
bookId |
String |
required | Unique ID for progress tracking |
accentColor |
Color |
Colors.indigoAccent |
Primary accent color |
onPageFlip |
Function(int, int)? |
null |
Called on page change |
onLastPage |
Function(int)? |
null |
Called on last page |
chapterListTitle |
String |
'Table of Contents' |
TOC screen title |
shouldOpenDrawer |
bool |
false |
Open TOC on start |
starterChapter |
int |
-1 |
Start at specific chapter |
Automatic detection and support for Right-to-Left languages:
No configuration needed — just open the EPUB and the library handles direction, alignment, and navigation automatically.
bookId. Using the same ID for different books will cause progress conflicts.isar_community for progress persistence (Android/iOS/Desktop only, no web support).BSD-3
Feel free to open an issue or reach out: https://allmylinks.com/mamasodikov