【问题标题】:How would be translated this simple input python code into dart?如何将这个简单的输入 python 代码翻译成飞镖?
【发布时间】:2019-01-07 16:12:32
【问题描述】:

我正在使用 dartpad 尝试学习一些 dart 代码,我在 stackoverflow 中找到了一些答案,但是当我在 dartpad 中尝试时它不起作用,下面我将提供一些简单的 python 代码,如果有人能提供帮助将非常有帮助稍微了解一下它在 dart 中的工作原理,或参考任何文章的链接。

在python中输入:

input_string = input("Enter something here: ")
print("You entered {}".format(input_string))

这是我在 dartpad 中尝试过的 dart 代码:

import 'dart:io';
import 'dart:async';

void main() {
    print("Please, enter a line \n");
    Stream cmdLine = stdin
    .transform(new StringDecoder())
    .transform(new LineTransformer());

  StreamSubscription cmdSubscription = cmdLine.listen(
    (line) => print('Entered line: $line '),
    onDone: () => print(' finished'),
    onError: (e) => /* Error on input. */);


}

【问题讨论】:

  • 您可以使用stdin.readLineSync(encoding: utf8); 读取一行文本。

标签: python dart


【解决方案1】:

类似

print('Enter something here');
final line = stdin.readLineSync(encoding: utf8);
print('You entered: $line');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-03
    • 2022-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 2020-04-18
    • 2017-11-04
    • 1970-01-01
    相关资源
    最近更新 更多