-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): Format and style
todo
example (#27)
Applies formatting and style rules to the `todo` example.
- Loading branch information
Showing
12 changed files
with
379 additions
and
365 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
import 'package:celest_backend/client.dart'; | ||
import 'package:celest_backend/exceptions.dart'; | ||
import 'package:celest_backend/models.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
|
||
List<Task> tasks = []; | ||
Map<String, Task> tasks = {}; | ||
|
||
List<Task> alltasks() { | ||
Future<Map<String, Task>> listAllTasks() async { | ||
print('fetching tasks'); | ||
return tasks; | ||
} | ||
|
||
Future<List<Task>> addTask( | ||
{required String title, required String importance}) async { | ||
Future<void> addTask({ | ||
required String title, | ||
required Importance importance, | ||
}) async { | ||
print('creating new task'); | ||
if(title.trim().isEmpty){ | ||
if (title.trim().isEmpty) { | ||
throw ServerException('Title cannot be empty'); | ||
} | ||
var uuid = Uuid(); | ||
final newTask = Task( | ||
id: uuid.v1(), | ||
title: title, | ||
importance: importance, | ||
); | ||
tasks.add(newTask); | ||
return alltasks(); | ||
id: uuid.v1(), | ||
title: title, | ||
importance: importance, | ||
); | ||
tasks[newTask.id] = newTask; | ||
} | ||
|
||
Future<List<Task>> deleteTask({required String id}) async { | ||
Future<void> deleteTask({required String id}) async { | ||
print('removing task $id'); | ||
tasks.removeWhere((element) => element.id == id); | ||
return alltasks(); | ||
tasks.remove(id); | ||
} | ||
|
||
Future<void> markAsCompleted({required String id}) async { | ||
print('marking as completed'); | ||
Task task = tasks.where((element) => element.id == id).first; | ||
int index = tasks.indexOf(task); | ||
print('index of completed task: $index'); | ||
tasks.removeAt(index); | ||
tasks.insert(index, task.copyWith(id: DateTime.now().microsecondsSinceEpoch.toString(), isCompleted: true)); | ||
final task = tasks[id]; | ||
if (task == null) { | ||
throw ServerException('Task not found'); | ||
} | ||
tasks[id] = task.copyWith(isCompleted: true); | ||
} | ||
|
||
Future<void> markAsIncomplete({required String id}) async { | ||
print('marking as incomplete'); | ||
Task task = tasks.where((element) => element.id == id).first; | ||
int index = tasks.indexOf(task); | ||
print('index of completed task: $index'); | ||
tasks.removeAt(index); | ||
tasks.insert(index, task.copyWith(id: DateTime.now().microsecondsSinceEpoch.toString(),isCompleted: false)); | ||
final task = tasks[id]; | ||
if (task == null) { | ||
throw ServerException('Task not found'); | ||
} | ||
tasks[id] = task.copyWith(isCompleted: false); | ||
} |
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
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
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
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
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
Oops, something went wrong.