ScerIO / packages.flutter

👨‍💻 Plugins and packages for Flutter framework
https://pub.dev/publishers/serge.software/packages
MIT License
437 stars 420 forks source link

getting cfi as null "/6/0[null]!/4/2/4" in middle #499

Open Himanshusha673 opened 3 months ago

Himanshusha673 commented 3 months ago

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) {}, ), ), ); }

abdulwahhab1 commented 3 weeks ago

When will this bug be fixed?