Skip to content

Load a local file #60

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

Closed
MaskyS opened this issue Apr 9, 2018 · 12 comments
Closed

Load a local file #60

MaskyS opened this issue Apr 9, 2018 · 12 comments

Comments

@MaskyS
Copy link

MaskyS commented Apr 9, 2018

Hi, how can I open a file that is locally stored on the device? For example, if the file index.html is located inside my project's assets folder?

@MaskyS
Copy link
Author

MaskyS commented Apr 9, 2018

CC @lejard-h

@ghost
Copy link

ghost commented Apr 9, 2018

I have exactly the same requirement.

i need to load a react app that is stored locally. Its actually some very complex JS that i cant rewrite in Dart. It does CRDT stuff.

Once loaded i need to call certain public exported JavaScript functions. Wondering if i can use EvalJavascript Dart call.
I also need to receive calls from inside the Webview to Dart - not sure how to do that, other than polling which is pretty bad and will kill battery.

@eugenio-tesio
Copy link

I need to open a PDF file. I was thinking of doing it with a WebView. Would this be possible?

@MaskyS
Copy link
Author

MaskyS commented Apr 10, 2018

@eugenio-tesio I tried that out, it wouldn't work unless if you feed a gdoc url to the method as such:
("http://docs.google.com/gview?embedded=true&url=" + pdfURL). But isn't very suitable for mobile, the gdocs site has additional icons which ruin the UI. Besides that my app also needs to work offline. So my workaround has been to convert the PDFs to HTML first.

@MaskyS
Copy link
Author

MaskyS commented Apr 10, 2018

I found this today, we may be able to do this, but will require changes to the plugin. See https://flutter.io/assets-and-images/#sharing-assets-with-the-underlying-platform. Another way that can work is to pass a url like "file:///data/data/com.provider.package/file_name.html" but you will need the exact file path of the HTML. I didn't manage to do this though because my assets are inside the assets folder of my project, and those are not placed in any kind of permanent directory.

@lejard-h
Copy link
Collaborator

duplicate of #23

I am closing this one since we already discussed about solution in the previous one

@MaskyS
Copy link
Author

MaskyS commented Apr 10, 2018

@lejard-h that solution isn't working well for me it seems. I'm getting this: (17795): Unrecognized GLES max version string in extensions:
E/flutter (17795): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (17795): Invalid argument(s): String contains invalid characters.
E/flutter (17795): #0 _UnicodeSubsetEncoder.convert (dart:convert/ascii.dart:97:9)
E/flutter (17795): #1 AsciiCodec.encode (dart:convert/ascii.dart:47:46)
E/flutter (17795): #2 new UriData.fromString (dart:core/uri.dart:3197:44)
E/flutter (17795): #3 new Uri.dataFromString (dart:core/uri.dart:304:24)
E/flutter (17795): #4 _MyHomePageState.getUri. (file:///home/maskys/webview_test/lib/main.dart:57:21)

the widget webview remains white

@MaskyS
Copy link
Author

MaskyS commented Apr 10, 2018

I think that is triggering because my html file contains quote characters?

@MaskyS
Copy link
Author

MaskyS commented Apr 10, 2018

isn't the quote characters, must be something else.. Possible all the special characters in the file or the square brackets.

@MaskyS
Copy link
Author

MaskyS commented Apr 10, 2018

@lejard-h Please reopen, the solution in #23 doesn't seem to be able to work for this use case. I will need to load various files which all contain image assets, special characters like © and other symbols. The easiest way imho is if we can figure out how to use the "file:///" syntax to load files from the project's asset folder.

@kevin-sakemaer
Copy link
Collaborator

if you launch a web server you should not have problem
here is an example https://github.com/Jaguar-dart/jaguar_flutter_asset

@lejard-h
Copy link
Collaborator

@MaskyS

even if the solution don't work for you, it is the same issue, please continue the conversation on the other one and try the solution of @kleak describe in the article mention in the other issue

@fluttercommunity fluttercommunity locked as too heated and limited conversation to collaborators Apr 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants