rchkm

1

votes
0

answer
58

views

How to write to an HTML element from the server in Dart

I am trying to learn the basics of server side Dart. When I hit the submit element on the HTML page, the screen is cleared and replaced with 'hello.' I am trying to keep all elements in place, and put the 'hello' in the div place. I have not found any basic documentation on this, so I may be miss...
rchkm
1

votes
1

answer
521

views

How to implement async/await in Dart

I think I understand the idea behind async, returning a Future, but I am not clear on how async behaves on a very basic level. From my understanding, it does not automatically create asynchronous behavior in a program. For example: import 'dart:async'; main() { a(); b(); } a() { new Timer(new Dur...
rchkm
5

votes
2

answer
504

views

Difference between await for and listen in Dart

I am trying to create a web server stream. Here is the code: import 'dart:io'; main() async { HttpServer requestServer = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8000); requestServer.listen((request) { //comment out this or the await for to work request.response ..write('This is a li...
rchkm
12

votes
3

answer
5.3k

views

When to use part/part of versus import/export in Dart?

I do not completely understand the difference between part/part of and import/export when using libraries in Dart. For example: one.dart: library one; part 'two.dart'; Class One { }; and two.dart: part of one; import 'somefile.dart'; Class Two { } versus library one; import 'two.dart'; Class One {...
rchkm
13

votes
1

answer
2.3k

views

What does BuildContext do in Flutter?

I'm trying to learn Flutter, and hitting a wall rather early. What does BuildContext do, and what information do we get out of it? https://docs.flutter.io/flutter/widgets/BuildContext-class.html is just not clear. https://flutter.io/widgets-intro/#basic-widgets on the 9th instance of the term '...
rchkm
2

votes
3

answer
423

views

Moving elements by dragging in Dart

I am trying to move an element using drag and drop. I want to be able to drag and element to a different location, and when I drop it, the element moves to the dropped location. Super basic, and nothing fancy. This is what I have so far: html: Dart code: Element drag = querySelector('.draggable')...
rchkm
4

votes
2

answer
8.4k

views

How do getters and setters change properties in Dart?

I am struggling with the concept of getters and setters in Dart, and the more I read, the more I cannot grasp the underlying purpose. Take for example the following code: main() { Car car = new Car(); car.doors = 44; print(car.doors); // 44 } class Car { int doors = 4; } Later, I decide to make ...
rchkm
2

votes
2

answer
88

views

Future / Completer behavior in dart not running asynchronously

I am just trying to understand the behavior of Futures. Here is a sample code: import'dart:async'; main() { Future short = shortWait(); Future medium = mediumWait(); Future long = longWait(); long.then((String e)=>print(e)); medium.then((String e)=> print(e)); short.then((String e)=> print(e)); } F...
rchkm
1

votes
4

answer
4.1k

views

How to load images with image.file

I can't seem to simply load an image from the hard drive to the screen. Image.network seems straightforward. But I can't figure out how to use Image or Image.file. Image seems to require a stream, so I don't think that is what I am looking for. import 'package:flutter/material.dart'; import 'da...
rchkm
8

votes
2

answer
1.5k

views

How do you print a dollar sign $ in Dart

I need to actually print a Dollar sign in Dart, ahead of a variable. For example: void main() { int dollars=42; print('I have $dollars.'); // I have 42. } I want the output to be: I have $42. How can I do this? Thanks.
rchkm
2

votes
1

answer
88

views

Writing to a file through a loop in Dart

I am trying to write a series of Strings into a file, Letters.txt. import 'dart:io'; main() { List letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']; File file = new File('Letters.txt'); for (int i = 0; i < 10; i++) { file.writeAsString('${letters[i]}', mode: FileMode.APPEND); } } Wh...
rchkm