dart-io

Console application - StringDecoder stdin

﹥>﹥吖頭↗ 提交于 2019-12-25 00:18:07
问题 The following or similar was shown for terminal input, however terminating input with ctl-d is not good. Is there another way to exit from this "loop"? import "dart:io"; void main() { stdout.write("Enter Data : "); new StringDecoder().bind(stdin).listen((String sInput){}); //// Do something with sInput ............ } 回答1: You can terminate a dart program by running the exit method when using dart:io void exit(int status) Exit the Dart VM process immediately with the given status code. This

HTTPRequest.request with sendData, can't seem to get this to work

折月煮酒 提交于 2019-12-24 12:15:30
问题 I'm trying to wrap my head around Dart, and in doing so got stumped with adding some data to an HTTPRequest. I need to send a parameter with this request, so I figured the "sendData" variable would probably help me do that. Documentation is sparse at best for this method, so for all I know it's just my syntax that's wrong. Any idea why this wouldn't work? HttpRequest.request(url, sendData:{"rnd":rnd.millisecondsSinceEpoch}).then(onLoadSuccess).catchError(onLoadError); Currently it tanks out

How to stream a file line-by-line in Dart

假装没事ソ 提交于 2019-12-23 20:03:47
问题 This question is a continuation of a previous question. I wrote the following piece of code to determine if File.openRead() created a Stream that could be streamed line-by-line. It turns out that the answer is no. The entire file is read and then passed to the next transform. My question is then: How do you Stream a file line-by-line in Dart? import 'dart:async'; import 'dart:convert'; import 'dart:io'; void main(List<String> arguments) { Stream<List<int>> stream = new File('Data.txt')

Why can't Dart's “Process.start” execute an Ubuntu command when the command works in Ubuntu terminal?

安稳与你 提交于 2019-12-22 08:29:12
问题 I have command I would like to call with Dart. The command is sonar-runner which works perfectly if I run it in a normal Ubuntu terminal. This is because I have edited the PATH in the .profile file so it becomes a global command. However, if I wrote a simple Process.start code that should trigger the same thing: Process.run('sonar-runner', []).then((result) { stdout.write(result.stdout); stderr.write(result.stderr); }); I get as a response: Uncaught Error: ProcessException: No such file or

How do I list the contents of a directory with Dart?

孤街醉人 提交于 2019-12-21 07:03:10
问题 I would like to list all the contents of a directory (on the file system) using Dart. How can I do this? 回答1: The API has changed and I have updated the async code for M4 release (0.5.16_r23799 ): Future<List<FileSystemEntity>> dirContents(Directory dir) { var files = <FileSystemEntity>[]; var completer = new Completer(); var lister = dir.list(recursive: false); lister.listen ( (file) => files.add(file), // should also register onError onDone: () => completer.complete(files) ); return

How to create/add middleware that adds default headers to each request

笑着哭i 提交于 2019-12-19 09:04:53
问题 How can I add middleware to the shelf pipeline that adds default HTTP headers to each request? 回答1: Update There is now a pub package to simplify adding CORS headers see https://pub.dartlang.org/packages/shelf_cors Original See also https://groups.google.com/a/dartlang.org/forum/#!topic/cloud/2Vn_IqzGtTc final Map<String, String> _headers = {'Access-Control-Allow-Origin': '*', 'Content-Type': 'text/html'}; // for OPTIONS (preflight) requests just add headers and an empty response shelf

How do I find the current directory, in Dart?

十年热恋 提交于 2019-12-19 05:33:40
问题 I want to know what the current directory is. I don't want to shell out to run pwd . Is there an easy way to do this in Dart? 回答1: Indeed there is! import 'dart:io'; main() { Directory current = Directory.current; } Note: this only works on the command-line, not in the browser. Read more about the API docs for Directory.current. 来源: https://stackoverflow.com/questions/19436793/how-do-i-find-the-current-directory-in-dart

Flutter. File existsSync() always returns false

旧时模样 提交于 2019-12-11 07:05:08
问题 this is the problem that I'm facing right now. I have a folder named 'assets' and inside that folder I have an image named 'no_icon.png'. I have added this to the pubspec.yaml like this: flutter: assets: - assets/teamShields/ - assets/no_icon.png And when I do inside a StatelessWidget final imageP = File('assets/no_icon.png'); and then inside this and a MaterialApp: body: Text(imageP.existsSync().toString()), I always see false on my screen. Also, if I type Image.asset('assets/no_icon.png'),

How do you set a Dart IO Process to use an existing Stream for its stdin?

岁酱吖の 提交于 2019-12-11 04:52:14
问题 I'm creating a Process using Process.start and am a bit stuck with the stdin getter. Ideally, I've got a StreamController set up elsewhere, whose stream of Strings I'd like to pass into stdin. But there aren't too many sophisticated examples for interacting with Process.stdin, so I'm not sure how to do anything more than a writeln to stdin. So I've got something like this, that I can add String messages to: StreamController<String> processInput = new StreamController<String>.broadcast(); And

Simple command-line app I/O in Dart

本小妞迷上赌 提交于 2019-12-11 02:42:41
问题 Is there a way of taking single character (integer) keyboard inputs from the user and storing them to a variable in a Dart command-line app? I've tried something like: Stream cmdLine = stdin .transform(new StringDecoder()) .transform(new LineTransformer()); StreamSubscription cmdSubscription = cmdLine.listen( (line) => (choice = line); cmdSubscription.cancel();); In an attempt to store a keyboard input into the variable 'choice' and many slight variations of this code but can't get it to work