Skip to content

Commit a4a6a83

Browse files
coderabbitai[bot]CodeRabbit
andauthored
fix: apply CodeRabbit auto-fixes
Fixed 3 file(s) based on 4 unresolved review comments. Co-authored-by: CodeRabbit <[email protected]>
1 parent 0e4ad09 commit a4a6a83

3 files changed

Lines changed: 68 additions & 10 deletions

File tree

src/lib/features/note/view/focus_widget.dart

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,27 @@ class QuickNoteCard extends StatelessWidget {
234234
children: [
235235
ClipRRect(
236236
borderRadius: BorderRadius.circular(8),
237-
child: Image.file(File(vm.selectedImagePath!), height: 80, width: 80, fit: BoxFit.cover),
237+
child: Image.file(
238+
File(vm.selectedImagePath!),
239+
height: 80,
240+
width: 80,
241+
fit: BoxFit.cover,
242+
errorBuilder: (context, error, stackTrace) {
243+
return Container(
244+
height: 80,
245+
width: 80,
246+
decoration: BoxDecoration(
247+
color: Colors.grey.shade300,
248+
borderRadius: BorderRadius.circular(8),
249+
),
250+
child: Icon(
251+
Icons.broken_image_outlined,
252+
color: Colors.grey.shade600,
253+
size: 40,
254+
),
255+
);
256+
},
257+
),
238258
),
239259
Positioned(
240260
top: -10,
@@ -321,7 +341,7 @@ class QuickNoteCard extends StatelessWidget {
321341
Text(note.content, style: const TextStyle(fontSize: 14, color: Color(0xFF2C3E50), height: 1.4)),
322342

323343
// DISPLAY ATTACHED IMAGE IN NOTE
324-
if (note.imagePath != null) ...[
344+
if (note.imagePath != null && note.imagePath!.isNotEmpty) ...[
325345
const SizedBox(height: 8),
326346
ClipRRect(
327347
borderRadius: BorderRadius.circular(10),
@@ -330,6 +350,34 @@ class QuickNoteCard extends StatelessWidget {
330350
width: double.infinity,
331351
height: 150,
332352
fit: BoxFit.cover,
353+
errorBuilder: (context, error, stackTrace) {
354+
return Container(
355+
width: double.infinity,
356+
height: 150,
357+
decoration: BoxDecoration(
358+
color: Colors.grey.shade300,
359+
borderRadius: BorderRadius.circular(10),
360+
),
361+
child: Column(
362+
mainAxisAlignment: MainAxisAlignment.center,
363+
children: [
364+
Icon(
365+
Icons.broken_image_outlined,
366+
color: Colors.grey.shade600,
367+
size: 50,
368+
),
369+
const SizedBox(height: 8),
370+
Text(
371+
'Image not available',
372+
style: TextStyle(
373+
color: Colors.grey.shade600,
374+
fontSize: 12,
375+
),
376+
),
377+
],
378+
),
379+
);
380+
},
333381
),
334382
),
335383
],

src/lib/features/note/viewmodel/focus_viewmodel.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ class FocusViewModel extends ChangeNotifier {
3939
final prefs = await SharedPreferences.getInstance();
4040
List<String>? noteStrings = prefs.getStringList('saved_notes');
4141
if (noteStrings != null) {
42-
notes = noteStrings.map((s) => NoteModel.fromJson(s)).toList();
42+
List<NoteModel> loadedNotes = [];
43+
for (String noteString in noteStrings) {
44+
try {
45+
loadedNotes.add(NoteModel.fromJson(noteString));
46+
} catch (e) {
47+
debugPrint("Error parsing note JSON: $e");
48+
// Skip the malformed entry and continue
49+
}
50+
}
51+
notes = loadedNotes;
4352
notifyListeners();
4453
}
4554
}
@@ -66,7 +75,7 @@ class FocusViewModel extends ChangeNotifier {
6675
}
6776

6877
// Add note (optionally with an image) instantly to the UI and save to disk
69-
void addNote() {
78+
Future<void> addNote() async {
7079
final text = noteController.text.trim();
7180
if (text.isEmpty && selectedImagePath == null) return; // Skip if both text and image are empty
7281

@@ -78,21 +87,21 @@ class FocusViewModel extends ChangeNotifier {
7887
));
7988

8089
_sortNotes();
81-
saveNotesToDisk(); // Persist data
90+
await saveNotesToDisk(); // Persist data
8291
noteController.clear();
8392
selectedImagePath = null; // Clear temporary image after saving
8493
notifyListeners();
8594
}
8695

8796
// Remove note instantly and update storage
88-
void removeNote(String id) {
97+
Future<void> removeNote(String id) async {
8998
notes.removeWhere((note) => note.id == id);
90-
saveNotesToDisk(); // Persist data
99+
await saveNotesToDisk(); // Persist data
91100
notifyListeners();
92101
}
93102

94103
// Pin/unpin note and update storage
95-
void togglePin(String id) {
104+
Future<void> togglePin(String id) async {
96105
final index = notes.indexWhere((n) => n.id == id);
97106
if (index != -1) {
98107
notes[index] = NoteModel(
@@ -102,7 +111,7 @@ class FocusViewModel extends ChangeNotifier {
102111
imagePath: notes[index].imagePath // Keep image when pinning
103112
);
104113
_sortNotes();
105-
saveNotesToDisk(); // Persist data
114+
await saveNotesToDisk(); // Persist data
106115
notifyListeners();
107116
}
108117
}

src/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies:
4141
provider: ^6.1.5+1
4242
flutter_ringtone_player: ^4.0.0+4
4343
image_picker: ^1.2.1
44+
shared_preferences: ^2.2.2
4445

4546
dev_dependencies:
4647
flutter_test:
@@ -90,4 +91,4 @@ flutter:
9091
# weight: 700
9192
#
9293
# For details regarding fonts from package dependencies,
93-
# see https://flutter.dev/to/font-from-package
94+
# see https://flutter.dev/to/font-from-package

0 commit comments

Comments
 (0)