w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
#Dart: Divs are removed when jquery fires an event to an Dart callback method
In dartium the following code should work : js.context.$('#mySlider').on('change', new js.Callback.many((_) { print('Element changed'); })); With dart2js (which also use $) you have two options : compile with --global-js-name option to change $ to something else. call $.noConflit() before the dart script is loaded to release $ used by jQuery and change js.context.$ with js.context.jQuery in the above code snippet. Some comments on your code : it's not necessary anymore to use js.scoped the callback is called with one parameter so you have to define it even if you don't use it (that why I use a _ to handle this parameter that I don't care)

Categories : Javascript

How to debug client side dart code in Dart editor without CORS
My understanding is that you can debug, but the real problem is that you don't get the expected data back from the server due to missing cookies. Standard CORS requests do not send or set any cookies by default. In order to include cookies as a part of the request, besides setting up the server, you need to specify withCredentials property, e.g.: HttpRequest.getString(url, withCredentials:true)... You will also need to setup server to provide Access-Control-Allow-Credentials header. EDIT: it seems that additional issue is that you don't want to have 2 servers, each serving different part of app. In that case, you can configure DartEditor to launch the URL, instead of files. Go to Run > Manage Launches and add create a new Dartium or Dart2JS launch with specified URL and source di

Categories : Dart

How to create an instance of Dart Polymer custom element in Dart code?
Here is the example code: import 'dart:html'; import 'package:polymer/polymer.dart'; main() { querySelector('#add-here').children.add(new Element.tag('my-element')); } Notice the use of new Element.tag('my-element').

Categories : Dart

How do you create an observable derivative property in Dart / Polymer Dart?
you may want to check observable_getter example from dart-polymer-dart-examples github repo. class App extends Object with ObservableMixin { @observable DateTime timestamp; App() { bindProperty(this, const Symbol('timestamp'), () => notifyProperty(this, const Symbol('second'))); } int get second => timestamp.second; } main() { App app = new App(); new Timer.periodic(const Duration(seconds: 1), (_) { app.timestamp = new DateTime.now(); }); query('#tmpl').model = app; } Also check discussion at: https://code.google.com/p/dart/issues/detail?id=12473

Categories : Dart

Writing a WebWorker in Dart (without dart:isolate)
The Worker class seems to support what you want. You can use postMessage to send messages to it You can subscribe to onMessage to receive messages You can use terminate to terminate it

Categories : Javascript

Is there any example for dart's `spawnUri(...)` in library "dart:isolate"?
WARNING : This code is out of date. Replace your second.dart with the following to make it work : import "dart:isolate"; String hello(String who, String message) { return "Hello, $who, $message"; } main() { port.receive((msg, reply) => reply.send(hello(msg[0], msg[1]))); }

Categories : Dart

how to get started on Google Dart if I am totally new to programming?
First of all you should know that all the information that interests you exists on the main site: Dart: Structured web apps. This site include the following information: Get started: Get Dart Get Tutorials Technical Overview Docs: Programmer’s Guide Dart API Reference Language Specification Dart Cookbook Dart: Up and Running Books on Dart Articles Frequently Asked Questions (FAQ) Tools: Dart Editor Pub Package Manager More tools for Dart Resources: Dart Code Samples Dart Synonym: Translations from Dart Try Dart online Dart Presentations Dartisans: The Dart show and podcast Dart Tips: Short Video Tutorials Dart Bug and Feature request Community: Contact the Dart Project Contributor's Guide Community Resources Within these resources, you can find a lot of useful infor

Categories : Dart

Dart polymer.dart dart2js
If it is complaining about a main entry point, I suspect it cannot find a main() function defined anywhere. In your index.html (or whatever the main html file is called), you presumably have a link to a Dart file. Does that file have a main() function defined?

Categories : Dart

Running an interactive Dart program from another Dart program
I have looked at Process.run and Process.start, but apparently they don't function that way. Process.start is what you want here. It can do what you want, but you'll have to become a bit more comfortable with async programming if you aren't already. You'll spawn the process and then asynchronously read and write to the spawned processes stdout and stdin streams. Your interactive program can do something like this: // interactive.dart import 'dart:io'; main() { var input = stdin.readLineSync(); print(input.toUpperCase()); } It's using stdin to read input from the command line. Then it outputs the processed result using regular print(). The non-interactive script can spawn and drive that using something like: import 'dart:convert'; import 'dart:io'; main() { Process.sta

Categories : Dart

Dart CheckboxInputElement doesn't show text
You have to add a Label with the descriptor text and link it to the Checkbox: FormElement form = new FormElement(); CheckboxInputElement option = new CheckboxInputElement(); option.name = "text1"; option.value = "text1"; option.id = "text1"; form.children.add(option); LabelElement label = new LabelElement(); label.htmlFor = 'text1'; label.text = "This is a checkbox label"; form.children.add(label); window.children.add(form); The for property will look for the input with the id specified and connect them (so that clicking on the label text will toggle the checkbox) . You will end up with the following HTML: <form> <input type="checkbox" name="text1" value="text1" id="text1"> <label for="text1">This is a checkbox label</label> </form>

Categories : Dart

Setting python path for sublimerepl from sublime text?
Is it possible you're changing the wrong line of code in /Packages/SublimeREPL/config/Python/Main.sublime-menu? If you wish to run REPL on the current file, {"command": "repl_open", "caption": "Python - RUN current file", "id": "repl_python_run", "mnemonic": "d", "args": { "type": "subprocess", "encoding": "utf8", "cmd": ["C:\Users\Andy\Documents\_Main\M-Stick Backups\08.07.13\Computing\Python Portable\Portable Python 2.7.3.1\App\python.exe", "-u", "$file_basename"], "cwd": "$file_path", "syntax": "Packages/Python/Python.tmLanguage", "external_id": "python", "extend_env": {"PYTHONIOENCODING": "utf-8"} } is what the modified section should look like. (It appears you might be modifying the command which opens the interpreter in interactive mode as oppos

Categories : Python

How to extend Windows PATH env variable in Sublime Text?
You forgot to add the key name "PATH": "default_extend_env": { "PATH" : "{PATH};H:\scala-2.10.2\bin" } Your full user config file should look like this: { "default_extend_env": { "PATH" : "{PATH};H:\scala-2.10.2\bin" } }

Categories : Python

Where is `dart:uri` now?
According to this post to the Dart announcement list, dart:uri has been replaced with the core Uri class. Your code translates to: main() { decodeUrl("str"); } Though it might be more instructive to write print(Uri.decodeFull("str%20here"));.

Categories : Misc

Start Sublime 3 from terminal, when default is Sublime Text 2
When you run sublime, your computer should run a bash file at /usr/bin/sublime (running which sublime as Mike Li suggested will confirm the location. Open that up and edit it for Sublime Text 3. The contents of that file should be: #!/bin/bash /usr/lib/sublime-text-2/sublime_text --class=sublime-text-2 "$@" Edit it as so: (On my computer the executable is called subime_text_3 instead of subime_text. Verifiy by opening /usr/lib/sublime-text-3.) #!/bin/bash /usr/lib/sublime-text-3/sublime_text_3 --class=sublime-text-3 "$@" Point it to the location of Sublime Text 3 on your system. Edit Build 2221 (using the ppa) changed the installation directory from /usr/lib/sublime-text-2 to /opt/sublime_text_2

Categories : Linux

How to profile a dart app?
It has already been pointed out in the comments that there are ways to get a CPU profile from the VM on Linux (https://code.google.com/p/dart/wiki/Profiling). As far as I understand what you are really looking for is to get a heap or memory profile. While it is possible to print an object histogram when the program terminates (see below), we do not have any convenient way to get the object histogram while your server is running. We do hope to be able to add this capability over the next months. To print the object histogram when the Dart script exits, you should pass the flag --print_object_histogram to the Dart VM. This will print the averages of the live objects at the end of each major GC over the life of the program. This can be fine to get a quick overview, but is not ideal to trac

Categories : Dart

What is an Interceptor in dart?
When you open the declaration of any such type in DartEditor, it turns out that it is actually derived from NativeFieldWrapperClass1 class. NativeFieldWrapperClass1 class is used as the base class for types which have a native implementation in environments which embed Dart VM, e.g. classes which wrap DOM elements - canvas DOM element is implemented in browser and wrapped into CanvasElement Dart class. Instances of such types have their peers in native implementation (CanvasElement instance has native peer C/C++ object in the browser). Deriving from NativeFieldWrapperClass1 ensures they have a slot where embedders can store a pointer to the peer object - native data. This is done with embedder API (Dart_SetNativeInstanceField function).

Categories : Dart

What is boot.js (dart)
In a nutshell, the boot.js script makes it possible to load and run a polymer.dart app without needing to compile your app using build.dart. You can still run build.dart as a lint tool, but there is no required compile step anymore. Internally, boot.js looks for the imported files with <polymer-element>s, collects them, and initializes each <polymer-element> for you. Read the description at the top of file if you want to know more about the internals. You can find it under packages/polymer of any polymer app.

Categories : Dart

Pass a URL into a Dart app
You can use the route package to handle the URL's for you. For example: import 'package:route/client.dart'; final fruitUrl = new UrlPattern(r'/fruit/(w+)'); main() { var router = new Router() ..addHandler(fruitUrl, showFruit) ..listen(); } void showFruit(String path) { var fruit = fruitUrl.parse(req.path)[0]; // Display the page according to the fruit type } If you don't need to handle actual routes, and you just want to handle any query parameters passed of the form ?fruit=apple you don't have to use the routes package and can instead manually parse the URL: Map params = {}; // If arguments were provided, decode them into params map if(window.location.search.length > 1) { // Break all arguments into form: fruit=apple List<String> queryPairs = window.loc

Categories : Dart

Web app to a packaged app with Dart
There are a few caveats when writing a packaged app in Dart. One is related to symlinks (packaged apps don't like them, and pub uses them), and the other is related to dart2js (you need to compile with the --disallow-unsafe-eval flag). If you're using the Editor, you can create a new chrome packaged app from the wizard. This will set up a project that handles both issues above. I'd do that and make sure it runs, and then copy your web app into that project.

Categories : Dart

Dart: unhandledExceptionCallback is ignored
I don't know if you did wrong, it could be a bug. But it seems exceptions thrown in the isolate's main function aren't caught by the handler. If you change it like this: import 'dart:isolate'; void isolateMain() { port.receive((whatever, mahPort) { throw new Exception("$whatever"); }); } bool handleException(IsolateUnhandledException e) { print("EXCEPTION in isolate: ${e.toString()}"); return true; } void main() { SendPort sendPort = spawnFunction(isolateMain, handleException); sendPort.call("Hello").then((e) { print("Main received $e"); }); } ... then handleException() will be called.

Categories : Dart

How can I get the name of a file in Dart?
You can use the path package : import 'dart:io'; import 'package:path/path.dart'; main() { File file = new File("/dev/dart/work/hello/app.dart"); String filename = basename(file.path); }

Categories : File

How to add HTML entities in Dart?
DocumentFragment will do the job. This: my_element.nodes.add(new DocumentFragment.html('&amp;&copy;')); will output &© in your HTML document.

Categories : Dart

How to inject a Dart file in tab?
Not a way to directly inject dart-files, but a workaround to inject your dart-application would be to use dart2js and than inject the compiled js-file myDartScript.dart.precompiled.js of your dart-script. (Use the precompiled-version to avoid errors against the Content Security Policy) Maybe you also have to inject packages/browser/dart.js and packages/browser/interop.js. Untested

Categories : Dart

Why can't I run a dart file inside a dir?
EDIT pub install was renamed to pub get (pub install is still available as an undocumented alias for pub get) EDIT pub install solves this issue by creating additional packages directories that link to the main packages directory at the root of your package. It assumes your package is laid out according to the package layout guide, and creates a linked packages directory in bin/, test/, and example/, as well as their subdirectories Dart Editor If you are using the Dart Editor it can automaticly create a directory link to the main package folder. You need to choose "Pub Install" from the context menu on the pubspec.yaml file in the Files view. Command Line If you want to create the directory from the command line you can use the pub install command. You need to run it in t

Categories : Dart

How do I get a ClassMirror on a Dart class?
You can get a ClassMirror from an instance of the class, or from the library where the class was defined, or directly using the class name. Obtaining a class mirror from an instance or an InstanceMirror To obtain information about a class, you need a ClassMirror. To obtain a ClassMirror, you first need an instance of the class, or the name of the library where the class is defined. If you have an instance, you can use the top level reflectClass() function defined in the dart:mirrors library. This function returns a ClassMirror object: var classMirror = reflectClass(myObj.runtimeType); MirrorSystem.getName(classMirror.simpleName); // 'MyClass' If you have an InstanceMirror, use the InstanceMirror's type property to get the ClassMirror: var myObj = new MyClass(); var instanceMirror =

Categories : Dart

Dart request succeeding ... somehow?
This is because the request actually completes successfully. Your request to "login" will actually call http://127.0.0.1:6521/[Path_to_your_Dart_file]/login The server started by Dart when running in Dartium (127.0.0.1:6521) seems to answer to every POST request with HTTP 200 and an empty response body. If you change the method from POST to GET, it will fail as expected. As for why the server does this - I don't really know. This would have to be answered by the Dart team.

Categories : Dart

Dart - How to sort Map's keys
Use a TreeMap. That should solve your issue. Map<String, String> unsortMap = new HashMap<String, String>(); unsortMap.put("2", "B"); unsortMap.put("1", "A"); unsortMap.put("4", "D"); unsortMap.put("3", "B"); Map<String, String> treeMap = new TreeMap<String, String>(unsortMap); Hope this helps.

Categories : Dart

One-line function in Dart using “=>”
It's a matter of taste, so my suggestion is to do whatever feels reasonable to you. I don't see any problem with writing void functions in shorthand form and I do it often, but it can bite you if you don't know what you are doing. Your example 3 doesn't behave as you think it does. It is not equivalent to example 2, because in example 3, deductDbl returns an int. There is a difference between: deductDbl1(double dValue) { _iValue -= (dValue * 1).toInt(); } // returns null and deductDbl2(double dValue) => _iValue -= (dValue * 1).toInt(); // returns int The reason for this is that result of the expression _iValue -= something is _iValue, so the return type is int. This gives: var r1 = deductDbl1(x); // r1 is null! var r2 = deductDbl2(x); // r2 is an int equal to _iValue!

Categories : Dart

Create a package in dart
There's no such possibilty in the Dart Editor for now. To create a package follow these steps : create an New Application mylib without sample content add a pubspec.yaml file add a lib folder create a mylib.dart containing the code you want to package See the Package layout conventions for more informations.

Categories : Dart

is there any way to cancel a dart Future?
As far as I know, there isn't a way to cancel a Future. But there is a way to cancel a Stream subscription, and maybe that can help you. Calling onSubmit on a button returns a StreamSubscription object. You can explicitly store that object and then call cancel() on it to cancel the stream subscription: StreamSubscription subscription = someDOMElement.onSubmit.listen((data) { // you code here if (someCondition == true) { subscription.cancel(); } }); Later, as a response to some user action, perhaps, you can cancel the subscription:

Categories : Dart

Embedding Dart into application
I couldn't find any good article on this, only this discussion thread in Dart group. However, there are working demos in the Dart's source code. Take a look at DartHost implementation in some of these projects - this should give you some idea about how to do it.

Categories : C

What is the use of observable function in Dart?
In theory, the @observable before the show() function determines whether the <template> gets activated or not. If show() starts to return true, maybe because sillyword, adjective, etc. all became non-empty strings, the <template> would get activated. That's the general principle, anyway, But, in this specific example, all the strings used within are also marked @observable: @observable String sillyword=''; @observable String adjective=''; @observable String animal=''; @observable String bodypart=''; @observable String verb=''; @observable String adverb=''; This makes the @observable declaration right before show() unnecessary. If you remove that particular @observable, the code still works.

Categories : Dart

Dynamically add a WebComponent in Dart?
I tested the same with build 0.5.13_r23552 editor & SDK and run into the same problem when running in Dartium. If I do the dart2js (Run as Javascript/Generate javascript) however, it works. However, be aware of the following (based on my experience): Try to change to the SDK version that it has been tested and verified with. It seems the tests are updated to run with 0.5.15; while the SDK delivered with the editor on the dartlang site is only 0.5.13. Maybe clone the bleeding edge version to make it work? Dart is constantly evolved. Always do pub update on your project after updating to the newest editor, if you are using dependencies and not a specific library version. Add the build.dart to your project to make sure that code is generated on changes (See bottom of this page: Build.

Categories : Dart

How do I get all fields for a class in Dart?
No, you should go through ClassMirror.variables: class Test { int a = 5; static int s = 5; final int _b = 6; int get b => _b; int get c => 0; } void main() { Test t = new Test(); InstanceMirror instance_mirror = reflect(t); var class_mirror = instance_mirror.type; for(var v in class_mirror.variables.values) { var name = MirrorSystem.getName(v.simpleName); print("$name => S: ${v.isStatic}, P: ${v.isPrivate}, F: ${v.isFinal}"); } } This will output: _b => S: false, P: true, F: true a => S: false, P: false, F: false s => S: true, P: false, F: false ClassMirror.getters would only return b and c.

Categories : Dart

How to get Dart's Web UI to put an image in the out folder
I had the same problem, and have almost solved it by updating my build.dart to include a copy of the img folder into the out folder. import 'dart:io'; import 'dart:async'; import 'package:web_ui/component_build.dart'; // Ref: http://www.dartlang.org/articles/dart-web-components/tools.html // Actually ... https://github.com/sethladd/dart-web-components-tests/blob/master/build.dart main() { var args = new List.from(new Options().arguments); // args.addAll(['--', '--no-rewrite-urls']); Future dwc = build(args, ['web/index.html']); dwc .then((_) => Process.run('cp', ['-fR', 'web/img', 'web/out'])); } In the above I've added a command to run "cp" (I'm on a Mac) of web/img to web/out. I say almost solved it because those image in the img folder also end up being copied direc

Categories : Dart

Dart drag & drop div
As far as I know, you'd need to have a handle to the event that you added, and use that to remove it later, for example: var myEvent = (MouseEvent event) => runMoveEvent(event); // store the function in a variable. void init() { document.on.mouseMove.add(myEvent); // refer to the function by name } void stopMoveEvent(MouseEvent event) { document.on.mouseMove.remove(myEvent); // remove the same function. } void runMoveEvent(event) { ... } What you're doing in your code is adding one anonymous function, and removing a different anonymous function. I think that http://dartbug.com/144 (tagged WontFix) probably provides more details about why this doesn't work.

Categories : Dart

What parser generator does Dart use?
From the README, it looks like it's not generated by a parser generator, but rather machine-translated from an existing (presumably human-coded) Java implementation: This code is part of an experimental port of the Editor's analysis engine from Java to Dart. While we will continue to support the Java version of the analysis engine and the services built on it, we also intend to provide the same services to Dart-based applications. This is very early code and we expect it to change, possibly in significant ways. While we are eager to see other people make use of the analysis engine, we also want to be clear, in case you are interested in doing so, that the current API's should in no way be considered to be stable. In particular, this code was automatically translated fr

Categories : Dart

Using dart to download a file
The python example linked to in the question involves requesting the contents of example.com and writing the response to a file. Here is how you can do something similar in Dart: import 'dart:io'; main() { var url = Uri.parse('http://example.com'); var httpClient = new HttpClient(); httpClient.getUrl(url) .then((HttpClientRequest request) { return request.close(); }) .then((HttpClientResponse response) { response.transform(new StringDecoder()).toList().then((data) { var body = data.join(''); print(body); var file = new File('foo.txt'); file.writeAsString(body).then((_) { httpClient.close(); }); }); }); }

Categories : Dart

How do I overloading operators to allow 2 * A in dart?
This is impossible to add class members at runtime. Also impossible add an operator overload at runtime. If you want overload some operator you must do this when you declare class. The value "2" has the type that implements 'int' interface. But because you not declared this type ("int") and cannot modify it declaration then you cannot change it behavior in any way. But this not means that you cannot design behavior of your own classes. If you want specify some behavior when some operation will be performed on the values ​​of your types then you can overload some operators in the class declaration. These operators include the following: < + | [] > / ^ []= <= ~/ & ~ >= * << == – % >> Example of declarations; void main() { var zero = new Nothing();

Categories : Dart

@override of Dart code
From @override doc : An annotation used to mark an instance member (method, field, getter or setter) as overriding an inherited class member. Tools can use this annotation to provide a warning if there is no overridden member. So, it depends on the tool you use. In the current Dart Editor(r24275), there's no warning for the following code but it should (it looks like a bug). import 'package:meta/meta.dart'; class A { m1() {} } class B extends A { @override m1() {} // no warning because A has a m1() @override m2() {} // tools should display a warning because A has no m2() }

Categories : Dart



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.