cosmos_epub 0.0.2 copy "cosmos_epub: ^0.0.2" to clipboard
cosmos_epub: ^0.0.2 copied to clipboard

EPUB reader package with great UI, easy customization and awesome features

CosmosEpub 💫 #

CosmosEpub is a Flutter package that allows users to open and read EPUB files easily. It provides features like opening EPUB files from assets or local path, changing themes, adjusting font styles and sizes, accessing chapter contents, and more. The reader is responsive, enabling its use with both normal-sized smartphones and tablets.

Showcase #

banner

Features #

  • Open EPUB files from assets or local path.
  • Change themes with 5 options: Grey, Purple, White, Black, and Pink
  • Customize font style and size
  • Access table of contents and navigate to specific chapters
  • Display current chapter name at the bottom of the screen
  • Previous and next buttons to switch between chapters
  • Adjust screen brightness
  • Save book reading progress
  • Nice page flip animation while reading
  • ...and feel free to ask for new features @ generalmarshallinbox@gmail.com or open an issue.

Getting Started #

In your flutter project add the dependency:

dependencies:
  cosmos_epub: ^x.y.z
copied to clipboard

Run the command:

flutter pub get
copied to clipboard

For more information, check out the documentation.

Usage example #

Import the package in your Dart code:

import 'package:cosmos_epub/cosmos_epub.dart';
copied to clipboard

First things first, you have to initialize databases before using any other method. Kindly, do it earlier, preferably in the main.dart file.

There are various methods to control over book progress DB too for your ease :)

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initializer and methods return a bool
  var _initialized = await CosmosEpub.initialize();
  
  if (_initialized) {
    BookProgressModel bookProgress = CosmosEpub.getBookProgress('bookId');
    await CosmosEpub.setCurrentPageIndex('bookId', 1);
    await CosmosEpub.setCurrentChapterIndex('bookId', 2);
    await CosmosEpub.deleteBookProgress('bookId');
    await CosmosEpub.deleteAllBooksProgress();
  }

  runApp(MyApp());
}
copied to clipboard

To open an EPUB file from the assets, use the openAssetBook method:

 await CosmosEpub.openAssetBook(
     assetPath: 'assets/book.epub',
     context: context,
     // Book ID is required to save the progress for each opened book
     bookId: '3',
     // Callbacks are optional
     onPageFlip: (int currentPage, int totalPages) {
       print(currentPage);
     },
     onLastPage: (int lastPageIndex) {
       print('We arrived to the last widget');
     });
copied to clipboard

To open an EPUB file from a local storage, use the openLocalBook method:

 await CosmosEpub.openLocalBook(
     localPath: book.path,
     context: context,
     // Book ID is required to save the progress for each opened book
     bookId: '3'
     // Callbacks are optional
     onPageFlip: (int currentPage, int totalPages) {
       print(currentPage);
     },
     onLastPage: (int lastPageIndex) {
       print('We arrived to the last widget');
     });
copied to clipboard

Also you can use CosmosEpub.openURLBook and CosmosEpub.openFileBook for your convenience.

For clearing theming cache, use this method:

  await CosmosEpub.clearThemeCache();
copied to clipboard

Note: I haven't handled all exceptions, so control it on your own side. For example, if you give same bookId to the another book, it can open page and chapter from that book's progress or may break 💀

Feel free to contact me if you have any questions: https://allmylinks.com/mamasodikov

40
likes
130
points
120
downloads

Publisher

verified publisherflutterdev.uz

Weekly Downloads

2024.09.19 - 2025.04.03

EPUB reader package with great UI, easy customization and awesome features

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

epubx, fading_edge_scrollview, flutter, flutter_html_reborn, flutter_screenutil, fluttertoast, get_storage, html, http, isar, isar_flutter_libs, path_provider, screen_brightness

More

Packages that depend on cosmos_epub