From 971e425ff3bb460f25d137cd734d9f0079042e7d Mon Sep 17 00:00:00 2001 From: Victor Carreras <34163765+vicajilau@users.noreply.github.com> Date: Sat, 14 Jun 2025 08:27:39 +0200 Subject: [PATCH 1/3] Fixed epub_view.dart project --- packages/epub_view/README.md | 65 ++++++++++++++--------- packages/epub_view/example/ios/.gitignore | 2 + packages/epub_view/example/lib/main.dart | 3 +- packages/epub_view/lib/epub_view.dart | 2 +- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/packages/epub_view/README.md b/packages/epub_view/README.md index c20df95e..11f2ea54 100644 --- a/packages/epub_view/README.md +++ b/packages/epub_view/README.md @@ -4,7 +4,7 @@ Pure flutter widget (non native) for view EPUB documents on all platforms. Based ## Showcase - +Snapshot of epub_view example project ## Getting Started In your flutter project add the dependency: @@ -60,22 +60,24 @@ Widget build(BuildContext context) => Scaffold( ### How start from last view position? This method allows you to keep the exact reading position even inside the chapter: ```dart -_epubController = EpubController( - // initialize with epub cfi string for open book from last position - epubCfi: 'epubcfi(/6/6[chapter-2]!/4/2/1612)', -); +void main() { + _epubController = EpubController( + // initialize with epub cfi string for open book from last position + epubCfi: 'epubcfi(/6/6[chapter-2]!/4/2/1612)', + ); // Attach controller -EpubView( - controller: _epubController, -); + EpubView( + controller: _epubController, + ); // Get epub cfi string // for example output - epubcfi(/6/6[chapter-2]!/4/2/1612) -final cfi = _epubController.generateEpubCfi(); + final cfi = _epubController.generateEpubCfi(); // or usage controller for navigate -_epubController.gotoEpubCfi('epubcfi(/6/6[chapter-2]!/4/2/1612)'); + _epubController.gotoEpubCfi('epubcfi(/6/6[chapter-2]!/4/2/1612)'); +} ``` ## Api @@ -84,12 +86,17 @@ _epubController.gotoEpubCfi('epubcfi(/6/6[chapter-2]!/4/2/1612)'); **Local document open:** ```dart -EpubDocument.openAsset('assets/sample.pdf') +void main() { + FutureOr data = []; // Uint8List from file + + EpubDocument.openAsset('assets/sample.pdf'); -EpubDocument.openData(FutureOr data) + EpubDocument.openData(data); // Not supports on Web -EpubDocument.openFile('path/to/file/on/device') + EpubDocument.openFile('path/to/file/on/device'); +} + ``` **Network document open:** @@ -102,30 +109,36 @@ And use it ```dart import 'package:internet_file/internet_file.dart'; -// The cors policy is required on the server. +void main() { + // The cors policy is required on the server. // You can raise your cors proxy. -EpubDocument.openData(InternetFile.get('https://link.to/book.epub')) + EpubDocument.openData(InternetFile.get('https://link.to/book.epub')); +} ``` ### Control document ```dart -// Get epub cfi string of actual view insets +void main() { + // Get epub cfi string of actual view insets // for example output - epubcfi(/6/6[chapter-2]!/4/2/1612) -final cfi = _epubController.generateEpubCfi(); + final cfi = _epubController.generateEpubCfi(); // Navigate to paragraph in document -_epubController.gotoEpubCfi('epubcfi(/6/6[chapter-2]!/4/2/1612)'); + _epubController.gotoEpubCfi('epubcfi(/6/6[chapter-2]!/4/2/1612)'); +} ``` ### Document callbacks ```dart -EpubView( - controller: epubController, - - onExternalLinkPressed: (href) {}, +void main() { + EpubView( + controller: epubController, - onDocumentLoaded: (document) {}, - onChapterChanged: (chapter) {}, - onDocumentError: (error) {}, -); + onExternalLinkPressed: (href) {}, + + onDocumentLoaded: (document) {}, + onChapterChanged: (chapter) {}, + onDocumentError: (error) {}, + ); +} ``` diff --git a/packages/epub_view/example/ios/.gitignore b/packages/epub_view/example/ios/.gitignore index e96ef602..7a7f9873 100644 --- a/packages/epub_view/example/ios/.gitignore +++ b/packages/epub_view/example/ios/.gitignore @@ -1,3 +1,4 @@ +**/dgph *.mode1v3 *.mode2v3 *.moved-aside @@ -18,6 +19,7 @@ Flutter/App.framework Flutter/Flutter.framework Flutter/Flutter.podspec Flutter/Generated.xcconfig +Flutter/ephemeral/ Flutter/app.flx Flutter/app.zip Flutter/flutter_assets/ diff --git a/packages/epub_view/example/lib/main.dart b/packages/epub_view/example/lib/main.dart index 2a74b799..e9cbadcd 100644 --- a/packages/epub_view/example/lib/main.dart +++ b/packages/epub_view/example/lib/main.dart @@ -30,8 +30,7 @@ class _MyAppState extends State with WidgetsBindingObserver { } Brightness get platformBrightness => - MediaQueryData.fromView(WidgetsBinding.instance.window) - .platformBrightness; + MediaQueryData.fromView(View.of(context)).platformBrightness; void _setSystemUIOverlayStyle() { if (platformBrightness == Brightness.light) { diff --git a/packages/epub_view/lib/epub_view.dart b/packages/epub_view/lib/epub_view.dart index 6f30ea7f..53fce7e0 100644 --- a/packages/epub_view/lib/epub_view.dart +++ b/packages/epub_view/lib/epub_view.dart @@ -1,6 +1,6 @@ export 'package:epubx/epubx.dart'; +export 'src/helpers/epub_document.dart'; export 'src/ui/actual_chapter.dart'; export 'src/ui/epub_view.dart'; export 'src/ui/table_of_contents.dart'; -export 'src/helpers/epub_document.dart'; From e9f9a4a35673d08c81b2e47185f9ce9f2a82237f Mon Sep 17 00:00:00 2001 From: Victor Carreras <34163765+vicajilau@users.noreply.github.com> Date: Sat, 14 Jun 2025 08:35:02 +0200 Subject: [PATCH 2/3] epub_view - Fixed interpolation string --- packages/epub_view/lib/src/data/epub_cfi/_parser.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/epub_view/lib/src/data/epub_cfi/_parser.dart b/packages/epub_view/lib/src/data/epub_cfi/_parser.dart index 1e0825ab..07fc1565 100644 --- a/packages/epub_view/lib/src/data/epub_cfi/_parser.dart +++ b/packages/epub_view/lib/src/data/epub_cfi/_parser.dart @@ -1039,7 +1039,7 @@ class EpubCfiParser { } if (result0 != null) { result0 = ((offset, intPartVal, fracPartVal) => - intPartVal.join('') + '.' + fracPartVal.join(''))( + "${intPartVal.join('')}.${fracPartVal.join('')}")( pos0, result0[0], result0[2]); } if (result0 == null) { From abb8c323df9b42b0e18d444968aa93f275da4f5f Mon Sep 17 00:00:00 2001 From: Victor Carreras <34163765+vicajilau@users.noreply.github.com> Date: Sat, 14 Jun 2025 08:49:25 +0200 Subject: [PATCH 3/3] tool - fixed scripts files migration --- script/tool/lib/src/common/plugin_command.dart | 3 +++ script/tool/lib/src/common/xcode.dart | 4 ++-- script/tool/lib/src/format_command.dart | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/script/tool/lib/src/common/plugin_command.dart b/script/tool/lib/src/common/plugin_command.dart index a6a1932b..a75045c2 100644 --- a/script/tool/lib/src/common/plugin_command.dart +++ b/script/tool/lib/src/common/plugin_command.dart @@ -144,6 +144,9 @@ abstract class PluginCommand extends Command { /// The command to use when running `flutter`. String get flutterCommand => platform.isWindows ? 'flutter.bat' : 'flutter'; + /// The command to use when running `dart`. + String get dartCommand => 'dart'; + /// The shard of the overall command execution that this instance should run. int get shardIndex { if (_shardIndex == null) { diff --git a/script/tool/lib/src/common/xcode.dart b/script/tool/lib/src/common/xcode.dart index 83f681bc..fc0fdbc1 100644 --- a/script/tool/lib/src/common/xcode.dart +++ b/script/tool/lib/src/common/xcode.dart @@ -42,8 +42,8 @@ class Xcode { final List args = [ _xcodeBuildCommand, ...actions, - if (workspace != null) ...['-workspace', workspace], - if (scheme != null) ...['-scheme', scheme], + ...['-workspace', workspace], + ...['-scheme', scheme], if (configuration != null) ...['-configuration', configuration], ...extraFlags, ]; diff --git a/script/tool/lib/src/format_command.dart b/script/tool/lib/src/format_command.dart index bb788ac4..cc852777 100644 --- a/script/tool/lib/src/format_command.dart +++ b/script/tool/lib/src/format_command.dart @@ -178,8 +178,8 @@ class FormatCommand extends PluginCommand { print('Formatting .dart files...'); // `flutter format` doesn't require the project to actually be a Flutter // project. - final int exitCode = await _runBatched(flutterCommand, ['format'], - files: dartFiles); + final int exitCode = + await _runBatched(dartCommand, ['format'], files: dartFiles); if (exitCode != 0) { printError('Failed to format Dart files: exit code $exitCode.'); throw ToolExit(_exitFlutterFormatFailed);