Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
build/
flutter_*.png
pubspec.lock
.metadata

# IntelliJ IDEs
.idea/
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
- Asynchrone Programmierung
- [Flutter](flutter/flutter.md)
- Widgets
- Build Context
- Layout
- BuildContext
- Styling & Theming
- State
- Debugging
- [Riverpod](riverpod/riverpod.md)
- [Bloc](bloc/bloc.md)
- Cubit
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
8 changes: 8 additions & 0 deletions dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ void main() async {

Für mehr Details über Streams siehe die Dokumentation zum [nutzen](https://dart.dev/libraries/async/using-streams) und [erstellen](https://dart.dev/libraries/async/creating-streams) von Streams.

## Networking

*TODO*

## Code Generation

*TODO*

## Weiterführendes

- [Late/Lazy Variablen](https://dart.dev/language/variables#late-variables)
Expand Down
49 changes: 27 additions & 22 deletions dart/challenges.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
// Challenge 1: Null Safety
String toUpperCaseOrDefault(String? input) {
// TODO: Implement logic to return the uppercase version or "DEFAULT" if null
return "";
return input?.toUpperCase() ?? "DEFAULT";
}

// Challenge 2: Typecasts
String describeObject(Object obj) {
// TODO: Implement logic to handle String, int, and other types
// If the object is a String, return its length
// If the object is an int, return its square
// For other types, return "Unknown type"
return "";
if (obj is String) {
return obj.length.toString();
} else if (obj is int) {
return (obj * obj).toString();
} else {
return "Unknown type";
}
}

// Challenge 3: Asynchronous Programming
Future<String> processUserName(
Future<Map<String, String>> userDataFuture,
) async {
// TODO: Wait for the future to complete and extract the "name" value
// If the "name" key is not present, return "Unknown"
return "";
final userData = await userDataFuture;
return userData["name"] ?? "Unknown";
}

// Challenge 4: Classes and Constructors
// Tests are commented out to avoid errors
class Person {
String name;
int age;

// TODO: Add default constructor

// TODO: Add named constructor with default values "Default Name" and 18

// TODO: Add factory constructor with caching logic

Person(this.name, this.age);

Person.named()
: name = "Default Name",
age = 18;

static final Map<String, Person> _cache = {};
factory Person.factory(String key) {
if (_cache.containsKey(key)) {
return _cache[key]!;
} else {
final person = Person(key, 30);
_cache[key] = person;
return person;
}
}
}

// Challenge 5: Optional and Named Parameters
// Tests are commented out to avoid errors
String createUser() {
// TODO: Add the right parameters to the function
// return "Name: $name, Age: $age, Email: $email";
return "";
String createUser(String name, [String? email, int age = 18]) {
return "Name: $name, Age: $age, Email: $email";
}
30 changes: 18 additions & 12 deletions dart/test/challenges_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,29 @@ void main() {

// Test for Challenge 4: Classes and Constructors
test('Person constructors work as expected', () {
// final person = Person("Alice", 30);
// expect(person.name, equals("Alice"));
// expect(person.age, equals(30));
final person = Person("Alice", 30);
expect(person.name, equals("Alice"));
expect(person.age, equals(30));

// final namedPerson = Person.named();
// expect(namedPerson.name, equals("Default Name"));
// expect(namedPerson.age, equals(18));
final namedPerson = Person.named();
expect(namedPerson.name, equals("Default Name"));
expect(namedPerson.age, equals(18));

// final cachedPerson = Person.factory("cached");
// final sameCachedPerson = Person.factory("cached");
// expect(cachedPerson, same(sameCachedPerson));
final cachedPerson = Person.factory("cached");
final sameCachedPerson = Person.factory("cached");
expect(cachedPerson, same(sameCachedPerson));
});

// Test for Challenge 5: Optional and Named Parameters
test('createUser handles optional and named parameters', () {
// expect(createUser("Alice"), equals("Name: Alice, Age: 18, Email: None"));
// expect(createUser("Bob", "[email protected]"), equals("Name: Bob, Age: 18, Email: [email protected]"));
// expect(createUser("Charlie", null, 25), equals("Name: Charlie, Age: 25, Email: None"));
expect(createUser("Alice"), equals("Name: Alice, Age: 18, Email: null"));
expect(
createUser("Bob", "[email protected]"),
equals("Name: Bob, Age: 18, Email: [email protected]"),
);
expect(
createUser("Charlie", null, 25),
equals("Name: Charlie, Age: 25, Email: null"),
);
});
}
Loading