Skip to content

Commit

Permalink
Exposed EpubChapterRef and updated flutter_ex
Browse files Browse the repository at this point in the history
flutter_ex now shows chapter count and the Cover Image (if present)
  • Loading branch information
orthros committed May 17, 2019
1 parent ae06ac5 commit d731778
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 48 deletions.
54 changes: 50 additions & 4 deletions example/flutter_ex/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:epub/epub.dart' as epub;
import 'package:image/image.dart' as image;

void main() => runApp(EpubWidget());

Expand Down Expand Up @@ -33,8 +34,8 @@ class EpubState extends State<EpubWidget> {
color: Colors.white,
child: new Container(
child: new Center(
child: new Column(children: [
new Padding(padding: EdgeInsets.only(top: 140.0)),
child: new ListView(children: [
new Padding(padding: EdgeInsets.only(top: 70.0)),
new Text(
'Epub Inspector',
style: new TextStyle(fontSize: 25.0),
Expand Down Expand Up @@ -104,6 +105,8 @@ class EpubState extends State<EpubWidget> {
}

Widget buildEpubWidget(epub.EpubBookRef book) {
var chapters = book.getChapters();
var cover = book.readCover();
return Container(
child: new Column(
children: <Widget>[
Expand All @@ -125,12 +128,55 @@ Widget buildEpubWidget(epub.EpubBookRef book) {
Text(
book.Author,
style: TextStyle(fontSize: 15.0),
)
),
new Padding(
padding: EdgeInsets.only(top: 15.0),
),
FutureBuilder<List<epub.EpubChapterRef>>(
future: chapters,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: <Widget>[
Text("Chapters", style: TextStyle(fontSize: 20.0)),
Text(
snapshot.data.length.toString(),
style: TextStyle(fontSize: 15.0),
)
],
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Container();
}),
new Padding(
padding: EdgeInsets.only(top: 15.0),
),
FutureBuilder<epub.Image>(
future: cover,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: <Widget>[
Text("Cover", style: TextStyle(fontSize: 20.0)),
Image.memory(image.encodePng(snapshot.data)),
],
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Container();
},
),
],
));
}

// Needs a url to a valid url to an epub like 'https://www.gutenberg.org/ebooks/11.epub.images'
// Needs a url to a valid url to an epub such as
// https://www.gutenberg.org/ebooks/11.epub.images
// or
// https://www.gutenberg.org/ebooks/19002.epub.images
Future<epub.EpubBookRef> fetchBook(String url) async {
// Hard coded to Alice Adventures In Wonderland in Project Gutenberb
final response = await http.get(url);
Expand Down
51 changes: 7 additions & 44 deletions example/flutter_ex/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
name: flutter_ex
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
Expand All @@ -26,51 +16,24 @@ dependencies:

# Epub
epub: ^2.0.0
# To get the epub from the internet
http: ^0.12.0+2

image: ^2.0.0

dependency_overrides:
epub:
path: ../../

dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
1 change: 1 addition & 0 deletions lib/epub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'src/utils/enum_from_string.dart';
export 'src/epub_reader.dart';
export 'src/epub_writer.dart';
export 'src/ref_entities/epub_book_ref.dart';
export 'src/ref_entities/epub_chapter_ref.dart';
export 'src/entities/epub_book.dart';
export 'src/entities/epub_chapter.dart';
export 'src/entities/epub_content.dart';
Expand Down

0 comments on commit d731778

Please sign in to comment.