Skip to content

Commit 020bd04

Browse files
feat(ref: no-ref): fix comments
1 parent 60f51ed commit 020bd04

File tree

10 files changed

+97
-123
lines changed

10 files changed

+97
-123
lines changed

lib/common/input/input.widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class InputWidget extends StatelessWidget {
44
const InputWidget({
55
required this.textController,
66
required this.focusNode,
7-
required this.hintText,
87
required this.onSubmitted,
8+
this.hintText = '',
99
super.key,
1010
});
1111

lib/main.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import 'package:flutter/material.dart';
22
import 'package:get/get.dart';
33
import 'screens/home/home.screen.dart';
4+
import 'screens/home/home.binding.dart';
45

56
void main() {
6-
runApp(const TodoApp());
7+
runApp(const MyApp());
78
}
89

9-
class TodoApp extends StatelessWidget {
10-
const TodoApp({super.key});
10+
class MyApp extends StatelessWidget {
11+
const MyApp({super.key});
1112

1213
@override
1314
Widget build(BuildContext context) => GetMaterialApp(
14-
title: 'Todos',
15-
getPages: [
16-
GetPage(
17-
name: '/',
18-
page: HomeScreen.new,
19-
),
20-
],
15+
initialBinding: HomeBinding(),
16+
home: const HomeScreen(),
2117
);
2218
}

lib/screens/home/home.binding.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:get/get.dart';
2+
import 'todo/filter-panel/filter-panel.controller.dart';
3+
import 'todo/todo.controller.dart';
4+
5+
class HomeBinding extends Bindings {
6+
@override
7+
Future<void> dependencies() async {
8+
Get
9+
..lazyPut(TodoController.new)
10+
..lazyPut(FilterPanelController.new);
11+
}
12+
}

lib/screens/home/home.screen.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import 'package:flutter/material.dart';
2-
import 'package:get/get.dart';
3-
import 'todo/todo.controller.dart';
42
import 'todo/todo.widget.dart';
53
import '../home/title/title.widget.dart';
64

75
class HomeScreen extends StatelessWidget {
86
const HomeScreen({super.key});
97

108
@override
11-
Widget build(BuildContext context) {
12-
Get.lazyPut(TodoController.new);
13-
14-
return const Scaffold(
9+
Widget build(BuildContext context) => const Scaffold(
1510
backgroundColor: Colors.white,
1611
body: Center(
1712
child: Column(
@@ -22,5 +17,4 @@ class HomeScreen extends StatelessWidget {
2217
),
2318
),
2419
);
25-
}
2620
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:get/get.dart';
2+
import '../todo.controller.dart';
3+
import '../todo.model.dart';
4+
import 'filter-panel.model.dart';
5+
6+
class FilterPanelController extends GetxController {
7+
final TodoController todoController = Get.find<TodoController>();
8+
9+
final List<Filter> filters = const <Filter>[
10+
Filter(label: 'All', key: 'all'),
11+
Filter(label: 'Active', key: 'active'),
12+
Filter(label: 'Completed', key: 'completed'),
13+
];
14+
15+
final RxString currentFilter = 'all'.obs;
16+
17+
List<Task> get tasks => todoController.tasks;
18+
19+
List<Task> get filteredTasks {
20+
switch (currentFilter.value) {
21+
case 'active':
22+
return tasks.where((Task task) => !task.isFinished).toList();
23+
case 'completed':
24+
return tasks.where((Task task) => task.isFinished).toList();
25+
default:
26+
return tasks;
27+
}
28+
}
29+
30+
int get activeCount => tasks.where((Task task) => !task.isFinished).length;
31+
32+
void clearCompleted() {
33+
todoController.tasks.removeWhere((Task task) => task.isFinished);
34+
}
35+
}
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
import 'package:flutter/material.dart';
22
import 'package:get/get.dart';
33
import '../../../../common/button/button.widget.dart';
4-
import '../todo.controller.dart';
4+
import 'filter-panel.controller.dart';
55
import 'filter-panel.model.dart';
66

7-
class FilterPanelWidget extends GetView<TodoController> {
7+
class FilterPanelWidget extends GetView<FilterPanelController> {
88
const FilterPanelWidget({super.key});
99

1010
@override
11-
Widget build(BuildContext context) => Container(
12-
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
13-
child: Obx(() => Row(
14-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
15-
children: <Widget>[
16-
Text(
17-
'${controller.activeCount} items left',
18-
style: const TextStyle(fontSize: 14, color: Colors.grey),
19-
),
20-
Row(
21-
children: controller.filters
22-
.map((Filter filter) => ButtonWidget(
23-
label: filter.label,
24-
isActive:
25-
controller.currentFilter.value == filter.key,
26-
onTap: () => controller.setFilter(filter.key),
27-
))
28-
.toList(),
29-
),
30-
ButtonWidget(
31-
onTap: controller.clearCompleted,
32-
label: 'Clear completed',
33-
),
34-
],
35-
)),
36-
);
11+
Widget build(BuildContext context) => Obx(() {
12+
if (controller.tasks.isEmpty) {
13+
return const SizedBox();
14+
}
15+
16+
return Container(
17+
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
18+
child: Row(
19+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
20+
children: <Widget>[
21+
Text(
22+
'${controller.activeCount} items left',
23+
style: const TextStyle(fontSize: 14, color: Colors.grey),
24+
),
25+
Row(
26+
children: controller.filters
27+
.map<Widget>((Filter filter) => ButtonWidget(
28+
label: filter.label,
29+
isActive: controller.currentFilter.value == filter.key,
30+
onTap: () => controller.currentFilter.value = filter.key,
31+
))
32+
.toList(),
33+
),
34+
ButtonWidget(
35+
onTap: controller.clearCompleted,
36+
label: 'Clear completed',
37+
),
38+
],
39+
),
40+
);
41+
});
3742
}

lib/screens/home/todo/task-list/task-list.widget.dart

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
1-
// import 'package:flutter/material.dart';
2-
// import 'package:get/get.dart';
3-
// import '../todo.controller.dart';
4-
// import '../task-list-item/task-list-item.widget.dart';
5-
// import '../filter-panel/filter-panel.widget.dart';
6-
// import '../todo.model.dart';
7-
//
8-
// class TaskListWidget extends GetView<TodoController> {
9-
// const TaskListWidget({super.key});
10-
//
11-
// @override
12-
// Widget build(BuildContext context) => Obx(() {
13-
// final List<Task> filteredTasks = controller.filteredTasks;
14-
// final RxList<Task> tasks = controller.tasks;
15-
//
16-
// return Column(
17-
// children: <Widget>[
18-
// if (filteredTasks.isNotEmpty)
19-
// Column(
20-
// children: filteredTasks
21-
// .map(
22-
// (Task task) => TaskListItemWidget(
23-
// task: task,
24-
// onStatusChange: (bool status) =>
25-
// controller.updateTaskStatus(task, isFinished: status),
26-
// onUpdate: (String updatedText) =>
27-
// controller.updateTaskText(task, updatedText),
28-
// onDelete: () => controller.deleteTask(task),
29-
// ),
30-
// )
31-
// .toList(),
32-
// ),
33-
// if (tasks.isNotEmpty) const FilterPanelWidget(),
34-
// ],
35-
// );
36-
// });
37-
// }
381
import 'package:flutter/material.dart';
392
import 'package:get/get.dart';
3+
import '../filter-panel/filter-panel.controller.dart';
404
import '../todo.controller.dart';
415
import '../task-list-item/task-list-item.widget.dart';
426
import '../filter-panel/filter-panel.widget.dart';
@@ -47,14 +11,14 @@ class TaskListWidget extends GetView<TodoController> {
4711

4812
@override
4913
Widget build(BuildContext context) => Obx(() {
50-
final List<Task> filteredTasks = controller.filteredTasks;
51-
final RxList<Task> tasks = controller.tasks;
14+
final FilterPanelController filterController =
15+
Get.find<FilterPanelController>();
5216

5317
return Column(
5418
children: <Widget>[
55-
if (filteredTasks.isNotEmpty)
19+
if (filterController.filteredTasks.isNotEmpty)
5620
Column(
57-
children: filteredTasks
21+
children: filterController.filteredTasks
5822
.map(
5923
(Task task) => TaskListItemWidget(
6024
task: task,
@@ -67,7 +31,7 @@ class TaskListWidget extends GetView<TodoController> {
6731
)
6832
.toList(),
6933
),
70-
if (tasks.isNotEmpty) const FilterPanelWidget(),
34+
const FilterPanelWidget(),
7135
],
7236
);
7337
});
Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
11
import 'package:get/get.dart';
2-
import 'package:flutter/material.dart';
3-
import 'filter-panel/filter-panel.model.dart';
42
import 'todo.model.dart';
3+
import 'package:flutter/material.dart';
54

65
class TodoController extends GetxController {
76
final TextEditingController textController = TextEditingController();
87
final FocusNode focusNode = FocusNode();
9-
10-
final List<Filter> filters = const <Filter>[
11-
Filter(label: 'All', key: 'all'),
12-
Filter(label: 'Active', key: 'active'),
13-
Filter(label: 'Completed', key: 'completed'),
14-
];
15-
16-
17-
RxList<Task> tasks = <Task>[].obs;
18-
RxString currentFilter = 'all'.obs;
19-
20-
List<Task> get filteredTasks {
21-
switch (currentFilter.value) {
22-
case 'active':
23-
return tasks.where((Task task) => !task.isFinished).toList();
24-
case 'completed':
25-
return tasks.where((Task task) => task.isFinished).toList();
26-
default:
27-
return tasks;
28-
}
29-
}
30-
31-
int get activeCount => tasks.where((Task task) => !task.isFinished).length;
8+
final RxList<Task> tasks = <Task>[].obs;
329

3310
void addTask(String title) {
3411
tasks.add(Task(title: title));
@@ -53,12 +30,4 @@ class TodoController extends GetxController {
5330
void deleteTask(Task task) {
5431
tasks.remove(task);
5532
}
56-
57-
void setFilter(String filter) {
58-
currentFilter.value = filter;
59-
}
60-
61-
void clearCompleted() {
62-
tasks.removeWhere((Task task) => task.isFinished);
63-
}
6433
}

lib/screens/home/todo/todo.model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ class Task {
33

44
String title;
55
bool isFinished;
6-
}
6+
}

lib/screens/home/todo/todo.widget.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
22
import 'add-task/add-task.widget.dart';
33
import 'task-list/task-list.widget.dart';
44

5-
65
class TodoWidget extends StatelessWidget {
76
const TodoWidget({super.key});
87

0 commit comments

Comments
 (0)