1
1
import 'package:flutter/material.dart' ;
2
- import 'package:shared_preferences/shared_preferences.dart' ;
3
2
import 'dart:io' ;
4
3
import 'package:flutter_string_encryption/flutter_string_encryption.dart' ;
5
4
import 'dart:async' ;
6
5
import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
7
6
import 'package:path_provider/path_provider.dart' ;
7
+ import 'package:shared_preferences/shared_preferences.dart' ; // TODO get rid of this
8
8
9
9
// TODO: encrypt notes and their titles
10
10
// decrypt all titles (seperate file), to build the listView
@@ -31,7 +31,7 @@ class HomePage extends StatefulWidget {
31
31
}
32
32
33
33
class HomePageState extends State <HomePage > {
34
- // DECLARATIONS
34
+
35
35
final GlobalKey <ScaffoldState > _scaffoldState = new GlobalKey <ScaffoldState >();
36
36
37
37
final _storage = new FlutterSecureStorage (); // to securely store the salt
@@ -55,9 +55,11 @@ class HomePageState extends State<HomePage> {
55
55
debugPrint (_generatedKey);
56
56
}
57
57
58
- void _loadIDsFromMemory () async {
59
- SharedPreferences prefs = await SharedPreferences .getInstance ();
60
- setState ( () => _noteIDs = new Set .from (prefs.getStringList ("noteIDs" )) ?? new Set ());
58
+ void _loadIDsFromMemory () async { // TODO fix this!!!!! test this!!!!!
59
+ String _noteIDsString = await readTitles ();
60
+ String separator = "\$ " ;
61
+ List <String > _noteIDsList = _noteIDsString.split (separator);
62
+ setState ( () => _noteIDs = new Set .from (_noteIDsList) ?? new Set ());
61
63
}
62
64
63
65
@override
@@ -116,7 +118,7 @@ class HomePageState extends State<HomePage> {
116
118
new ListTile (
117
119
leading: new Icon (Icons .library_books),
118
120
title: new Text ("aj" ),
119
- onTap: () => Navigator . of (context). pushNamed ( "/noteEditor/aj" ) ,
121
+ onTap: readTitles ,
120
122
),
121
123
new ListTile (
122
124
leading: new Icon (Icons .exit_to_app),
@@ -128,32 +130,29 @@ class HomePageState extends State<HomePage> {
128
130
);
129
131
}
130
132
131
- Future <String > get _localPath async {
132
- final directory = await getApplicationDocumentsDirectory ();
133
- return directory.path;
134
- }
135
-
136
- Future <File > get _titleFile async {
137
- final path = await _localPath;
138
- return new File ('$path /note_titles.txt' );
139
- }
140
-
141
- Future <File > writeTitles (String titles) async {
142
- final file = await _titleFile;
143
- return file.writeAsString ('$titles ' ); // Write the file
133
+ void writeTitles (String titles) async {
134
+ final path = (await getApplicationDocumentsDirectory ()).path;
135
+ final file = new File ('$path /note_titles.txt' );
136
+ file.writeAsString ('$titles ' ); // Write the file
144
137
}
145
138
146
- Future <int > readCounter () async {
139
+ Future <String > readTitles () async {
147
140
try {
148
- final file = await _titleFile;
141
+ final path = (await getApplicationDocumentsDirectory ()).path;
142
+ final file = new File ('$path /note_titles.txt' );
149
143
String contents = await file.readAsString (); // Read the file
150
- return int .parse (contents);
144
+ debugPrint ("he" );
145
+ debugPrint (contents);
146
+ return contents;
151
147
}
152
- catch (e) {
153
- return 0 ; // If we encounter an error, return 0
148
+ catch (e) { // No file yet
149
+ debugPrint ("er" );
150
+ return "" ; // If we encounter an error, return empty str
154
151
}
155
152
}
156
153
154
+
155
+
157
156
158
157
159
158
}
0 commit comments