Last active
July 20, 2020 12:46
-
-
Save Nailik/dec160ba097348cefa54085f694659a8 to your computer and use it in GitHub Desktop.
Dart Einstieg
This file contains 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
// Copyright 2015 the Dart project authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license | |
// that can be found in the LICENSE file. | |
import "dart:async"; | |
void main() { | |
print(AutoMarkeExtension.fromText("Mercedes").toText()); | |
dynamic car = new Car("Mercedes"); | |
print(car); | |
final car2 = Car("Mercedes", color: "blue"); | |
car2.printCheck(); | |
} | |
class Car{ | |
dynamic name; | |
String _color; | |
int number = 3; | |
get color => _color; | |
Car(this.name, {color}) : _color = color; | |
//geht nicht schon defined | |
//Car(this.name, this.color); | |
toString() => "$name ${'${_color ?? "nullcolor"}'}"; | |
Future<bool> checkCar() { | |
return new Future.delayed(const Duration(seconds : 1), () => true); | |
} | |
printCheck () { | |
checkCar().then((value) => print("check $value")); | |
print("beforecheck".firstUpper()); | |
} | |
} | |
extension StringExtension on String{ | |
firstUpper() => this[0].toUpperCase() + this.substring(1); | |
} | |
enum AutoMarke{ | |
//Mercedes = "Mercedes", geht nicht | |
Mercedes, | |
BMW, | |
Opel | |
} | |
extension AutoMarkeExtension on AutoMarke{ | |
toText(){ | |
switch(this){ | |
case AutoMarke.Mercedes: | |
return "Mercedes"; | |
} | |
} | |
static AutoMarke fromText(String value){ | |
switch(value){ | |
case "Mercedes": | |
return AutoMarke.Mercedes; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment