Skip to content

Instantly share code, notes, and snippets.

View r3dm1ke's full-sized avatar
🎯
Before software can be reusable it first has to be usable.

Michael Krasnov r3dm1ke

🎯
Before software can be reusable it first has to be usable.
View GitHub Profile
@r3dm1ke
r3dm1ke / hello-world.dart
Created November 25, 2019 20:03
Hello World in Dart
void main() {
print('Hello world');
}
@r3dm1ke
r3dm1ke / variables.dart
Created November 25, 2019 20:15
Different types of variables in Dart
void main() {
// Create a variable name of type String
var name = 'John';
// Create a variable last_name of type String
String last_name = 'Smith';
// Create a dynamic variable age, which is of type int for now
dynamic age = 18;
@r3dm1ke
r3dm1ke / control-flow.dart
Created November 25, 2019 20:29
Control flow statements in Dart
import 'dart:io';
void main() {
// Read some text from console
var password = stdin.readLineSync();
// Check if password is correct
if (password == 'abc') {
print('Access granted');
} else if (password == 'xyz') {
@r3dm1ke
r3dm1ke / comments.dart
Created November 25, 2019 20:32
Comments in Dart
void main() {
// This is an inline comment
var a = 5;
/* This
is
a
multilne
comment
*/
}
@r3dm1ke
r3dm1ke / imports.dart
Created November 25, 2019 20:37
Basic imports in Dart
import 'dart:html'; // Import dart's standart HTML processing library
import '../lib/mylib.dart'; // Import your own file from another folder
@r3dm1ke
r3dm1ke / deferred-imports.dart
Created November 25, 2019 20:41
Deferred imports in Dart
// Importing standart math library
// Note that with deferred imports we have to specify its name
// using _is_ keyword
import 'dart:math' deferred as math;
void main() {
greet();
}
// This is a function that is async. I will talk about
@r3dm1ke
r3dm1ke / classes.dart
Created November 25, 2019 23:09
Class definitions in Dart
class Computer {
String hostname;
int numberOfCores;
// Syntactic sugar for instance variable assignment
Computer(this.hostname, this.numberOfCores) {
// Some initialization code
}
void ping() {
@r3dm1ke
r3dm1ke / classes-inheritance.dart
Created November 25, 2019 23:31
Class inheritance in Dart
class MacPro extends Computer {
double price;
MacPro(String hostname, int numberOfCores, this.price) : super(hostname, numberOfCores);
}
@r3dm1ke
r3dm1ke / mixins.dart
Created November 25, 2019 23:38
Mixins in Dart
mixin Battery {
int level = 100;
void die() {
this.level = 0;
}
}
class Laptop extends Computer with Battery {
//...
@r3dm1ke
r3dm1ke / interfaces.dart
Created November 25, 2019 23:44
Interfacing in Dart
class MockComputer extends Computer {
//....
}