How to make window.prompt in Dart?


I make some apps using Dart and I have one simple question. I haven’t found the prompt dialog in dart:html library. I’ve found only alert and confirm dialog calls, but that’s not, what I need. I’ve tried some other possibilities from Dart api, but no way to do it. I think there should be something like a modal dialog or Dart own prompt dialog. I know, modal is here, but it only loads another file in the popup.

Can somebody help me?

Update: Actually, I found one solution. It’s an emulation of JavaScript in dart:js library:

var password=context.callMethod('prompt',['Password','']);

It is good solution, but I think, that there must be something better than emulating JavaScript.

Update 2: Because of an insufficiency of the prompt dialog in the Dart spec, Dart APIs and Dart libraries here is a bug on Google Code issue tracker, so let’s star the bug, if you think prompt is important in the spec or comment if you have any other idea, how to do it in a modern way (you can try to propose something like built-in modal dialog for example). Or just share it if you think prompt/modal dialog implementation should be also in modern programming languages…

Update 3: Now we are discussing the new modal alert, confirm and prompt dialogs, which could be in Polymer.dart library. Here is the enhancement on Google Code issue tracker, so let’s star the bug, if you are for the modern modal form of that dialogs, or discuss, if you know how to do it better…


You can use js interop to do this:

import 'dart:js';

main() {
  var result = context.callMethod('prompt', ['Hello from Dart!']);

I’m not sure why this is not available in dart:html. Perhaps file a bug.

Ideally you’d be able to use another UI component library to do this, rather than using window.prompt(). Something like these. But it’s still pretty early days, and I’m not sure if there is a good library available yet.


window.prompt() has be purposefully removed from dart:html to discourage its use as it blocks the execution of script.

Answered By – Greg Lowe

Answer Checked By – Clifford M. (FlutterFixes Volunteer)

Leave a Reply

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