Compare commits
1 Commits
controller
...
joe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28e5fc4f7a |
@@ -22,26 +22,28 @@ class NoteDatabase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Database> _initDB(String filePath) async {
|
Future<Database> _initDB(String filePath) async {
|
||||||
|
// On Android, it is typically data/data//databases.
|
||||||
|
// On iOS and MacOS, it is the Documents directory.
|
||||||
final databasePath = await getDatabasesPath();
|
final databasePath = await getDatabasesPath();
|
||||||
|
// Directory databasePath = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
final path = join(databasePath, filePath);
|
final path = join(databasePath, filePath);
|
||||||
return await openDatabase(path, version: 1, onCreate: _createDB);
|
return await openDatabase(path, version: 1, onCreate: _createDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _createDB(Database database, int version) async {
|
Future _createDB(Database database, int version) async {
|
||||||
if (await isDatabaseExists()) {
|
//check if the database is created
|
||||||
|
if (database.query(noteTable) != null) {
|
||||||
print("Database already created");
|
print("Database already created");
|
||||||
deleteDatabase();
|
|
||||||
print("Database deleted");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}else{
|
||||||
|
print("demo data inserting");
|
||||||
await database.execute('''CREATE TABLE promemoria (
|
await database.execute('''CREATE TABLE promemoria (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
creationDate TEXT NOT NULL,
|
creationDate TEXT NOT NULL,
|
||||||
lastModificationDate TEXT,
|
lastModificationDate TEXT,
|
||||||
expirationDate TEXT,
|
expirationDate TEXT,
|
||||||
arrayPromemoria TEXT,
|
|
||||||
description TEXT,
|
description TEXT,
|
||||||
priority TEXT,
|
priority TEXT,
|
||||||
color TEXT
|
color TEXT
|
||||||
@@ -53,32 +55,22 @@ class NoteDatabase {
|
|||||||
title TEXT NOT NULL,
|
title TEXT NOT NULL,
|
||||||
creationDate TEXT NOT NULL,
|
creationDate TEXT NOT NULL,
|
||||||
lastModificationDate TEXT,
|
lastModificationDate TEXT,
|
||||||
arrayPromemoria TEXT,
|
|
||||||
description TEXT
|
description TEXT
|
||||||
);
|
);
|
||||||
''');
|
''');
|
||||||
|
|
||||||
print("database created");
|
print("database created");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
await fillDemoData(database, version);
|
await fillDemoData(database, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future fillDemoData(Database database, int version) async {
|
Future fillDemoData(Database database, int version) async {
|
||||||
|
|
||||||
var nota = Note();
|
print("boh speriamo funzioni");
|
||||||
nota.setTitle("Nota 1");
|
// Add some fake accounts
|
||||||
nota.setCreationDate("2023-09-56");
|
|
||||||
nota.setLastModificationDate("2023-09-56");
|
|
||||||
nota.setArrayPromemoria("1,2,3,4,5");
|
|
||||||
nota.setDescription("Questo è un esempio di nota 1.");
|
|
||||||
|
|
||||||
await createNote(database, nota);
|
|
||||||
|
|
||||||
print(await readNote(1));
|
|
||||||
|
|
||||||
nota.setDescription("ciao");
|
|
||||||
await updateNote (nota);
|
|
||||||
|
|
||||||
print(await readNote (1));
|
|
||||||
|
|
||||||
// Add fake categories
|
// Add fake categories
|
||||||
await database.execute('''
|
await database.execute('''
|
||||||
@@ -86,7 +78,6 @@ class NoteDatabase {
|
|||||||
title,
|
title,
|
||||||
creationDate,
|
creationDate,
|
||||||
lastModificationDate,
|
lastModificationDate,
|
||||||
arrayPromemoria,
|
|
||||||
description
|
description
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'Nota 2',
|
'Nota 2',
|
||||||
@@ -96,12 +87,12 @@ class NoteDatabase {
|
|||||||
)
|
)
|
||||||
''');
|
''');
|
||||||
|
|
||||||
|
|
||||||
await database.execute('''
|
await database.execute('''
|
||||||
INSERT INTO note (
|
INSERT INTO note (
|
||||||
title,
|
title,
|
||||||
creationDate,
|
creationDate,
|
||||||
lastModificationDate,
|
lastModificationDate,
|
||||||
arrayPromemoria,
|
|
||||||
description
|
description
|
||||||
) VALUES (
|
) VALUES (
|
||||||
'Nota 2',
|
'Nota 2',
|
||||||
@@ -118,7 +109,6 @@ class NoteDatabase {
|
|||||||
creationDate,
|
creationDate,
|
||||||
lastModificationDate,
|
lastModificationDate,
|
||||||
expirationDate,
|
expirationDate,
|
||||||
arrayPromemoria,
|
|
||||||
description,
|
description,
|
||||||
priority,
|
priority,
|
||||||
color
|
color
|
||||||
@@ -140,7 +130,6 @@ class NoteDatabase {
|
|||||||
creationDate,
|
creationDate,
|
||||||
lastModificationDate,
|
lastModificationDate,
|
||||||
expirationDate,
|
expirationDate,
|
||||||
arrayPromemoria,
|
|
||||||
description,
|
description,
|
||||||
priority,
|
priority,
|
||||||
color
|
color
|
||||||
@@ -170,27 +159,6 @@ class NoteDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future close() async {
|
|
||||||
final database = await instance.database;
|
|
||||||
database.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> deleteDatabase() async {
|
|
||||||
final databasePath = await getDatabasesPath();
|
|
||||||
final path = join(databasePath, 'note.db');
|
|
||||||
databaseFactory.deleteDatabase(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> isDatabaseExists() async {
|
|
||||||
final databasePath = await getDatabasesPath();
|
|
||||||
final path = join(databasePath, 'note.db');
|
|
||||||
// Apre il database in modalità sola lettura.
|
|
||||||
Database database = await openDatabase(path, readOnly: true);
|
|
||||||
|
|
||||||
// Restituisce true se il database è stato aperto correttamente, altrimenti false.
|
|
||||||
return database.isOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<Map>> selectAllPromemoria() async {
|
Future<List<Map>> selectAllPromemoria() async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
|
|
||||||
@@ -199,61 +167,15 @@ class NoteDatabase {
|
|||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Map>> selectAllNotes() async {
|
Future close() async {
|
||||||
final db = await database;
|
final database = await instance.database;
|
||||||
|
database.close();
|
||||||
final List<Map<String, dynamic>> maps = await db.query(noteTable);
|
|
||||||
|
|
||||||
return maps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createNote(Database database, Note note) async {
|
// WARNING: FOR DEV/TEST PURPOSES ONLY!!
|
||||||
await database.insert(
|
Future<void> deleteDatabase() async {
|
||||||
'note',
|
final databasePath = await getDatabasesPath();
|
||||||
note.toMap(),
|
final path = join(databasePath, 'note.db');
|
||||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
databaseFactory.deleteDatabase(path);
|
||||||
);
|
|
||||||
|
|
||||||
print('note $note.title inserted');
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> createPromemoria(
|
|
||||||
Database database, Promemoria promemoria) async {
|
|
||||||
await database.insert(
|
|
||||||
'promemoria',
|
|
||||||
promemoria.toMap(),
|
|
||||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
|
||||||
);
|
|
||||||
|
|
||||||
print('promemoria $promemoria.title inserted');
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Map<String, Object?>> readPromemoria(int id) async {
|
|
||||||
final db = await database;
|
|
||||||
|
|
||||||
final results = await db.query('SELECT * FROM note where id=$id');
|
|
||||||
return results.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<Map<String, Object?>> readNote(int id) async {
|
|
||||||
final db = await database;
|
|
||||||
|
|
||||||
final results = await db.query('SELECT * FROM promemoria where id=$id');
|
|
||||||
|
|
||||||
return results.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> updatePromemoria(Promemoria promemoria) async {
|
|
||||||
final db = await database;
|
|
||||||
|
|
||||||
await db.update('promemoria', promemoria.toMap(),
|
|
||||||
where: 'id = ?', whereArgs: [promemoria.getId()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> updateNote(Note note) async {
|
|
||||||
final db = await database;
|
|
||||||
|
|
||||||
await db.update('note', note.toMap(),
|
|
||||||
where: 'id = ?', whereArgs: [note.getId()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ import 'myApp.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MyApp());
|
runApp(MyApp());
|
||||||
print("App started");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,63 +9,4 @@ class Note extends BaseEntity {
|
|||||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||||
static String arrayPromemoria = '';
|
static String arrayPromemoria = '';
|
||||||
static String description = '';
|
static String description = '';
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
|
||||||
return {
|
|
||||||
'id': id,
|
|
||||||
'title': title,
|
|
||||||
'creationDate': creationDate,
|
|
||||||
'lastModificationDate': lastModificationDate,
|
|
||||||
'arrayPromemoria': arrayPromemoria,
|
|
||||||
'description': description
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setId(String id) {
|
|
||||||
id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTitle(String title) {
|
|
||||||
title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getCreationDate() {
|
|
||||||
return creationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCreationDate(String creationDate) {
|
|
||||||
creationDate = creationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getLastModificationDate() {
|
|
||||||
return lastModificationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLastModificationDate(String lastModificationDate) {
|
|
||||||
lastModificationDate = lastModificationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getArrayPromemoria() {
|
|
||||||
return arrayPromemoria;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setArrayPromemoria(String arrayPromemoria) {
|
|
||||||
arrayPromemoria = arrayPromemoria;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDescription(String description) {
|
|
||||||
description = description;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,85 +13,6 @@ class Promemoria extends BaseEntity {
|
|||||||
static String arrayPromemoria = '';
|
static String arrayPromemoria = '';
|
||||||
static String description = '';
|
static String description = '';
|
||||||
static Priority priority = Priority.none;
|
static Priority priority = Priority.none;
|
||||||
|
|
||||||
static Color color = Color.none;
|
static Color color = Color.none;
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
|
||||||
return {
|
|
||||||
'id': id,
|
|
||||||
'title': title,
|
|
||||||
'creationDate': creationDate,
|
|
||||||
'lastModificationDate': lastModificationDate,
|
|
||||||
'expirationDate': expirationDate,
|
|
||||||
'arrayPromemoria': arrayPromemoria,
|
|
||||||
'description': description,
|
|
||||||
'priority': priority,
|
|
||||||
'color': color,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
String getId(){
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setId(String id) {
|
|
||||||
id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTitle(String title) {
|
|
||||||
title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getCreationDate() {
|
|
||||||
return creationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCreationDate(String creationDate) {
|
|
||||||
creationDate = creationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getLastModificationDate() {
|
|
||||||
return lastModificationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLastModificationDate(String lastModificationDate) {
|
|
||||||
lastModificationDate = lastModificationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getExpirationDate() {
|
|
||||||
return expirationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setExpirationDate(String expirationDate) {
|
|
||||||
expirationDate = expirationDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getArrayPromemoria() {
|
|
||||||
return arrayPromemoria;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setArrayPromemoria(String arrayPromemoria) {
|
|
||||||
arrayPromemoria = arrayPromemoria;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDescription(String description) {
|
|
||||||
description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
Priority getPriority() {
|
|
||||||
return priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPriority(Priority priority) {
|
|
||||||
priority = priority;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import 'navigation.dart';
|
|||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({ Key? key }) : super(key: key);
|
const MyApp({ Key? key }) : super(key: key);
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class _NavigationState extends State<Navigation> {
|
|||||||
],
|
],
|
||||||
currentIndex: _selectedIndex,
|
currentIndex: _selectedIndex,
|
||||||
onTap: _onItemTapped,
|
onTap: _onItemTapped,
|
||||||
|
type: BottomNavigationBarType.fixed,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user