Skip to content
New issue

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

Main #514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Main #514

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
1 change: 1 addition & 0 deletions packages/epub_view/example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions packages/epub_view/example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
164 changes: 113 additions & 51 deletions packages/epub_view/lib/src/ui/epub_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import 'package:epub_view/src/data/models/paragraph.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
//import 'package:flutter_html_all/flutter_html_all.dart';
//import 'package:flutter_html/flutter_html.dart' as flutter_html;

export 'package:epubx/epubx.dart' hide Image;

Expand Down Expand Up @@ -316,60 +318,120 @@ class _EpubViewState extends State<EpubView> {
),
);

static Widget _chapterBuilder(
BuildContext context,
EpubViewBuilders builders,
EpubBook document,
List<EpubChapter> chapters,
List<Paragraph> paragraphs,
int index,
int chapterIndex,
int paragraphIndex,
ExternalLinkPressed onExternalLinkPressed,
) {
if (paragraphs.isEmpty) {
return Container();
}

final defaultBuilder = builders as EpubViewBuilders<DefaultBuilderOptions>;
final options = defaultBuilder.options;
// static Widget _chapterBuilder(
// BuildContext context,
// EpubViewBuilders builders,
// EpubBook document,
// List<EpubChapter> chapters,
// List<Paragraph> paragraphs,
// int index,
// int chapterIndex,
// int paragraphIndex,
// ExternalLinkPressed onExternalLinkPressed,
// ) {
// if (paragraphs.isEmpty) {
// return Container();
// }

// final defaultBuilder = builders as EpubViewBuilders<DefaultBuilderOptions>;
// final options = defaultBuilder.options;

// return Column(
// children: <Widget>[
// if (chapterIndex >= 0 && paragraphIndex == 0)
// builders.chapterDividerBuilder(chapters[chapterIndex]),
// Html(
// data: paragraphs[index].element.outerHtml,
// onLinkTap: (href, _, __) => onExternalLinkPressed(href!),
// style: {
// 'html': Style(
// padding: HtmlPaddings.only(
// top: (options.paragraphPadding as EdgeInsets?)?.top,
// right: (options.paragraphPadding as EdgeInsets?)?.right,
// bottom: (options.paragraphPadding as EdgeInsets?)?.bottom,
// left: (options.paragraphPadding as EdgeInsets?)?.left,
// ),
// ).merge(Style.fromTextStyle(options.textStyle)),
// },
// extensions: [
// TagExtension(
// tagsToExtend: {"img"},
// builder: (imageContext) {
// final url =
// imageContext.attributes['src']!.replaceAll('../', '');
// final content = Uint8List.fromList(
// document.Content!.Images![url]!.Content!);
// return Image(
// image: MemoryImage(content),
// );
// },
// ),
// ],
// ),
// ],
// );
// }


static Widget _chapterBuilder(
BuildContext context,
EpubViewBuilders builders,
EpubBook document,
List<EpubChapter> chapters,
List<Paragraph> paragraphs,
int index,
int chapterIndex,
int paragraphIndex,
ExternalLinkPressed onExternalLinkPressed,
) {
if (paragraphs.isEmpty) {
return Container();
}

return Column(
children: <Widget>[
if (chapterIndex >= 0 && paragraphIndex == 0)
builders.chapterDividerBuilder(chapters[chapterIndex]),
Html(
data: paragraphs[index].element.outerHtml,
onLinkTap: (href, _, __) => onExternalLinkPressed(href!),
style: {
'html': Style(
padding: HtmlPaddings.only(
top: (options.paragraphPadding as EdgeInsets?)?.top,
right: (options.paragraphPadding as EdgeInsets?)?.right,
bottom: (options.paragraphPadding as EdgeInsets?)?.bottom,
left: (options.paragraphPadding as EdgeInsets?)?.left,
),
).merge(Style.fromTextStyle(options.textStyle)),
},
extensions: [
TagExtension(
tagsToExtend: {"img"},
builder: (imageContext) {
final url =
imageContext.attributes['src']!.replaceAll('../', '');
final content = Uint8List.fromList(
document.Content!.Images![url]!.Content!);
return Image(
image: MemoryImage(content),
);
},
final defaultBuilder = builders as EpubViewBuilders<DefaultBuilderOptions>;
final options = defaultBuilder.options;

return Column(
children: <Widget>[
if (chapterIndex >= 0 && paragraphIndex == 0)
builders.chapterDividerBuilder(chapters[chapterIndex]),
Html(
data: paragraphs[index].element.outerHtml,
style: {
'html': Style(
padding: HtmlPaddings.only(
top: (options.paragraphPadding as EdgeInsets?)?.top,
right: (options.paragraphPadding as EdgeInsets?)?.right,
bottom: (options.paragraphPadding as EdgeInsets?)?.bottom,
left: (options.paragraphPadding as EdgeInsets?)?.left,
),
],
).merge(Style.fromTextStyle(options.textStyle)),
},
extensions: [
TagExtension(
tagsToExtend: {"img"},
builder: (imageContext) {
final url =
imageContext.attributes['src']!.replaceAll('../', '');
final content = Uint8List.fromList(
document.Content!.Images![url]!.Content!);
return Image(
image: MemoryImage(content),
);
},
),
],
),
Padding(
padding: options.paragraphPadding ?? EdgeInsets.zero,
child: SelectableText(
paragraphs[index].element.text,
style: options.textStyle,
),
],
);
}

),
],
);
}
Widget _buildLoaded(BuildContext context) {
return ScrollablePositionedList.builder(
shrinkWrap: widget.shrinkWrap,
Expand Down
4 changes: 2 additions & 2 deletions packages/epub_view/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ dependencies:
epubx: ^4.0.0
equatable: ^2.0.5
html: ^0.15.4
flutter_html: ^3.0.0-beta.2
flutter_html: ^3.0.0-alpha.5
scrollable_positioned_list: ^0.3.8
collection: ^1.17.1
universal_file: ^1.0.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down