Questions tagged [dart-io]

dart:io allows you to work with files, directories, sockets, processes, HTTP servers and clients, and more

dart:io library is used for Dart server applications, which run on a stand-alone Dart VM from the command line. This library does not work in browser based applications.

This library allows you to work with files, directories, sockets, processes, HTTP servers and clients, and more.

191 questions
60
votes
9 answers

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

I would like to list all the contents of a directory (on the file system) using Dart. How can I do this?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
54
votes
10 answers

How do I read console input / stdin in Dart?

How do I read console input from stdin in Dart? Is there a scanf in Dart?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
33
votes
3 answers

How do I create a file in a directory structure that does not exist yet in Dart?

I want to create a file, say foo/bar/baz/bleh.html, but none of the directories foo, foo/bar/, etc. exist. How do I create my file recursively creating all of the directories along the way?
Juniper Belmont
  • 3,296
  • 2
  • 18
  • 28
31
votes
2 answers

Http POST request with json content-type in dart:io

How to perform HTTP POST using the console dart application (using dart:io or may be package:http library. I do something like that: import 'package:http/http.dart' as http; import 'dart:io'; http.post( url, headers:…
Roman
  • 2,145
  • 4
  • 26
  • 33
26
votes
2 answers

How do I find the current directory, in Dart?

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?
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
22
votes
5 answers

flutter websockets autoreconnect - how to implement

I am struggling how to implement websockets autoreconnect in flutter. I use web_socket_channel, however, the plugin just wraps dart.io WebSocket, hence any solution based on WebSocket class will work for me as well. I already figured out, how to…
Angel Todorov
  • 1,443
  • 2
  • 19
  • 37
21
votes
3 answers

Dart: handle incoming HTTP requests in parallel

I am trying to write an HTTP server in Dart that can handle multiple requests in parallel. I have been unsuccessful at achieving the "parallel" part thus far. Here is what I tried at first: import 'dart:io'; main() { …
Michael Hixson
  • 1,250
  • 1
  • 10
  • 15
18
votes
1 answer

Is there a better way to find out of a file or directory exists?

This seems a bit cumbersome var fileExists = new File(path).existsSync() || new Directory(path).existsSync() || new Link(path).existsSync() Is there a shorter or better way?
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
18
votes
4 answers

How do I get the directory of the current script, in Dart?

I want to know what the script's directory is. I have a command-line Dart script.
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
17
votes
2 answers

Reading file line by line in dart

I'm trying to process large text files in a language Dart. The files have a size over 100 MB. I tried readAsLines and readAsLinesSync methods of dart:io library. Every time I run out of memory: Exhausted heap space. Is there a way to read a file…
Martin Janda
  • 171
  • 1
  • 1
  • 4
16
votes
3 answers

Flutter Http error SocketException: OS Error: Connection refused

I'm using the last flutter version on a fresh created project. I'm trying to call this URL https://jsonplaceholder.typicode.com/users But on iOS or Android I get flutter: Error SocketException: OS Error: Connection refused, errno = 61, address =…
jaumard
  • 8,202
  • 3
  • 40
  • 63
15
votes
1 answer

Access to user environment variable

In my .bashrc file: export DART_SDK=/home/nicolas/dart/dart-sdk In command line, it works when I "echo" it. But I cannot see this user variable from dart with, I just see system variable but not mine: var env =…
12
votes
3 answers

What is the best way to stream stdout from a Process, in Dart?

I would like to run a Process, and stream the process's stdout to the console. What is the best (most effective, easiest to understand, least lines of code) way to do this? For example: var process = await Process.start(exec, args); I'd like to see…
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
11
votes
1 answer

Doing an HTTP Post with headers and a body

Right, so I've been working on something which requires basic authentication through headers, and passing some variables via HTTP Post. This is a terminal app. This is what my code looks like: import 'package:http/http.dart' as http; import…
Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
10
votes
1 answer

How can I print to stderr in Dart in a synchronous way?

I'm trying to print a message to stderr. Is there a way to pass the stderr filehandle to print?
Shannon -jj Behrens
  • 4,910
  • 2
  • 19
  • 24
1
2 3
12 13