Skip to content

Commit e7d57b2

Browse files
feat(ref: no-ref): fix comments
1 parent c782860 commit e7d57b2

File tree

8 files changed

+64
-84
lines changed

8 files changed

+64
-84
lines changed
Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
import 'package:flutter/material.dart';
22

33
class ButtonWidget extends StatelessWidget {
4-
const ButtonWidget({
5-
required this.label,
6-
required this.onTap,
7-
this.isActive = false,
8-
super.key,
9-
});
4+
const ButtonWidget(
5+
{
6+
required this.title,
7+
required this.onTap,
8+
this.isActive = false,
9+
super.key});
1010

11-
final String label;
11+
final String title;
1212
final bool isActive;
1313
final VoidCallback onTap;
1414

1515
@override
16-
Widget build(BuildContext context) => Padding(
17-
padding: const EdgeInsets.symmetric(horizontal: 8),
18-
child: TextButton(
19-
onPressed: onTap,
20-
style: ButtonStyle(
21-
side: WidgetStateProperty.all(
22-
BorderSide(
23-
color: isActive ? Colors.red : Colors.transparent,
24-
width: 2,
25-
),
26-
),
27-
foregroundColor: WidgetStateProperty.all(
28-
isActive ? Colors.red : Colors.grey,
29-
),
30-
padding: WidgetStateProperty.all(
31-
const EdgeInsets.symmetric(horizontal: 16),
32-
),
33-
),
34-
child: Text(
35-
label,
36-
style: TextStyle(
37-
fontSize: 14,
38-
fontWeight: isActive ? FontWeight.bold : FontWeight.normal,
39-
),
40-
),
41-
),
42-
);
43-
}
16+
Widget build(BuildContext context) => InkWell(
17+
onTap: onTap,
18+
borderRadius: BorderRadius.circular(14),
19+
child: Container(
20+
height: 40,
21+
padding: const EdgeInsets.symmetric(horizontal: 8),
22+
decoration: BoxDecoration(
23+
border: Border.all(
24+
color: isActive ? Colors.red : Colors.transparent,
25+
width: 2,
26+
),
27+
borderRadius: BorderRadius.circular(14)),
28+
child: Center(
29+
child: Text(title,
30+
style: const TextStyle(
31+
fontSize: 14,
32+
),
33+
)
34+
)
35+
)
36+
);
37+
}

lib/screens/home/todo/filter-panel/filter-panel.controller.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ import 'package:get/get.dart';
22
import '../todo.model.dart';
33
import '../todo.service.dart';
44
import 'filter-panel.enum.dart';
5-
import 'filter-panel.model.dart';
65

76
class FilterPanelController extends GetxController {
87
FilterPanelController(this._todoService);
98

109
final TodoService _todoService;
1110
final Rx<FilterType> currentFilter = FilterType.all.obs;
12-
final List<FilterModel> filters = const <FilterModel>[
13-
FilterModel(type: FilterType.all),
14-
FilterModel(type: FilterType.active),
15-
FilterModel(type: FilterType.completed),
16-
];
11+
final List<FilterType> filters = FilterType.values;
1712

18-
List<TaskModel> get filteredTasks => _todoService.filteredTasks(currentFilter.value.label);
13+
List<TaskModel> get filteredTasks => _todoService.filteredTasks(currentFilter.value);
1914
List<TaskModel> get tasks => _todoService.tasks;
2015

2116
int get activeCount => _todoService.activeCount;
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
enum FilterType {
2-
all,
3-
active,
4-
completed;
2+
all('All'),
3+
active('Active'),
4+
completed('Completed');
55

6-
String get label {
7-
switch (this) {
8-
case FilterType.all:
9-
return 'All';
10-
case FilterType.active:
11-
return 'Active';
12-
case FilterType.completed:
13-
return 'Completed';
14-
}
15-
}
16-
}
6+
const FilterType(this.type);
7+
8+
final String type;
9+
}

lib/screens/home/todo/filter-panel/filter-panel.model.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/screens/home/todo/filter-panel/filter-panel.widget.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:get/get.dart';
33
import '../../../../common/button/button.widget.dart';
44
import 'filter-panel.controller.dart';
5-
import 'filter-panel.model.dart';
5+
import 'filter-panel.enum.dart';
66

77
class FilterPanelWidget extends GetView<FilterPanelController> {
88
const FilterPanelWidget({super.key});
@@ -22,18 +22,19 @@ class FilterPanelWidget extends GetView<FilterPanelController> {
2222
'${controller.activeCount} items left',
2323
style: const TextStyle(fontSize: 14, color: Colors.grey),
2424
),
25-
Row(
25+
Wrap(
26+
spacing: 10,
2627
children: controller.filters
27-
.map<Widget>((FilterModel filter) => ButtonWidget(
28-
label: filter.label,
29-
isActive: controller.currentFilter.value == filter.type,
30-
onTap: () => controller.setFilter(filter.type),
28+
.map<Widget>((FilterType filter) => ButtonWidget(
29+
title: filter.type,
30+
isActive: controller.currentFilter.value == filter,
31+
onTap: () => controller.setFilter(filter),
3132
))
3233
.toList(),
3334
),
3435
ButtonWidget(
3536
onTap: controller.clearCompleted,
36-
label: 'Clear completed',
37+
title: 'Clear completed',
3738
),
3839
],
3940
),

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,23 @@ class TaskListWidget extends GetView<FilterPanelController> {
99
const TaskListWidget({super.key});
1010

1111
@override
12-
Widget build(BuildContext context) => Obx(() => Column(
13-
children: <Widget>[
14-
if (controller.filteredTasks.isNotEmpty)
15-
Column(
12+
Widget build(BuildContext context) => Column(
13+
children: <Widget>[
14+
Obx(() {
15+
if (controller.filteredTasks.isNotEmpty) {
16+
return Column(
1617
children: controller.filteredTasks
17-
.map(
18+
.map<Widget>(
1819
(TaskModel task) => TaskListItemWidget(
1920
task: task,
2021
),
2122
)
2223
.toList(),
23-
),
24-
const FilterPanelWidget(),
25-
],
26-
));
24+
);
25+
}
26+
return const SizedBox();
27+
}),
28+
const FilterPanelWidget(),
29+
],
30+
);
2731
}

lib/screens/home/todo/todo.service.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:get/get.dart';
2+
import 'filter-panel/filter-panel.enum.dart';
23
import 'todo.model.dart';
34

45
class TodoService extends GetxService {
@@ -14,11 +15,11 @@ class TodoService extends GetxService {
1415
}
1516

1617

17-
List<TaskModel> filteredTasks(String filter) {
18+
List<TaskModel> filteredTasks(FilterType filter) {
1819
switch (filter) {
19-
case 'active':
20+
case FilterType.active:
2021
return tasks.where((TaskModel task) => !task.isFinished).toList();
21-
case 'completed':
22+
case FilterType.completed:
2223
return tasks.where((TaskModel task) => task.isFinished).toList();
2324
default:
2425
return tasks;

test/widget_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:todo_mvc/main.dart';
1313
void main() {
1414
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
1515
// Build our app and trigger a frame.
16-
await tester.pumpWidget(TodoApp());
16+
await tester.pumpWidget(const MyApp());
1717

1818
// Verify that our counter starts at 0.
1919
expect(find.text('0'), findsOneWidget);

0 commit comments

Comments
 (0)