Skip to content

Commit

Permalink
Fixed Errors in NotesPage
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGuyDangerous committed Oct 28, 2022
1 parent fd564b4 commit 2c5f701
Show file tree
Hide file tree
Showing 15 changed files with 1,430 additions and 760 deletions.
26 changes: 17 additions & 9 deletions lib/Screens/edit_note_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class _AddEditNotePageState extends State<AddEditNotePage> {

@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: const Color(0xffffffff),
backgroundColor: const Color(0xff000000),
appBar: AppBar(
backgroundColor: const Color(0xFF2f2554),
toolbarHeight: 75,
backgroundColor: const Color(0xff000000),
actions: [buildButton()],
),
body: Form(
Expand All @@ -61,14 +62,21 @@ class _AddEditNotePageState extends State<AddEditNotePage> {

return Padding(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
child: FloatingActionButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
child: GestureDetector(
onTap: addOrUpdateNote,
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
border: Border.all(color: const Color(0x28ffffff)),
borderRadius: BorderRadius.circular(16),
color: const Color(0xff272727),
),
child: const Icon(
Iconsax.book_saved,
size: 36,
color: Color(0xa1ffffff),
),
),
backgroundColor: const Color(0xFFD1C4E9),
foregroundColor: const Color(0xFF512DA8),
onPressed: addOrUpdateNote,
child: const Icon(Iconsax.book_saved),
),
);
}
Expand Down
72 changes: 40 additions & 32 deletions lib/Screens/note_detail_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:iconsax/iconsax.dart';
import 'package:intl/intl.dart';
import 'package:voicerra/db/notes_database.dart';
import 'package:voicerra/model/note.dart';
Expand Down Expand Up @@ -37,45 +38,49 @@ class _NoteDetailPageState extends State<NoteDetailPage> {

@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: const Color(0xfff2f2f2),
backgroundColor: const Color(0xff000000),
appBar: AppBar(
backgroundColor: const Color(0xFF2f2554),
backgroundColor: const Color(0xFF000000),
centerTitle: true,
actions: [editButton(), deleteButton()],
),
body: isLoading
? const Center(child: CircularProgressIndicator())
: Padding(
padding: const EdgeInsets.all(12),
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 8),
children: [
Text(
note.title,
style: const TextStyle(
color: Color(0xff263238),
fontSize: 22,
fontWeight: FontWeight.bold,
child: SafeArea(
minimum: const EdgeInsets.only(left: 10),
child: ListView(
padding: const EdgeInsets.symmetric(vertical: 8),
children: [
Text(
note.title,
style: const TextStyle(
color: Color(0xff808080),
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 8),
Text(
DateFormat.yMMMd().format(note.createdTime),
style: const TextStyle(color: Colors.black26),
),
const SizedBox(height: 8),
Text(
note.description,
style: const TextStyle(
color: Color(0xff263238), fontSize: 18),
)
],
const SizedBox(height: 25),
Text(
DateFormat.yMMMd().format(note.createdTime),
style: const TextStyle(
color: Color(0x81808080), fontSize: 15),
),
const SizedBox(height: 28),
Text(
note.description,
style: const TextStyle(
color: Color(0xffffffff), fontSize: 20),
)
],
),
),
),
);

Widget editButton() => IconButton(
icon: const Icon(Icons.edit_outlined),
icon: const Icon(Iconsax.edit),
onPressed: () async {
if (isLoading) return;

Expand All @@ -86,13 +91,16 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
refreshNote();
});

Widget deleteButton() => IconButton(
icon: const Icon(Icons.delete),
onPressed: () async {
final navigator = Navigator.of(context);
await NotesDatabase.instance.delete(widget.noteId);
Widget deleteButton() => Padding(
padding: const EdgeInsets.only(right: 15.0, left: 5.0),
child: IconButton(
icon: const Icon(Iconsax.trash),
onPressed: () async {
final navigator = Navigator.of(context);
await NotesDatabase.instance.delete(widget.noteId);

navigator.pop();
},
navigator.pop();
},
),
);
}
176 changes: 85 additions & 91 deletions lib/Screens/notes_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:voicerra/db/notes_database.dart';
import 'package:voicerra/model/note.dart';
import 'package:voicerra/Screens/edit_note_page.dart';
import 'package:voicerra/Screens/note_detail_page.dart';
import 'package:voicerra/widget/customappbar.dart';
import 'package:voicerra/widget/note_card_widget.dart';
import 'package:iconsax/iconsax.dart';

Expand All @@ -16,6 +17,29 @@ class NotesPage extends StatefulWidget {
}

class _NotesPageState extends State<NotesPage> {
Widget buildNotes() => StaggeredGridView.countBuilder(
padding: const EdgeInsets.symmetric(vertical: 14.0, horizontal: 8.0),
itemCount: notes.length,
staggeredTileBuilder: (index) => const StaggeredTile.fit(2),
crossAxisCount: 4,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
itemBuilder: (context, index) {
final note = notes[index];

return GestureDetector(
onTap: () async {
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => NoteDetailPage(noteId: note.id!),
));

refreshNotes();
},
child: NoteCardWidget(note: note, index: index),
);
},
);

late List<Note> notes;
bool isLoading = false;

Expand All @@ -41,102 +65,72 @@ class _NotesPageState extends State<NotesPage> {
setState(() => isLoading = false);
}

_add() async {
await Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const AddEditNotePage()),
);

refreshNotes();
}

@override
Widget build(BuildContext context) => Scaffold(
backgroundColor: const Color(0xFF2f2554),
appBar: AppBar(
toolbarHeight: 80,
backgroundColor: const Color(0xFF2f2554),
elevation: 0,
centerTitle: true,
title: const Text(
'Notes',
style: TextStyle(
fontSize: 24, fontFamily: 'Raleway', color: Colors.white),
),
),
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics()),
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
color: Color(0xFFf2f2f2),
borderRadius: BorderRadius.only(
topRight: Radius.circular(40),
topLeft: Radius.circular(40),
backgroundColor: const Color(0xFF212025),
body: Stack(
children: [
SingleChildScrollView(
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics()),
child: Center(
child: isLoading
? const CircularProgressIndicator()
: notes.isEmpty
? Container(
height:
MediaQuery.of(context).copyWith().size.height,
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Iconsax.note_1,
color: Color(0x67ffffff),
size: 120,
),
SizedBox(
height: 20,
),
Text(
'empty!',
style: TextStyle(
fontWeight: FontWeight.w300,
fontSize: 22,
color: Color(0x67ffffff)),
),
],
),
)
: SafeArea(
minimum: const EdgeInsets.only(top: 150),
child: Container(
height: MediaQuery.of(context)
.copyWith()
.size
.height,
alignment: Alignment.topCenter,
child: buildNotes()),
),
),
),
child: Center(
child: isLoading
? const CircularProgressIndicator()
: notes.isEmpty
? Container(
alignment: Alignment.topCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: const [
SizedBox(
height: 150,
),
Icon(
Iconsax.note_1,
size: 120,
),
SizedBox(
height: 20,
),
Text(
'empty!',
style: TextStyle(
fontWeight: FontWeight.w300, fontSize: 22),
),
],
),
)
: buildNotes(),
SafeArea(
child: MyAppBar(
title: 'Notes',
onIconTap: _add,
iconName: Iconsax.add,
),
),
),
),
floatingActionButton: FloatingActionButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
backgroundColor: Colors.blue.shade100,
foregroundColor: Colors.black38,
child: const Icon(Icons.add),
onPressed: () async {
await Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const AddEditNotePage()),
);

refreshNotes();
},
],
),
);

Widget buildNotes() => StaggeredGridView.countBuilder(
padding: const EdgeInsets.symmetric(vertical: 14.0, horizontal: 8.0),
itemCount: notes.length,
staggeredTileBuilder: (index) => const StaggeredTile.fit(2),
crossAxisCount: 4,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
itemBuilder: (context, index) {
final note = notes[index];

return GestureDetector(
onTap: () async {
await Navigator.of(context).push(MaterialPageRoute(
builder: (context) => NoteDetailPage(noteId: note.id!),
));

refreshNotes();
},
child: NoteCardWidget(note: note, index: index),
);
},
);
}
Loading

0 comments on commit 2c5f701

Please sign in to comment.