We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import 'dart:async'; import 'dart:developer'; import 'dart:io';
import 'package:epub_view/epub_view.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart';
class EpubViewerPage extends StatefulWidget { final String path; final String lastLocation; const EpubViewerPage( {super.key, required this.path, required this.lastLocation});
@OverRide State createState() => _EpubViewerPageState(); }
class _EpubViewerPageState extends State { late EpubController _epubController; bool darkMode = false; StreamSubscription? _chapterIndexSubscription; StreamSubscription? _cfiSubscription;
Future _loadFromPath(String filePath) async { final file = File(filePath); return await file.readAsBytes(); }
@OverRide void initState() { super.initState(); _epubController = EpubController( // Load document document: EpubReader.readBook(_loadFromPath(widget.path)), // Set start point epubCfi: '/6/0[null]!/4/2/4', ); }
@OverRide Widget build(BuildContext context) => Theme( data: darkMode ? ThemeData.dark() : ThemeData.light(), child: Scaffold( appBar: AppBar( // Show actual chapter name title: EpubViewActualChapter( controller: _epubController, builder: (chapterValue) => Text( 'Chapter: ' + (chapterValue?.chapter?.Title ?.replaceAll('\n', '') .trim() ?? ''), textAlign: TextAlign.start, ), ), // Add a button to the AppBar actions actions: [ IconButton( icon: darkMode ? const Icon(Icons.light_mode) : const Icon(Icons.dark_mode), onPressed: () { setState(() { darkMode = !darkMode; }); // Manage the button press event here // For example, you can open a settings screen or perform any other action }, ), ], ), // Show table of contents drawer: Drawer( child: GestureDetector( onTap: () { Navigator.pop(context); }, child: EpubViewTableOfContents( controller: epubController, loader: const CircularProgressIndicator( color: Colors.red, ), // itemBuilder: (context, index, chapter, itemCount) { // return Container( // height: 100, // width: 100, // color: Colors.red, // ); // }, ), ), ), // Show epub document body: EpubView( builders: EpubViewBuilders( options: const DefaultBuilderOptions(), chapterDividerBuilder: () => const Divider( color: Colors.red, ), ), controller: _epubController, onExternalLinkPressed: (href) {}, onDocumentLoaded: (document) { log("Closed"); inspect(document); }, onChapterChanged: (chapter) { log("chapter changed"); String? loc = _epubController.epubCfi; log(loc.toString()); }, onDocumentError: (error) {}, ), ), ); }
The text was updated successfully, but these errors were encountered:
When will this bug be fixed?
Sorry, something went wrong.
SergeShkurko
No branches or pull requests
import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'package:epub_view/epub_view.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
class EpubViewerPage extends StatefulWidget {
final String path;
final String lastLocation;
const EpubViewerPage(
{super.key, required this.path, required this.lastLocation});
@OverRide
State createState() => _EpubViewerPageState();
}
class _EpubViewerPageState extends State {
late EpubController _epubController;
bool darkMode = false;
StreamSubscription? _chapterIndexSubscription;
StreamSubscription? _cfiSubscription;
Future _loadFromPath(String filePath) async {
final file = File(filePath);
return await file.readAsBytes();
}
@OverRide
void initState() {
super.initState();
_epubController = EpubController(
// Load document
document: EpubReader.readBook(_loadFromPath(widget.path)),
// Set start point
epubCfi: '/6/0[null]!/4/2/4',
);
}
@OverRide
Widget build(BuildContext context) => Theme(
data: darkMode ? ThemeData.dark() : ThemeData.light(),
child: Scaffold(
appBar: AppBar(
// Show actual chapter name
title: EpubViewActualChapter(
controller: _epubController,
builder: (chapterValue) => Text(
'Chapter: ' +
(chapterValue?.chapter?.Title
?.replaceAll('\n', '')
.trim() ??
''),
textAlign: TextAlign.start,
),
),
// Add a button to the AppBar actions
actions: [
IconButton(
icon: darkMode
? const Icon(Icons.light_mode)
: const Icon(Icons.dark_mode),
onPressed: () {
setState(() {
darkMode = !darkMode;
});
// Manage the button press event here
// For example, you can open a settings screen or perform any other action
},
),
],
),
// Show table of contents
drawer: Drawer(
child: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: EpubViewTableOfContents(
controller: epubController,
loader: const CircularProgressIndicator(
color: Colors.red,
),
// itemBuilder: (context, index, chapter, itemCount) {
// return Container(
// height: 100,
// width: 100,
// color: Colors.red,
// );
// },
),
),
),
// Show epub document
body: EpubView(
builders: EpubViewBuilders(
options: const DefaultBuilderOptions(),
chapterDividerBuilder: () => const Divider(
color: Colors.red,
),
),
controller: _epubController,
onExternalLinkPressed: (href) {},
onDocumentLoaded: (document) {
log("Closed");
inspect(document);
},
onChapterChanged: (chapter) {
log("chapter changed");
String? loc = _epubController.epubCfi;
log(loc.toString());
},
onDocumentError: (error) {},
),
),
);
}
The text was updated successfully, but these errors were encountered: