-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
580 additions
and
101 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
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,22 +1,42 @@ | ||
import 'package:academia/exports/barrel.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:flutter/material.dart'; | ||
import '../todo.dart'; | ||
|
||
class TodoController extends GetxController { | ||
final RxList<Todo> allTodos = <Todo>[].obs; | ||
|
||
@override | ||
void onInit() { | ||
super.onInit(); | ||
getAllTodos().then((value) { | ||
debugPrint("[+] Todos Loaded"); | ||
}); | ||
} | ||
|
||
Future<bool> addTask(Todo t) async { | ||
int value = await TodoModelHelper().create(t.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
Future<bool> updateTodo(Todo t) async { | ||
t.complete = !t.complete; | ||
int value = await TodoModelHelper().update(t.toJson()); | ||
return value == 0 ? false : true; | ||
} | ||
|
||
Future<List<Todo>> getAllTodos() async { | ||
TodoModelHelper().queryAll().then((value) { | ||
allTodos.clear(); | ||
for (final val in value) { | ||
allTodos.add(Todo.fromJson(val)); | ||
debugPrint("[+]Todo loaded"); | ||
} | ||
}); | ||
return allTodos; | ||
} | ||
|
||
Future<bool> addTask(Todo t) async { | ||
int value = await TodoModelHelper().create(t.toJson()); | ||
Future<bool> deleteTodo(Todo t) async { | ||
int value = await TodoModelHelper().delete(t.toJson()); | ||
getAllTodos(); | ||
return value == 0 ? false : true; | ||
} | ||
} |
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,3 +1,18 @@ | ||
export 'todo_home_screen.dart'; | ||
export 'models/models.dart'; | ||
export 'controllers/todo_controller.dart'; | ||
export 'widgets/widgets.dart'; | ||
import "package:intl/intl.dart"; | ||
|
||
// Helper functions | ||
String trimAndEllipsis(String input, int maxLength) { | ||
if (input.length <= maxLength) { | ||
return input; | ||
} else { | ||
return "${input.substring(0, maxLength)}..."; | ||
} | ||
} | ||
|
||
String formatDateTime(DateTime dateTime) { | ||
return DateFormat('EEEE, d MMM y • H:mm a').format(dateTime); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:ionicons/ionicons.dart'; | ||
import '../todo_view_page.dart'; | ||
import 'package:lottie/lottie.dart'; | ||
|
||
class EmptyTodoHomeScreen extends StatelessWidget { | ||
const EmptyTodoHomeScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Lottie.asset( | ||
"assets/lotties/study.json", | ||
), | ||
Text( | ||
"Nothing here yet? Create a new task to get started with productivity", | ||
textAlign: TextAlign.center, | ||
style: Theme.of(context).textTheme.headlineSmall, | ||
), | ||
const SizedBox(height: 12), | ||
TextButton.icon( | ||
onPressed: () { | ||
Navigator.of(context).push(MaterialPageRoute( | ||
builder: (context) => const TodoViewPage(), | ||
)); | ||
}, | ||
icon: const Icon(Ionicons.add), | ||
label: const Text("Create todo item"), | ||
), | ||
], | ||
); | ||
} | ||
} |
Oops, something went wrong.