Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions packages/epub_view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pure flutter widget (non native) for view EPUB documents on all platforms. Based

## Showcase

<img width="50%" src="https://raw.githubusercontent.com/ScerIO/packages.flutter/main/packages/epub_view/example/media/example.gif?raw=true" />
<img width="50%" src="https://raw.githubusercontent.com/ScerIO/packages.flutter/main/packages/epub_view/example/media/example.gif?raw=true" alt="Snapshot of epub_view example project"/>

## Getting Started
In your flutter project add the dependency:
Expand Down Expand Up @@ -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
Expand All @@ -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<Uint8List> data = []; // Uint8List from file

EpubDocument.openAsset('assets/sample.pdf');

EpubDocument.openData(FutureOr<Uint8List> 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:**

Expand All @@ -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) {},
);
}
```
2 changes: 2 additions & 0 deletions packages/epub_view/example/ios/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**/dgph
*.mode1v3
*.mode2v3
*.moved-aside
Expand All @@ -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/
Expand Down
3 changes: 1 addition & 2 deletions packages/epub_view/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
}

Brightness get platformBrightness =>
MediaQueryData.fromView(WidgetsBinding.instance.window)
.platformBrightness;
MediaQueryData.fromView(View.of(context)).platformBrightness;

void _setSystemUIOverlayStyle() {
if (platformBrightness == Brightness.light) {
Expand Down
2 changes: 1 addition & 1 deletion packages/epub_view/lib/epub_view.dart
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion packages/epub_view/lib/src/data/epub_cfi/_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions script/tool/lib/src/common/plugin_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ abstract class PluginCommand extends Command<void> {
/// 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) {
Expand Down
4 changes: 2 additions & 2 deletions script/tool/lib/src/common/xcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Xcode {
final List<String> args = <String>[
_xcodeBuildCommand,
...actions,
if (workspace != null) ...<String>['-workspace', workspace],
if (scheme != null) ...<String>['-scheme', scheme],
...<String>['-workspace', workspace],
...<String>['-scheme', scheme],
if (configuration != null) ...<String>['-configuration', configuration],
...extraFlags,
];
Expand Down
4 changes: 2 additions & 2 deletions script/tool/lib/src/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, <String>['format'],
files: dartFiles);
final int exitCode =
await _runBatched(dartCommand, <String>['format'], files: dartFiles);
if (exitCode != 0) {
printError('Failed to format Dart files: exit code $exitCode.');
throw ToolExit(_exitFlutterFormatFailed);
Expand Down