Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions lib/src/models/note_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions lib/src/ui/screens/todo/done_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:notes/src/models/note_model.dart';
import 'package:notes/src/ui/screens/home/providers/note_providers.dart';

class DoneButton extends ConsumerWidget {
const DoneButton({
Key? key,
required this.noteModel,
}) : super(key: key);
final NoteModel noteModel;

@override
Widget build(BuildContext context, WidgetRef ref) {
return OutlinedButton(
onPressed: () async {
final allNoteNotifier = ref.read(allNoteProvider.notifier);
allNoteNotifier.updateNote(noteModel.copyWith(finished: true));

final scaffoldMessager = ScaffoldMessenger.of(context);
scaffoldMessager.showSnackBar(SnackBar(
duration: const Duration(minutes: 1),
content: Text('Done "${noteModel.title}"'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
allNoteNotifier.updateNote(noteModel.copyWith(finished: false));
},
),
));
},
child: const Text('Done'));
}
}
35 changes: 35 additions & 0 deletions lib/src/ui/screens/todo/move_to_trash_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:notes/src/models/note_model.dart';
import 'package:notes/src/ui/screens/home/providers/note_providers.dart';

class MoveToTrashButton extends ConsumerWidget {
const MoveToTrashButton({
Key? key,
required this.noteModel,
}) : super(key: key);
final NoteModel noteModel;

@override
Widget build(BuildContext context, WidgetRef ref) {
return IconButton(
onPressed: () async {
final scaffoldMessager = ScaffoldMessenger.of(context);
final allNoteNotifier = ref.read(allNoteProvider.notifier);
await allNoteNotifier
.updateNote(noteModel.copyWith(movedToTrash: true));
scaffoldMessager.showSnackBar(SnackBar(
content: Text('Moved ${noteModel.title} to trash'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
allNoteNotifier
.updateNote(noteModel.copyWith(movedToTrash: false));
},
),
));
},
icon: const Icon(CupertinoIcons.trash));
}
}
67 changes: 37 additions & 30 deletions lib/src/ui/screens/todo/todo_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import 'package:notes/src/ui/screens/compose/compose_state.dart';
import 'package:notes/src/ui/screens/compose/providers.dart';
import 'package:notes/src/ui/screens/home/providers/note_providers.dart';
import 'package:notes/src/ui/screens/todo/providers.dart';
import 'package:notes/src/ui/screens/todo/move_to_trash_button.dart';
import 'package:notes/src/utils/time.dart';

import 'done_button.dart';

class TodoPage extends ConsumerWidget {
const TodoPage({
Key? key,
Expand Down Expand Up @@ -48,7 +51,10 @@ class _UnfinishedTodoList extends ConsumerWidget {
return const SizedBox();
}

return _TodoListRaw(noteModels: todos.map((e) => e.noteModel).toList());
return _TodoListRaw(
noteModels: todos.map((e) => e.noteModel).toList(),
finished: false,
);
}
}

Expand Down Expand Up @@ -94,6 +100,7 @@ class _SectionFinishedTodoList extends StatelessWidget {
)),
_TodoListRaw(
noteModels: todos,
finished: true,
),
],
);
Expand All @@ -104,8 +111,10 @@ class _TodoListRaw extends ConsumerWidget {
const _TodoListRaw({
Key? key,
required this.noteModels,
required this.finished,
}) : super(key: key);

final bool finished;
final List<NoteModel> noteModels;

@override
Expand All @@ -115,14 +124,17 @@ class _TodoListRaw extends ConsumerWidget {
physics: const NeverScrollableScrollPhysics(),
itemCount: noteModels.length,
itemBuilder: (context, index) {
return _ItemListRaw(noteModel: noteModels[index]);
if (finished) {
return _ItemFinishedRaw(noteModel: noteModels[index]);
}
return _ItemUnFinishedRaw(noteModel: noteModels[index]);
},
);
}
}

class _ItemListRaw extends ConsumerWidget {
const _ItemListRaw({
class _ItemUnFinishedRaw extends ConsumerWidget {
const _ItemUnFinishedRaw({
Key? key,
required this.noteModel,
}) : super(key: key);
Expand Down Expand Up @@ -160,32 +172,8 @@ class _ItemListRaw extends ConsumerWidget {
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
onChanged: (bool? value) {
ref
.read(allNoteProvider.notifier)
.updateNote(noteModel.copyWith(finished: value!));
},
value: noteModel.finished,
),
IconButton(
onPressed: () async {
final scaffoldMessager = ScaffoldMessenger.of(context);
final allNoteNotifier = ref.read(allNoteProvider.notifier);
await allNoteNotifier
.updateNote(noteModel.copyWith(movedToTrash: true));
scaffoldMessager.showSnackBar(SnackBar(
content: const Text('Moved 1 note to trash'),
action: SnackBarAction(
label: 'Undo',
onPressed: () {
allNoteNotifier.updateNote(
noteModel.copyWith(movedToTrash: false));
},
),
));
},
icon: const Icon(CupertinoIcons.trash))
DoneButton(noteModel: noteModel),
MoveToTrashButton(noteModel: noteModel),
],
),
);
Expand All @@ -200,3 +188,22 @@ class _ItemListRaw extends ConsumerWidget {
);
}
}

class _ItemFinishedRaw extends ConsumerWidget {
const _ItemFinishedRaw({
Key? key,
required this.noteModel,
}) : super(key: key);
final NoteModel noteModel;

@override
Widget build(BuildContext context, WidgetRef ref) {
const textStyle = TextStyle(decoration: TextDecoration.lineThrough);
return ListTile(
enabled: false,
title: Text(noteModel.title, style: textStyle),
subtitle: Text(noteModel.subTitle, style: textStyle),
trailing: MoveToTrashButton(noteModel: noteModel),
);
}
}
30 changes: 15 additions & 15 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ packages:
name: animations
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.2"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -161,21 +161,21 @@ packages:
name: cloud_firestore
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.3"
version: "2.5.4"
cloud_firestore_platform_interface:
dependency: transitive
description:
name: cloud_firestore_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "5.4.1"
version: "5.4.3"
cloud_firestore_web:
dependency: transitive
description:
name: cloud_firestore_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.2"
version: "2.4.4"
code_builder:
dependency: transitive
description:
Expand Down Expand Up @@ -252,28 +252,28 @@ packages:
name: firebase_auth
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
version: "3.1.4"
firebase_auth_platform_interface:
dependency: transitive
description:
name: firebase_auth_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.1"
version: "6.1.2"
firebase_auth_web:
dependency: transitive
description:
name: firebase_auth_web
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.2"
version: "3.1.3"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
firebase_core_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -327,7 +327,7 @@ packages:
name: flutter_local_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.0"
version: "9.0.2"
flutter_local_notifications_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -407,14 +407,14 @@ packages:
name: google_sign_in
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.1"
version: "5.2.1"
google_sign_in_platform_interface:
dependency: transitive
description:
name: google_sign_in_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.1.0"
google_sign_in_web:
dependency: transitive
description:
Expand Down Expand Up @@ -477,14 +477,14 @@ packages:
name: json_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
version: "4.3.0"
json_serializable:
dependency: "direct dev"
description:
name: json_serializable
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.2"
version: "6.0.1"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -673,7 +673,7 @@ packages:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
version: "3.0.4"
share_plus_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -741,7 +741,7 @@ packages:
name: source_helper
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
version: "1.3.0"
source_span:
dependency: transitive
description:
Expand Down
Loading