The built-in library 'dart:io' is not available on Dartium - dart

I don't know where is the problem. This error show up when I import my SystemCheck class to main Dart file.
SystemCheck class:
import 'dart:io';
class SystemCheck{
getOperatingSystem() => Platform.operatingSystem;
getUser() => Platform.localHostname;
}
Import in main file:
import 'cz.felguide.core/system.dart';

That's correct. You cannot use dart:io in Dartium or code designed for running in the browser. For this simple example much of what you want can be found in the Navigator class such as Navigator.platform
Dart has the same limitations as Javascript in that code that is running in a browser cannot natively access the File System of the running client. There are some exceptions such as the specialized Chrome Packaged Apps which allow certain permissions just within Chrome. Even then they require the app to specifically request the extra permissions and the user to grant them.

Related

Firefox Restclient plugin import fails

I am trying to use Firefox Restclient plugin to post some REST calls. This already works.
But now I need to execute my requests from another machine.
I wanted to export my requests and import them there but the import keeps failing.
What I already tried:
-firefox57 with latest plugin version - import does not work, no response
-using firefox56 with plugin2.05 - message that import succeeded, but I can not open manage Favourites section and I see the requests nowhere
does anybody know how to solve this?
A certain time after successful import, still you will be not able to see the favourite due to access restrictions, mostly in Linux machine. You can see a pop for access while saving another rest for access, allow it it will fetch all.

Using dart discoveryapis_generator on webapp?

Can't use my model file generated with the discoveryapis_generator.
It ask for a http.client to be used, but it's from dart:io, and i m trying to use it in a web app
static YoupipeApi api = new YoupipeApi(new http.Client()); //cant work on webapp
Failed to invoke tokenLoaded callback: Unsupported operation: IOClient isn't supported on this platform.
So, discoveryapis_generator is only available for native dart client?
Am i doing something wrong?
(related question here)
The http package also contains a client that runs in the browser. Just change the import to import the file package:http/browser_client.dart; instead.

How do I print from dart chrome app?

I want to print (on printer, not console) from a dart chrome app.
It is possible to print from chrome apps. Here is official sample.
This works properly for javascript apps, however I cannot do similar in dart.
Here's what I tried:
import 'dart:html';
import 'package:chrome/chrome_app.dart' as chrome;
void main() {
chrome.app.window.current().print();
}
Thanks in advance.
Update:
There seems to be no print() method in AppWindow object.
The question is how can I in dart access print() method? I mean the one that is available in javascript in window object. Not in regular dart runtime environment but when code is executed as chrome app written in dart.
Update2:
I posted the answer. The remaining mystery is how to get the DOM Window object from AppWindow object?
The answer seems to easier than I thought...
window.print()
does the job as described in documentation.

Usage of HTTPRequest APIs for Server side app

Below chunk of code seems to require dart:io.
HttpRequest.getString(uri).then(onDataLoaded);
The App that is being designed requires to make HttpRequests to fetch metadata and build up a HTML page. But when the below is executed, an error related to dart:io of not being availble in Dartium is output on console.
Error as below
The built-in library 'dart:io' is not available on Dartium.
Any suggestions would be helpful.
You haven't provided much code to see what you are actually doing.
In the browser you need to import import 'dart:html'; and use the HttpRequest class from there.

How to run DartVoid Vane application on localhost

In Vane Roadmap:
Better support for running Vane on localhost. Right now it's certainly
possible to run Vane on localhost, but it's a little bit tricky. On
DartVoid we autogenerate a dart based server using the http_server
package. And all you need to initialize a Vane class is a standard
HttpRequest object. So, this will come soon hopefully. You can find
your autogenerated server.dart file at the root of you app if you have
a DartVoid app (it's not generated if you use a different framework).
I've created Guestbook sample application and file server.dart was missing.
Is Guestbook sample DartVoid app?
Can I reach generated server.dart file via GitHub?
Is there another way to reach this file?
Please create tags for Vane and DartVoid...
File can be reached from application:
import 'dart:async';
import 'dart:io';
import 'package:vane/vane.dart';
String collectionName = "posts";
class GetAllPosts extends Vane {
Future main() {
log.info("Guestbook : GetAllPosts");
new File("server.dart").readAsString().then((String fileContent){
log.info(fileContent);
});
return end;
}
}
Content of file will appear in system console in http://manage.dartvoid.com
TL;DR
Vane doesn't need an auto-generated server.dart file anymore, which makes it super easy to use.
Long answer
As the co-founder of DartVoid and a co-author of Vane maybe I can give a small update on how we have improved Vane's routing.
We have since the OP's question moved away from auto-generating a server file and instead we use annotations to declare Routes. At startup we parse these routes to build the 'routing table'.
If you're interested in knowing the gritty details and see a couple of examples, I recommend that you head over to the project repository at:
https://github.com/DartVoid/Vane

Resources