JideGuru / epub_viewer

An epub reader for Flutter. Wrapped around Folioreader.(WIP)
https://pub.dev/packages/epub_viewer
Apache License 2.0
146 stars 80 forks source link

book URL #86

Closed Leokays closed 3 years ago

Leokays commented 3 years ago

Issue / Feature -

trying to run the epub viewer code and I keep crashing when I press the epub_buttton on android. What am I missing? Kindly help. I have the code and the crash error below.

Platform (android, iOS or both) - Android Crash / Error - I/flutter ( 7414): Directory: '/data/user/0/com.kayembe.dream_keys/app_flutter' I/flutter ( 7414): /data/user/0/com.kayembe.dream_keys/app_flutter/chair.epub I/SavedLocation( 7414): -> savedLocation -> {"bookId":"2239","href":"/OEBPS/ch06.xhtml","created":1539934158390,"locations":{"cfi":"epubcfi(/0!/4/4[simple_book]/2/2/6)"}} W/Java7Support( 7414): Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added E/flutter ( 7414): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Unable to load asset: assets/4.epub E/flutter ( 7414): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:227:7) E/flutter ( 7414): E/flutter ( 7414): #1 Util.getFileFromAsset (package:epub_viewer/utils/util.dart:27:21) E/flutter ( 7414): E/flutter ( 7414): #2 EpubViewer.openAsset (package:epub_viewer/epub_viewer.dart:59:22) E/flutter ( 7414): E/flutter ( 7414): #3 _DecodingDaesiState.build. (package:dream_keys/screens/decoding_daesi.dart:676:15) E/flutter ( 7414): E/flutter ( 7414): V/FolioActivity( 7414): -> initDistractionFreeMode V/FolioActivity( 7414): -> hideSystemUI V/FolioActivity( 7414): -> showSystemUI W/embe.dream_key( 7414): Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) W/embe.dream_key( 7414): Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) V/FolioActivity( 7414): -> setNightMode V/FolioActivity( 7414): -> initMediaController V/FolioActivity( 7414): -> setupBook V/FolioActivity( 7414): -> initBook E/FileUtil( 7414): alice.epub E/FolioActivity( 7414): -> Failed to initialize book E/FolioActivity( 7414): java.lang.IllegalStateException: extensionString must not be null E/FolioActivity( 7414): at com.folioreader.ui.activity.FolioActivity.initBook(FolioActivity.kt:509) E/FolioActivity( 7414): at com.folioreader.ui.activity.FolioActivity.setupBook(FolioActivity.kt:487) E/FolioActivity( 7414): at com.folioreader.ui.activity.FolioActivity.onCreate(FolioActivity.kt:301) E/FolioActivity( 7414): at android.app.Activity.performCreate(Activity.java:8000) E/FolioActivity( 7414): at android.app.Activity.performCreate(Activity.java:7984) E/FolioActivity( 7414): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) E/FolioActivity( 7414): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422) E/FolioActivity( 7414): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) E/FolioActivity( 7414): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) E/FolioActivity( 7414): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) E/FolioActivity( 7414): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) E/FolioActivity( 7414): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) E/FolioActivity( 7414): at android.os.Handler.dispatchMessage(Handler.java:106) E/FolioActivity( 7414): at android.os.Looper.loop(Looper.java:223) E/FolioActivity( 7414): at android.app.ActivityThread.main(ActivityThread.java:7656) E/FolioActivity( 7414): at java.lang.reflect.Method.invoke(Native Method) E/FolioActivity( 7414): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/FolioActivity( 7414): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) V/FolioActivity( 7414): -> onPostCreate V/FolioActivity( 7414): -> onResume V/FolioAppBarLayout( 7414): -> onApplyWindowInsets V/FolioAppBarLayout( 7414): -> onApplyWindowInsets V/FolioActivity( 7414): -> onOptionsItemSelected -> drawer D/AndroidRuntime( 7414): Shutting down VM E/AndroidRuntime( 7414): FATAL EXCEPTION: main E/AndroidRuntime( 7414): Process: com.kayembe.dream_keys, PID: 7414 E/AndroidRuntime( 7414): kotlin.KotlinNullPointerException E/AndroidRuntime( 7414): at com.folioreader.ui.activity.FolioActivity.startContentHighlightActivity(FolioActivity.kt:455) E/AndroidRuntime( 7414): at com.folioreader.ui.activity.FolioActivity.onOptionsItemSelected(FolioActivity.kt:422) E/AndroidRuntime( 7414): at android.app.Activity.onMenuItemSelected(Activity.java:4269) E/AndroidRuntime( 7414): at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:384) E/AndroidRuntime( 7414): at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:219) E/AndroidRuntime( 7414): at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:109) E/AndroidRuntime( 7414): at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:109) E/AndroidRuntime( 7414): at androidx.appcompat.widget.ToolbarWidgetWrapper$1.onClick(ToolbarWidgetWrapper.java:188) E/AndroidRuntime( 7414): at android.view.View.performClick(View.java:7448) E/AndroidRuntime( 7414): at android.view.View.performClickInternal(View.java:7425) E/AndroidRuntime( 7414): at android.view.View.access$3600(View.java:810) E/AndroidRuntime( 7414): at android.view.View$PerformClick.run(View.java:28305) E/AndroidRuntime( 7414): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime( 7414): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 7414): at android.os.Looper.loop(Looper.java:223) E/AndroidRuntime( 7414): at android.app.ActivityThread.main(ActivityThread.java:7656) E/AndroidRuntime( 7414): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 7414): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/AndroidRuntime( 7414): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) I/Process ( 7414): Sending signal. PID: 7414 SIG: 9

Steps to reproduce / Describe in detail -

here is the code:

import 'dart:convert'; //import 'dart:html'; import 'dart:io'; ///Input and output reader. Needed to use path provider

import 'package:dio/dio.dart'; import 'package:epub_viewer/epub_viewer.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; ///location for saving app files on device import 'package:permission_handler/permission_handler.dart'; //import 'package:flutter/foundation.dart'; //import 'dart:async';

class DecodingDaesi extends StatefulWidget {

DecodingDaesi({@required this.uid, @required this.userIDEmail}); final String uid; final String userIDEmail;

static String id = 'decoding_daesi';

TextEditingController nameInputController;

@override _DecodingDaesiState createState() => _DecodingDaesiState(); }

class _DecodingDaesiState extends State {

bool loading = false; Dio dio = new Dio();

@override void initState() { super.initState(); // download(); }

download() async { if (Platform.isIOS) { print('download'); // await downloadFile(); } else { loading = false; } }

@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text('Plugin example app'), ), body: Center( child: loading ? CircularProgressIndicator() : FlatButton( onPressed: () async { Directory appDocDir = await getApplicationDocumentsDirectory(); print('$appDocDir');

          String iosBookPath = '${appDocDir.path}/chair.epub';
          print(iosBookPath);
          String androidBookPath = 'file:///android_asset/alice.epub';
          EpubViewer.setConfig(
              themeColor: Theme.of(context).primaryColor,
              identifier: "iosBook",
              scrollDirection: EpubScrollDirection.ALLDIRECTIONS,
              allowSharing: true,
              enableTts: true,
              nightMode: true);
               EpubViewer.open(
                 Platform.isAndroid ? androidBookPath : iosBookPath,
                 lastLocation: EpubLocator.fromJson({
                   "bookId": "2239",
                   "href": "/OEBPS/ch06.xhtml",
                   "created": 1539934158390,
                   "locations": {
                     "cfi": "epubcfi(/0!/4/4[simple_book]/2/2/6)"
                   }
                 }),
               );

          await EpubViewer.openAsset(
            'assets/4.epub',
            lastLocation: EpubLocator.fromJson({
              "bookId": "2239",
              "href": "/OEBPS/ch06.xhtml",
              "created": 1539934158390,
              "locations": {
                "cfi": "epubcfi(/0!/4/4[simple_book]/2/2/6)"
              }
            }),
          );
          // get current locator
          EpubViewer.locatorStream.listen((locator) {
            print(
                'LOCATOR: ${EpubLocator.fromJson(jsonDecode(locator))}');
          });
        },
        child: Container(
          child: Text('open epub'),
        ),
      ),
    ),
  ),
);

}

// Future downloadFile() async { // print('download1'); // PermissionStatus permission = await PermissionHandler() // .checkPermissionStatus(PermissionGroup.storage); // // if (permission != PermissionStatus.granted) { // await PermissionHandler().requestPermissions([PermissionGroup.storage]); // await startDownload(); // } else { // await startDownload(); // } // }

startDownload() async { Directory appDocDir = Platform.isAndroid ? await getExternalStorageDirectory() : await getApplicationDocumentsDirectory();

String path = appDocDir.path + '/chair.epub';
File file = File(path);

// await file.delete();

if (!File(path).existsSync()) {
  await file.create();
  await dio.download(
    'https://github.com/FolioReader/FolioReaderKit/raw/master/Example/'
        'Shared/Sample%20eBooks/The%20Silver%20Chair.epub',
    path,
    deleteOnError: true,
    onReceiveProgress: (receivedBytes, totalBytes) {
      print((receivedBytes / totalBytes * 100).toStringAsFixed(0));
      //Check if download is complete and close the alert dialog
      if (receivedBytes == totalBytes) {
        loading = false;
        setState(() {});
      }
    },
  );
} else {
  loading = false;
  setState(() {});
}

} }

Leokays commented 3 years ago

Closed and restarted app and it did not crash. Not really sure what was causing the crash.