Support
Quality
Security
License
Reuse
kandi has reviewed BookReader and discovered the below as its top functions. This is intended to give you an instant insight into BookReader implemented functionality, and help decide if they suit your requirements.
:closed_book: "任阅" 网络小说阅读器,3D翻页效果、txt/pdf/epub书籍阅读、Wifi传书~
LICENSE
Copyright 2016 JustWayward Team, All right reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Unable to display html file from local storage in webview
Future<String> _loadHtmlFromAssets(int n) async {
final file = File(urls[n]);
String fileText = await file.readAsString();
final base64 = base64Encode(utf8.encode(fileText));
return "data:text/html;base64,$base64";
}
return WebView(
initialUrl: snapshot.data.toString(),
javascriptMode: JavascriptMode.unrestricted,
);
-----------------------
Future<String> _loadHtmlFromAssets(int n) async {
final file = File(urls[n]);
String fileText = await file.readAsString();
final base64 = base64Encode(utf8.encode(fileText));
return "data:text/html;base64,$base64";
}
return WebView(
initialUrl: snapshot.data.toString(),
javascriptMode: JavascriptMode.unrestricted,
);
Multithreading should close the whole process but doesn't
import pyttsx3
from pyttsx3.drivers import sapi5
from PyPDF2 import PdfFileReader
from threading import Thread
from psutil import process_iter
from easygui import enterbox,fileopenbox,msgbox,choicebox
import os
import signal
class Audiobook():
def readbook(self,title,page=0):
book = open(title, 'rb')
pdfReader = PdfFileReader(book)
pages = pdfReader.numPages
speaker = pyttsx3.init()
speaker.setProperty('rate',150)
for num in range(page-1,pages):
page = pdfReader.getPage(num)
text = page.extractText()
speaker.say(text)
speaker.runAndWait()
speaker.say("You arrived to page" + str(num+1))
def title(self):
title = fileopenbox(default="*.pdf",filetypes=["*.pdf"])
if title:
page = enterbox("From which page would you like to read? ",'Choose the page')
page = 1 if page=="" else int(page)
else:
return
self.readbook(title,page)
def killprocess(self):
kill = msgbox("Click here to stop reading","Close the Application?")
if kill is not None:
os.kill(os.getpid(),signal.SIGTERM)
bookreader = Audiobook()
process1 = Thread(target=bookreader.title)
process2 = Thread(target=bookreader.killprocess)
process2.start()
process1.start()
Connected Router - newly routed page contains additional data
<Provider>
<ConnectedRouter history={history}>
<Switch>
<Route path="/read" component={BookReader} />
<Route path="/">
<AppContainer>
<Route A />
<Route B />
<Route C />
</AppContainer>
</Route>
</Switch>
</ConnectedRouter>
</Provider>
<Router history={history}>
<Switch>
<Route path="/read" component={BookReader} />
<Route path="/" component={AppContainer} />
</Switch>
</Router>
-----------------------
<Provider>
<ConnectedRouter history={history}>
<Switch>
<Route path="/read" component={BookReader} />
<Route path="/">
<AppContainer>
<Route A />
<Route B />
<Route C />
</AppContainer>
</Route>
</Switch>
</ConnectedRouter>
</Provider>
<Router history={history}>
<Switch>
<Route path="/read" component={BookReader} />
<Route path="/" component={AppContainer} />
</Switch>
</Router>
Can't retrive data in view of an one to one polymorphic realation
@isset ($book->image)
<img src="{{$book->image->getImage()}}" alt="product image">
@endisset
<img src="{{optional($book->image)->getImage() ?? 'default_image_path.png'}}" alt="product image">
@if (isset($book->image))
<img src="{{$book->image->getImage()}}" alt="product image">
@else
<img src="default_image_path.png" alt="product image">
@endif
-----------------------
@isset ($book->image)
<img src="{{$book->image->getImage()}}" alt="product image">
@endisset
<img src="{{optional($book->image)->getImage() ?? 'default_image_path.png'}}" alt="product image">
@if (isset($book->image))
<img src="{{$book->image->getImage()}}" alt="product image">
@else
<img src="default_image_path.png" alt="product image">
@endif
-----------------------
@isset ($book->image)
<img src="{{$book->image->getImage()}}" alt="product image">
@endisset
<img src="{{optional($book->image)->getImage() ?? 'default_image_path.png'}}" alt="product image">
@if (isset($book->image))
<img src="{{$book->image->getImage()}}" alt="product image">
@else
<img src="default_image_path.png" alt="product image">
@endif
MongoDB - embedding, inserting one collection into another
db.people.aggregate([
{
$lookup: {
from: "addresses",
pipeline: [ ],
as: "addresses"
}
}
])
db.people.aggregate([
{
$lookup: {
from: "addresses",
pipeline: [ { $match: { street: "123 Fake Street" } } ],
as: "addresses"
}
}
])
-----------------------
db.people.aggregate([
{
$lookup: {
from: "addresses",
pipeline: [ ],
as: "addresses"
}
}
])
db.people.aggregate([
{
$lookup: {
from: "addresses",
pipeline: [ { $match: { street: "123 Fake Street" } } ],
as: "addresses"
}
}
])
Dagger2 not finding provided instance
@Module(includes = {RepositoriesModule.class})
class {
@Provides
@Singleton
fun provideGetRandomBookUseCase(booksRepository: BooksRepository) =
GetRandomBookUseCase(booksRepository)
}
@Component(
modules = [GetRandomBookUseCaseModule::class]
)
interface UseCasesComponent {
GetRandomBookUseCase getRandomBookUseCase();
}
-----------------------
@Module(includes = {RepositoriesModule.class})
class {
@Provides
@Singleton
fun provideGetRandomBookUseCase(booksRepository: BooksRepository) =
GetRandomBookUseCase(booksRepository)
}
@Component(
modules = [GetRandomBookUseCaseModule::class]
)
interface UseCasesComponent {
GetRandomBookUseCase getRandomBookUseCase();
}
-----------------------
@Component(
modules = [GetRandomBookUseCaseModule::class]
)
@Singleton
interface UseCasesComponent {
val getRandomBookUseCase: GetRandomBookUseCase
}
@Component(
dependencies = [UseCasesComponent::class],
modules = [BookReaderModule::class]
)
@PrototypeScope
interface BookReaderFragmentComponent {
val bookReader: BookReader
}
class BookReaderFragment : Fragment() {
lateinit var bookReader: BookReader
val component: BookReaderFragmentComponent by lazy {
DaggerBookReaderFragmentComponent
.builder()
.useCasesComponent(DaggerUseCasesComponent.create())
.bookReaderModule(BookReaderModule(context!!))
.build()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
bookReader = component.bookReader
...
}
...
}
-----------------------
@Component(
modules = [GetRandomBookUseCaseModule::class]
)
@Singleton
interface UseCasesComponent {
val getRandomBookUseCase: GetRandomBookUseCase
}
@Component(
dependencies = [UseCasesComponent::class],
modules = [BookReaderModule::class]
)
@PrototypeScope
interface BookReaderFragmentComponent {
val bookReader: BookReader
}
class BookReaderFragment : Fragment() {
lateinit var bookReader: BookReader
val component: BookReaderFragmentComponent by lazy {
DaggerBookReaderFragmentComponent
.builder()
.useCasesComponent(DaggerUseCasesComponent.create())
.bookReaderModule(BookReaderModule(context!!))
.build()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
bookReader = component.bookReader
...
}
...
}
-----------------------
@Component(
modules = [GetRandomBookUseCaseModule::class]
)
@Singleton
interface UseCasesComponent {
val getRandomBookUseCase: GetRandomBookUseCase
}
@Component(
dependencies = [UseCasesComponent::class],
modules = [BookReaderModule::class]
)
@PrototypeScope
interface BookReaderFragmentComponent {
val bookReader: BookReader
}
class BookReaderFragment : Fragment() {
lateinit var bookReader: BookReader
val component: BookReaderFragmentComponent by lazy {
DaggerBookReaderFragmentComponent
.builder()
.useCasesComponent(DaggerUseCasesComponent.create())
.bookReaderModule(BookReaderModule(context!!))
.build()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
bookReader = component.bookReader
...
}
...
}
QUESTION
Unable to display html file from local storage in webview
Asked 2021-Jun-10 at 11:53I have a Flutter project in which I am:
However, in the web view all I get is "Unable to load asset..."
Though any standard http url works fine in webview.
I tried from these two answers but no result: Answer1 & Answer2
The exception I get is :
E/flutter (10963): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Unable to load asset: /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/04/00.html
I need to understand how to make the local html at the given path display in webview.
Any help would be appreciated.
Edit:
The webview code (currently trying to display only 1st url in list):
class _BookReaderState extends State<BookReader> {
List<String> urls = UserData.ebook;
WebViewController web;
final _key = UniqueKey();
String _url;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text(
"Book Title Here",
style: GoogleFonts.roboto(
fontWeight: FontWeight.w900,
fontSize: 25.0,
color: Colors.white),
textAlign: TextAlign.center,
),
actions: [
Padding(
padding: EdgeInsets.only(right: 50),
child: IconButton(
icon: Image.asset('images/04_mobile-menu.png'),
color: Colors.red,
alignment: Alignment.centerLeft,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyLibrary_Screen()));
}),
),
Padding(
padding: const EdgeInsets.only(left: 1.0),
child: IconButton(
icon: Image.asset('images/05_mobile-close.png'),
color: Colors.red,
alignment: Alignment.centerRight,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyLibrary_Screen()));
}),
),
],
),
body: Column(
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Container(
width: 700,
height: 490,
child: FutureBuilder<String>(
future: _loadHtmlFromAssets(0),
builder: (context, snapshot) {
if (snapshot.hasData) {
return WebView(
initialUrl: new Uri.dataFromString(snapshot.data,
mimeType: 'text/html')
.toString(),
javascriptMode: JavascriptMode.unrestricted,
);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return CircularProgressIndicator();
})),
),
Padding(
padding: EdgeInsets.only(top: 85),
child: Container(
height: 70,
color: Colors.blue,
child: RowSuper(
innerDistance: 50,
children: [
InkWell(
child: Image.asset(
"images/05_mobile-arrow-left.png",
alignment: Alignment.bottomLeft,
height: 170,
width: 90,
),
onTap: () => pageIncDec(1),
),
Text('Page ${urls.indexOf(_url) + 1} of ${urls.length}',
style: GoogleFonts.roboto(
fontWeight: FontWeight.w900,
fontSize: 33.0,
color: Colors.white)),
InkWell(
child: Image.asset(
"images/05_mobile-arrow-right.png",
alignment: Alignment.bottomRight,
height: 270,
width: 90,
),
onTap: () => pageIncDec(2),
),
],
),
),
),
],
));
}
pageIncDec(int i) async {
int n;
if (i == 1) {
setState(() {
urls.indexOf(_url) > 0 ? n = urls.indexOf(_url) - 1 : n = 0;
});
} else {
setState(() {
urls.indexOf(_url) < urls.length
? n = urls.indexOf(_url) + 1
: n = urls.length - 1;
});
}
_url = await _loadHtmlFromAssets(n);
web.loadUrl(_url);
print(_url);
}
Future<String> _loadHtmlFromAssets(int n) async {
String fileText = await rootBundle.loadString(urls[n]);
print(fileText);
String r = (Uri.dataFromString(fileText,
mimeType: 'text/html', encoding: Encoding.getByName('utf-8'))
.toString());
print(r);
return r;
}
Code to add files :
Directory dir =
Directory('${_appDocDir.path}/$folderName/${item.key_name}');
List<FileSystemEntity> listOfAllFolderAndFiles =
await dir.list(recursive: false).toList();
if (UserData.ebook != null) UserData.ebook.clear();
listOfAllFolderAndFiles.forEach((element) {
if (element.toString().contains("html")) {
String url = element.toString().replaceAll("File: ", "");
url = url.replaceAll("'", "");
UserData.ebook.add(url.toString());
}
UserData.eBookTitle = item.title;
});
print(UserData.ebook);
And result of printing UserData.ebook :
I/flutter ( 3465): [/data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/00.html, /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/01.html, /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/02.html, /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/03.html, /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/04.html, /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/05.html, /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/06.html]
Checking:
//Checking if file exists
print("File ${UserData.ebook[0]} exists ? " +
File(UserData.ebook[0]).existsSync().toString());
Result:
I/flutter ( 3465): File /data/user/0/com.pts.school_ebook_reader_app_prag/app_flutter/ebooks/02/00.html exists ? true
ANSWER
Answered 2021-Jun-09 at 06:43I think you should load html as normal file, not like asset, because it's not located in Assets
directory and convert it to base64:
Future<String> _loadHtmlFromAssets(int n) async {
final file = File(urls[n]);
String fileText = await file.readAsString();
final base64 = base64Encode(utf8.encode(fileText));
return "data:text/html;base64,$base64";
}
Then show it like:
return WebView(
initialUrl: snapshot.data.toString(),
javascriptMode: JavascriptMode.unrestricted,
);
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit