diff --git a/lib/src/models/note_model.g.dart b/lib/src/models/note_model.g.dart index 72c1342..22b13e7 100644 --- a/lib/src/models/note_model.g.dart +++ b/lib/src/models/note_model.g.dart @@ -12,7 +12,7 @@ _$_NoteModel _$$_NoteModelFromJson(Map json) => _$_NoteModel( subTitle: json['sub_title'] as String? ?? '', alarm: json['alarm'] as int?, time: json['time'] as int?, - type: _$enumDecode(_$NoteTypeEnumMap, json['type'], + type: $enumDecode(_$NoteTypeEnumMap, json['type'], unknownValue: NoteType.memory), finished: json['finished'] as bool? ?? false, fbDocsId: json['fb_docs_id'] as String?, @@ -32,32 +32,6 @@ Map _$$_NoteModelToJson(_$_NoteModel instance) => 'moved_to_trash': instance.movedToTrash, }; -K _$enumDecode( - Map enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - const _$NoteTypeEnumMap = { NoteType.todo: 'todo', NoteType.memory: 'memory', diff --git a/lib/src/ui/screens/todo/done_button.dart b/lib/src/ui/screens/todo/done_button.dart new file mode 100644 index 0000000..4b10ea8 --- /dev/null +++ b/lib/src/ui/screens/todo/done_button.dart @@ -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')); + } +} diff --git a/lib/src/ui/screens/todo/move_to_trash_button.dart b/lib/src/ui/screens/todo/move_to_trash_button.dart new file mode 100644 index 0000000..f416964 --- /dev/null +++ b/lib/src/ui/screens/todo/move_to_trash_button.dart @@ -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)); + } +} diff --git a/lib/src/ui/screens/todo/todo_page.dart b/lib/src/ui/screens/todo/todo_page.dart index 00867c3..111f1b3 100644 --- a/lib/src/ui/screens/todo/todo_page.dart +++ b/lib/src/ui/screens/todo/todo_page.dart @@ -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, @@ -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, + ); } } @@ -94,6 +100,7 @@ class _SectionFinishedTodoList extends StatelessWidget { )), _TodoListRaw( noteModels: todos, + finished: true, ), ], ); @@ -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 noteModels; @override @@ -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); @@ -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), ], ), ); @@ -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), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index a7718ff..f8ec3e4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index d06bd77..274f58f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,45 +33,43 @@ dependencies: # UI packages cupertino_icons: ^1.0.3 - animations: ^2.0.1 + animations: ^2.0.2 cached_network_image: ^3.1.0 # State manager flutter_riverpod: 1.0.0-dev.11 # build_runner packages - json_annotation: ^4.1.0 + json_annotation: ^4.3.0 freezed_annotation: ^0.15.0 # Firebase - firebase_core: ^1.7.0 - firebase_auth: ^3.1.3 - cloud_firestore: ^2.5.3 + firebase_core: ^1.8.0 + firebase_auth: ^3.1.4 + cloud_firestore: ^2.5.4 # Auth - google_sign_in: ^5.1.1 + google_sign_in: ^5.2.1 # Notification - flutter_local_notifications: ^9.0.0 + flutter_local_notifications: ^9.0.2 # DI get_it: ^7.2.0 # Utils collection: ^1.15.0 - share_plus: ^3.0.2 + share_plus: ^3.0.4 logger: ^1.1.0 intl: ^0.17.0 uuid: ^3.0.5 - - dev_dependencies: flutter_test: sdk: flutter build_runner: ^2.1.4 - json_serializable: ^5.0.2 + json_serializable: ^6.0.1 freezed: ^0.15.0+1 mockito: ^5.0.16 golden_toolkit: ^0.11.0