This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
main() { | |
// Prints '2017' after a second. | |
computeSomething().then(print); | |
} | |
Future<int> computeSomething() { | |
// Pretend to do a computation, and take some time. | |
return new Future.delayed(const Duration(seconds: 1), () => 2017); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
final messageStorage = <String>[]; | |
Future save(String message) { | |
var completer = new Completer(); | |
new Future(() => messagesStorage.add(message)).then((_) => completer.complete()); | |
return completer.future; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
final messageStorage = <String>[]; | |
Future save(String message) => new Future(() => messageStorage.add(message)); | |
Future<List<String> getAll() => new Future(() => messageStorage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Cxxxxxxxxxxx": "axxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | |
"axx": "Gxx", | |
"mxxxxx": "Gxx", | |
"qxxxx": "pxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | |
"rxxxxxxxxxx": "dxxx", | |
"rxxxxxx": "Mxxxxxxxxxxxxxxxxxxxxx", | |
"rxxxxxxx": { | |
"ixxxx": [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns a future that completes when a [Resolver] for Dart [sourceCode]. | |
/// | |
/// ``` | |
/// await resolveSource(r''' | |
/// import 'dart:collection'; | |
/// | |
/// Map createMap() => {}; | |
/// ''') | |
/// ``` | |
/// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define USER as a constant and give it an initial value. | |
const USER = { name: 'Joe'; } | |
// This will throw an error. | |
USER = {}; | |
// But this will not. | |
USER.name = 'Jill'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
const user = const {'name': 'Joe'}; | |
// Static error: "Constant variables cannot be assigned a value". | |
user = {}; | |
// Runtime error: "Unsupported operation: Cannot modify unmodifiable Map". | |
user['name'] = 'Jill'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
final String name; | |
const User(this.name); | |
} | |
main() { | |
const user = const User('Joe'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
final String name; | |
final List<String> cars; | |
User(this.name, {this.cars}); | |
} | |
main() { | |
for (var i = 0; i < 100; i++) { | |
const users = const { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'pacakge:meta/meta.dart'; | |
// Error: This class inherits from a class marked as @immutable, and therefore | |
// should be immutable (all instance fields must be final). | |
@immutable | |
class User { | |
String name; | |
} |