How to use a dartscript on your website


Hello i just started to learn some dart and im new in this forum aswell,

i’ve created the ubersimple webapp, with webstorm and written a really simple dart script and a html document.

the head of my html doc:

<!DOCTYPE html>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="scaffolded-by" content="">
    <title>Das bist du!</title>
   <script defer src="" type="application/dart"></script>
   <script defer src="">    </script>


the dart code:

import 'dart:html';
import 'dart:math';

ButtonElement rndButton;
ImageElement rndImage;  
var images;
var rng;

void main() {
  rndButton = querySelector('#rndButton');
  rndImage = querySelector('#imgScreen');

  images = ['', '', '', '', '', '', '', ''];
 void pickYou (Event e) {
  rng = new Random();

void setYou (var rnd) {
  rndImage.src =  (images[rnd].toString());

I know the code is not pretty and all, i was just testing things out. 🙂

Now i want to use both on a website, i uploaded the html page the code and the dart.js to the website and put the src in the html script tag.

When testing in Webstorm with Chromium it works.
But the script dont run on the website. How can i use dart online on a website?

Thanks in advance


Dart doesn’t run in any browser directly except Dartium (the Chomium based Dart development browser that includes the Dart VM).

When you run pub build in your project directory (where the pubspec.yaml is) then you get an output in the build sub-directory that can be uploaded to web servers for public use.

There is also a transformer available that optimizes the script tags when pub build is run.

Answered By – Günter Zöchbauer

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *