1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:note_keeper/database/database.dart' ;
3
+ import 'package:provider/provider.dart' ;
2
4
3
5
class NoteListPage extends StatefulWidget {
4
6
const NoteListPage ({Key ? key}) : super (key: key);
@@ -8,15 +10,63 @@ class NoteListPage extends StatefulWidget {
8
10
}
9
11
10
12
class _NoteListPageState extends State <NoteListPage > {
13
+ late AppDatabase database;
11
14
@override
12
15
Widget build (BuildContext context) {
16
+ database = Provider .of <AppDatabase >(context);
13
17
return Scaffold (
14
- body: Center (
15
- child: Text (
16
- 'Hello World!' ,
17
- style: Theme .of (context).textTheme.headline5,
18
+ body: FutureBuilder <List <NoteData >>(
19
+ future: _getNoteFromDatabase (),
20
+ builder: (context, snapshot) {
21
+ if (snapshot.hasData) {
22
+ List <NoteData >? noteList = snapshot.data;
23
+ if (noteList != null ) {
24
+ if (noteList.isEmpty) {
25
+ return Center (
26
+ child: Text (
27
+ 'No Notes Found, Click on add button to add new note' ,
28
+ textAlign: TextAlign .center,
29
+ style: Theme .of (context).textTheme.bodyText2,
30
+ ),
31
+ );
32
+ } else {
33
+ return noteListUI (noteList);
34
+ }
35
+ }
36
+ } else if (snapshot.hasError) {
37
+ return Center (
38
+ child: Text (
39
+ snapshot.error.toString (),
40
+ style: Theme .of (context).textTheme.bodyText2,
41
+ ));
42
+ }
43
+ return Center (
44
+ child: Text (
45
+ 'Click on add button to add new note' ,
46
+ style: Theme .of (context).textTheme.bodyText2,
47
+ ),
48
+ );
49
+ },
50
+ ),
51
+ floatingActionButton: FloatingActionButton (
52
+ onPressed: () {},
53
+ shape: CircleBorder (
54
+ side: BorderSide (color: Colors .black, width: 2 ),
55
+ ),
56
+ backgroundColor: Colors .white,
57
+ child: Icon (
58
+ Icons .add,
59
+ color: Colors .black,
18
60
),
19
61
),
20
62
);
21
63
}
64
+
65
+ Future <List <NoteData >> _getNoteFromDatabase () async {
66
+ return await database.getNoteList ();
67
+ }
68
+
69
+ Widget noteListUI (List <NoteData > noteList) {
70
+ return Container ();
71
+ }
22
72
}
0 commit comments