Step 1 : Add Vocsy EpubViewer Dependency (Always Check Latest Version)
vocsy_epub_viewer: ^0.0.8
Step 2 : Make a New Class For Epub
///*** Put This Class In Glabally ***
class EpuB extends StatefulWidget {
EpuB({this.id, this.path});
int id;
String path;
@override
_EpuBState createState() => _EpuBState();
}
class _EpuBState extends State {
EpubLocator epubLocator;
@override
void initState() {
Navigator.of(context).pop();
epubLocator = EpubLocator();
EpubViewer.setConfig(
themeColor: Colors.blue,
identifier: "book",
scrollDirection: EpubScrollDirection.ALLDIRECTIONS,
allowSharing: true,
enableTts: true,
nightMode: false);
// bannerImage2();
open();
super.initState();
}
open() async {
SharedPreferences pref = await SharedPreferences.getInstance();
String locatorPref = pref.getString('locator');
try {
if (locatorPref != null) {
Map r = jsonDecode(locatorPref);
setState(() {
epubLocator = EpubLocator.fromJson(r);
});
}
} on Exception {
epubLocator = EpubLocator();
pref.remove('locator');
}
try {
EpubViewer.open(widget.path, lastLocation: epubLocator);
} catch (e) {
print(e);
}
EpubViewer.locatorStream.listen((locator) {
pref.remove('locator');
pref.setString('locator', locator);
print('LOCATOR: ${EpubLocator.fromJson(jsonDecode(locator))}');
// convert locator from string to json and save to your database to be retrieved later
});
}
@override
Widget build(BuildContext context) {
var i = widget.path;
return Container();
}
}
Step 3 : Call When And Where You Want
Navigator.push(context,MaterialPageRoute(
builder: (context) {
return EpuB(
id: /* Enter Your Book Id*/,
path: /*Enter Path Where You Download File*/);