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 TrafficLight { | |
static String updateLight(String currentState) { | |
return "Solution"; | |
} | |
} | |
void main() { | |
assert(TrafficLight.updateLight("green") == "yellow", | |
"Not correct answer for green"); | |
print("Color is yellow"); |
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
// Erweitere die Klasse string um die NumberParsing Extension | |
extension NumberParsing on String { | |
int parseInt() { | |
return int.parse(this); | |
} | |
String parseFloat() { | |
return double.parse(this).toStringAsFixed(2); | |
} | |
String changeDirection() { | |
return this.split('').reversed.join(); |
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 Vehicle { | |
String? make; | |
String? model; | |
int? manufactureYear; | |
int? vehicleAge; | |
String? color; | |
int get age { | |
return vehicleAge ?? 0; | |
} |
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
add2Numbers(int number1, {required int number2}) { | |
return number1 + number2; | |
} | |
add2NumbersNotReq([int number1 = 5, int number2 = 10]) { | |
return number1 + number2; | |
} | |
add2NumbersNamedOptional({required int number1, int? number2}) { | |
return number1 + (number2 ?? 0); |
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
Future<void> printOrderMessage() async { | |
print('Awaiting user order...'); | |
var order = await fetchUserOrder(); | |
print('Your order is: $order'); | |
} | |
Future<String> fetchUserOrder() { | |
// Imagine that this function is more complex and slow. | |
return Future.delayed(const Duration(seconds: 4), () => 'Large Latte'); | |
} | |
void main() async { |
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
// Erweitere die Klasse string um die NumberParsing Extension | |
extension StringParsing on String { | |
String changeDirection() { | |
return this.split('').reversed.join(); | |
} | |
// ··· | |
} | |
class Person { | |
String name = ''; |
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 'package:flutter/material.dart'; | |
import 'dart:async'; | |
import 'dart:math'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); |
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
Future<int> sumStream(Stream<int> stream) async { | |
var sum = 0; | |
await for (final value in stream) { | |
sum += value; | |
} | |
return sum; | |
} | |
Stream<int> countStream(int to) async* { | |
for (int i = 1; i <= to; i++) { |
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 { | |
String name; | |
String type; | |
User({required this.name, required this.type}); | |
} | |
enum MyEnum { | |
foo("test", "admin"), | |
bar("test2", "user"); |
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 MeinObjektPositionsParameter { | |
String name = ""; | |
// Positions Parameter an Stelle 1 | |
MeinObjektPositionsParameter(this.name); | |
} | |
class MeinObjektOptionalParameterDefault { | |
String name = ""; | |
// Positions Parameter an Stelle 1, aber optional mit default value | |
MeinObjektOptionalParameterDefault([this.name = 'FOO']) ; |