Skip to content

Commit

Permalink
Merge pull request #3 from mrunix00/patch-2
Browse files Browse the repository at this point in the history
Add support for deleting notes
  • Loading branch information
mrunix00 committed Nov 25, 2023
2 parents cbd0531 + 8d7b4e6 commit c5b90b8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 33 deletions.
39 changes: 34 additions & 5 deletions lib/ui/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
import 'package:noteapp/bloc/fetch_notes/fetch_notes_bloc.dart';
import 'package:noteapp/data/interfaces/notes_repository.dart';

import '../widgets/note_tile.dart';
import '../widgets/square_icon_button.dart';
Expand Down Expand Up @@ -63,15 +64,16 @@ class _HomeScreenState extends State<HomeScreen> {
key: refreshIndicatorKey,
onRefresh: () async {
bloc.add(FetchNotes());
bloc.stream.firstWhere(
await bloc.stream.firstWhere(
(state) => state is! FetchNotesInProgress,
);
},
child: BlocBuilder<FetchNotesBloc, FetchNotesState>(
buildWhen: (previous, current) =>
current is! FetchNotesInProgress,
builder: (context, state) {
if (state is FetchNotesSuccess && state.notes.isNotEmpty) {
return ListView.separated(
shrinkWrap: true,
itemCount: state.notes.length,
separatorBuilder: (context, index) => const SizedBox(
height: 25,
Expand All @@ -85,9 +87,36 @@ class _HomeScreenState extends State<HomeScreen> {
Color(0xFF9EFFFF),
Color(0xFFB69CFF),
];
return NoteTile(
state.notes[index],
cardColor: colors[index % colors.length],
return Dismissible(
key: ValueKey(state.notes[index]),
background: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.delete,
size: 48,
),
),
onDismissed: (_) {
GetIt.I
.get<NotesRepository>()
.deleteNote(state.notes[index])
.then((value) {
final message = value != null
? value.message
: "Note was deleted successfully";
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
);
refreshIndicatorKey.currentState?.show();
});
},
child: NoteTile(
state.notes[index],
cardColor: colors[index % colors.length],
),
);
},
);
Expand Down
32 changes: 17 additions & 15 deletions lib/ui/widgets/note_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ class NoteTile extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Card(
shape: RoundedRectangleBorder(
return Container(
clipBehavior: Clip.hardEdge,
padding: const EdgeInsets.symmetric(
horizontal: 46,
vertical: 22,
),
decoration: BoxDecoration(
color: cardColor,
borderRadius: BorderRadius.circular(10),
),
color: cardColor,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 46,
vertical: 22,
),
child: Text(
note.title,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Colors.black,
fontSize: 25,
),
),
constraints: const BoxConstraints(
minWidth: double.infinity,
),
child: Text(
note.title,
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Colors.black,
fontSize: 25,
),
),
);
}
Expand Down
26 changes: 13 additions & 13 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -212,10 +212,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
multiple_result:
dependency: "direct main"
description:
Expand Down Expand Up @@ -361,18 +361,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -401,10 +401,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -449,10 +449,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
win32:
dependency: transitive
description:
Expand All @@ -478,5 +478,5 @@ packages:
source: hosted
version: "6.3.0"
sdks:
dart: ">=3.1.3 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.7.0"

0 comments on commit c5b90b8

Please sign in to comment.