Skip to content

Instantly share code, notes, and snippets.

View kwalrath's full-sized avatar

Kathy Walrath kwalrath

View GitHub Profile
@kwalrath
kwalrath / hint.txt
Last active May 17, 2019 19:58 — forked from redbrogdon/hint.txt
DartPad Cheatsheet Codelab - 2 - Null-aware operators
All you need to do in this exercise is replace the TODO comments with either ?? or ??=.
Read the codelab text to make sure you understand both, and then give it a try.
@kwalrath
kwalrath / hint.txt
Last active May 17, 2019 22:03 — forked from redbrogdon/hint.txt
DartPad Cheatsheet Codelab - 5 - Collection literals
This exercise is fairly straightforward. Just add a list, set, or map literal after each equals sign.
See the codelab text for the correct syntax to use.
@kwalrath
kwalrath / hint.txt
Last active May 18, 2019 03:38 — forked from redbrogdon/hint.txt
DartPad Cheatsheet Codelab - 12 - Initializer lists
Two assignments that need to happen: letterOne should be word[0], and letterTwo should be word[1].
@kwalrath
kwalrath / main.dart
Last active July 15, 2019 21:55
Convert timestamp
// Say the timestamp in the Travis log looks like this:
//
// travis_time:end:22889f10:start=1559926540498807523,finish=1559926542012374871,duration=1513567348
//
// This program prints the time in local and UTC time zones.
main() {
int build = (1559926542012374871.0/1e6).toInt();
var buildDateTime = DateTime.fromMillisecondsSinceEpoch(build);
print('Local time: $buildDateTime');
@kwalrath
kwalrath / main.dart
Last active July 17, 2019 00:21
event loop example
RaisedButton(
child: Text('Click me'),
onPressed: () {
final myFuture = http.get('https://example.com');
myFuture.then((response) {
if (response.statusCode == 200) {
print('Success!');
}
});
},
@kwalrath
kwalrath / main.dart
Last active July 23, 2019 22:23
event loop example #2
RaisedButton( // (1)
child: Text('Click me'),
onPressed: () { // (2)
final myFuture = http.get('https://example.com');
myFuture.then((response) { // (3)
if (response.statusCode == 200) {
print('Success!');
}
});
},
RaisedButton(
onPressed: () {
final myFuture = http.get('https://my.image.url');
myFuture.then((resp) {
setImage(resp);
});
},
child: Text('Click me!'),
)
void main() {
final myFuture = Future(() {
return 12;
});
}
void main() {
final myFuture = Future(() {
print('Creating the future.'); // Prints second.
return 12;
});
print('Done with main().'); // Prints first.
}
final myFuture = Future.delayed(
const Duration(seconds: 5),
() => 12,
);