Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
carllosnc committed Aug 24, 2024
1 parent 5e95fbb commit abc6d86
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 35 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,14 @@ void main() {
}
```

## Use cases

<img src="tomato.jpg">

Tomato works like a Pomodoro timer, you can create multiple timers to organize your tasks and breks.
This project use `flutter_shared_state` tecnique to share the states between multiple widgets and
manage a lot of changes in the user interface.

---

Carlos Costa @ 2024
83 changes: 48 additions & 35 deletions lib/modules/todo_list/todo_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class _TodoListPageState extends State<TodoListPage> with SharedState {
@override
Widget build(BuildContext context) {
return Scaffold(
key: const ValueKey('todo_list_page'),
floatingActionButton: FloatingActionButton(
key: const ValueKey('add_todo_button'),
onPressed: () {
todoList.addTodo(
description: 'New Todo: ${todoList.randomId}',
Expand All @@ -25,45 +27,56 @@ class _TodoListPageState extends State<TodoListPage> with SharedState {
appBar: AppBar(
title: Text('Todo List - Total: ${todoList.todos.length}'),
),
body: ListView.builder(
itemCount: todoList.todos.length,
itemBuilder: (context, index) {
Todo todo = todoList.todos[index];
body: Builder(builder: (context) {
if (todoList.todos.isEmpty) {
return const Center(
key: ValueKey('todo_list_empty_message'),
child: Text('No Todos', style: TextStyle(fontSize: 20)),
);
}

return ListView.builder(
key: const ValueKey('todo_list_body'),
itemCount: todoList.todos.length,
itemBuilder: (context, index) {
Todo todo = todoList.todos[index];

return ListTile(
title: Text(
todo.description,
style: TextStyle(
fontSize: 20,
color: todo.done ? Colors.red : Colors.black,
decoration: todo.done ? TextDecoration.lineThrough : null,
return ListTile(
key: ValueKey("todo_list_item_$index"),
title: Text(
todo.description,
style: TextStyle(
fontSize: 20,
color: todo.done ? Colors.red : Colors.black,
decoration: todo.done ? TextDecoration.lineThrough : null,
),
),
),
onTap: () {
setDescription(context, (String description) {
todoList.setDescription(
todo.id,
description,
);
});
},
leading: IconButton(
onPressed: () {
todoList.checkTodo(todo.id, !todo.done);
onTap: () {
setDescription(context, (String description) {
todoList.setDescription(
todo.id,
description,
);
});
},
icon: Icon(
todo.done ? Icons.check_box : Icons.check_box_outline_blank,
leading: IconButton(
onPressed: () {
todoList.checkTodo(todo.id, !todo.done);
},
icon: Icon(
todo.done ? Icons.check_box : Icons.check_box_outline_blank,
),
),
),
trailing: IconButton(
onPressed: () {
todoList.removeTodo(todo.id);
},
icon: const Icon(Icons.delete),
),
);
},
),
trailing: IconButton(
onPressed: () {
todoList.removeTodo(todo.id);
},
icon: const Icon(Icons.delete),
),
);
},
);
}),
);
}

Expand Down
16 changes: 16 additions & 0 deletions test/widgets/todo_list_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_shared_state/modules/todo_list/todo_list_page.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('check rendering of todo list', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: TodoListPage(),
));

await tester.pumpAndSettle();

//see empty message
expect(find.byKey(const ValueKey('todo_list_empty_message')), findsOneWidget);
});
}
Binary file added tomato.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit abc6d86

Please sign in to comment.