如何在线获取用户在dartpad上的输入? [英] How to get user input on dartpad online?

查看:106
本文介绍了如何在线获取用户在dartpad上的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在dartpad上的控制台中获得用户输入?

How can I get user input in console on dartpad?

每当我编写

import 'dart:io';
void main() {
  stdout.write("What's your name? ");
  var name = stdin.readLineSync();
  print("Hi, $name!");
}

但是在这样的控制台窗口中却出现了异常

But I got an exception in console window like this

Uncaught exception:
Unsupported operation: StdIOUtils._getStdioOutputStream


推荐答案

如DartPad手册中所述: https://dart.dev/tools/dartpad

As described on the manual for DartPad: https://dart.dev/tools/dartpad


DartPad支持dart:*与Web应用程序兼容的库;它不支持dart:io或软件包中的库。如果要使用dart:io,请改用Dart SDK。如果要使用软件包,请获取该软件包支持的平台的SDK。

DartPad supports dart:* libraries that work with web apps; it doesn’t support dart:io or libraries from packages. If you want to use dart:io, use the Dart SDK instead. If you want to use a package, get the SDK for a platform that the package supports.

因此您不能使用stdin / stdout,因为它来自dart:io库。

So you cannot use stdin/stdout since it comes from the dart:io library.

要解决您的问题,可以在DartPad页面底部启用显示Web内容。在这里,您可以将HTML代码添加到项目中,并使用例如一个按钮。在Dart代码中添加一些逻辑,以监听按钮并读取文本字段的值。

For a solution to your problem, you can enable "Show web content" at the bottom of the DartPad page. Here you can add HTML code to your project and make a text field with e.g. a button. Add some logic in your Dart code which listen on the button and read the value of the text field.

这篇关于如何在线获取用户在dartpad上的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆