Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # lib/database/database.dart # lib/main.dart # lib/model/note.dart # lib/model/promemoria.dart # lib/navigation.dart
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../pages/EditReminder.dart';
|
||||
|
||||
class EditReminderButton extends StatelessWidget{
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => EditReminder()),
|
||||
);
|
||||
},
|
||||
child: Icon(Icons.list),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:progetto_m335_flutter/database/database.dart';
|
||||
import '../model/promemoria.dart';
|
||||
import '../navigation.dart';
|
||||
|
||||
class QuickReminder extends StatefulWidget {
|
||||
const QuickReminder({super.key});
|
||||
@@ -8,18 +11,35 @@ class QuickReminder extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _QuickReminderState extends State<QuickReminder> {
|
||||
NoteDatabase noteDatabase = NoteDatabase.instance;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const ListTile(
|
||||
leading: Checkbox(
|
||||
return ListTile(
|
||||
leading: const Checkbox(
|
||||
value: false,
|
||||
onChanged: null,
|
||||
),
|
||||
title: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'New Reminder',
|
||||
),
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'New Reminder',
|
||||
),
|
||||
onSubmitted: (String value) async{
|
||||
final db = await noteDatabase.database;
|
||||
noteDatabase.addPromemoria(Promemoria.today(
|
||||
value,
|
||||
DateTime.now().toString(),
|
||||
DateTime.now().toString(),
|
||||
DateTime.now().toString(),
|
||||
"description"));
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
PageRouteBuilder(pageBuilder: (context, animation1, animation2) {
|
||||
return Navigation();
|
||||
},
|
||||
transitionDuration: const Duration(seconds: 0)),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../Components/EditReminderButton.dart';
|
||||
import '../model/promemoria.dart';
|
||||
import '../pages/EditReminder.dart';
|
||||
|
||||
@@ -30,12 +29,12 @@ class _ReminderState extends State<Reminder> {
|
||||
value: _value,
|
||||
onChanged: _onChanged,
|
||||
),
|
||||
title: Text(widget.promemoria?.description ?? 'Nessun titolo'),
|
||||
subtitle: Text(DateTime.now().toString()),
|
||||
title: Text(widget.promemoria?.getTitle() ?? 'Nessun titolo'),
|
||||
subtitle: Text(widget.promemoria!.getExpirationDate().toString()),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => EditReminder()),
|
||||
MaterialPageRoute(builder: (context) => EditReminder(widget.promemoria)),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
167
lib/database/FireDb.dart
Normal file
167
lib/database/FireDb.dart
Normal file
@@ -0,0 +1,167 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:progetto_m335_flutter/model/promemoria.dart';
|
||||
import 'package:progetto_m335_flutter/model/note.dart';
|
||||
|
||||
class FireDb {
|
||||
|
||||
Future createPromemoria(Promemoria promemoria) async {
|
||||
final docPromemoria =
|
||||
FirebaseFirestore.instance.collection('promemoria').doc();
|
||||
|
||||
final json = {
|
||||
'id': docPromemoria.id,
|
||||
'title': promemoria.getTitle(),
|
||||
'creationDate': promemoria.getCreationDate(),
|
||||
'lastModificationDate': promemoria.getLastModificationDate(),
|
||||
'expirationDate': promemoria.getExpirationDate(),
|
||||
'arrayPromemoria': promemoria.getArrayPromemoria(),
|
||||
'description': promemoria.getDescription(),
|
||||
'priority': promemoria.getPriority(),
|
||||
'color': promemoria.getColor(),
|
||||
};
|
||||
|
||||
await docPromemoria.set(json);
|
||||
}
|
||||
|
||||
Future createAllPromemoria(List<Promemoria> promemorias) async {
|
||||
for (var promemoria in promemorias) {
|
||||
await createPromemoria(promemoria);
|
||||
}
|
||||
}
|
||||
|
||||
Future createNote(Note note) async {
|
||||
final docNote = FirebaseFirestore.instance.collection('note').doc();
|
||||
|
||||
final json = {
|
||||
'id': docNote.id,
|
||||
'title': note.getTitle(),
|
||||
'creationDate': note.getCreationDate(),
|
||||
'lastModificationDate': note.getLastModificationDate(),
|
||||
'arrayPromemoria': note.getArrayPromemoria(),
|
||||
'description': note.getDescription(),
|
||||
};
|
||||
|
||||
await docNote.set(json);
|
||||
}
|
||||
|
||||
Future createAllNotes(List<Note> notes) async {
|
||||
for (var note in notes) {
|
||||
await createNote(note);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Promemoria>> readAllPromemoria() async {
|
||||
var promemorias =
|
||||
await FirebaseFirestore.instance.collection('promemoria').get();
|
||||
|
||||
List<Promemoria> promemoriaList = [];
|
||||
|
||||
for (var promemoria in promemorias.docs) {
|
||||
promemoriaList.add(Promemoria.fromJson(promemoria.data()));
|
||||
}
|
||||
|
||||
return promemoriaList;
|
||||
}
|
||||
|
||||
Future<List<Note>> readAllNotes() async {
|
||||
var notes = await FirebaseFirestore.instance.collection('note').get();
|
||||
|
||||
List<Note> noteList = [];
|
||||
|
||||
for (var note in notes.docs) {
|
||||
noteList.add(Note.fromJson(note.data()));
|
||||
}
|
||||
|
||||
return noteList;
|
||||
}
|
||||
|
||||
Future<Note?> readNoteById(String id) async {
|
||||
var docNote = await FirebaseFirestore.instance.collection('note').doc(id);
|
||||
final snapshot = await docNote.get();
|
||||
|
||||
if (snapshot.exists) {
|
||||
return Note.fromJson(snapshot.data()!);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Promemoria?> readPromemoriaById(String id) async {
|
||||
final docPromemoria =
|
||||
await FirebaseFirestore.instance.collection('promemoria').doc(id);
|
||||
final snapshot = await docPromemoria.get();
|
||||
|
||||
if (snapshot.exists) {
|
||||
return Promemoria.fromJson(snapshot.data()!);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Future updateNote(Note note) async {
|
||||
final docNote = FirebaseFirestore.instance.collection('note').doc(note.getId());
|
||||
|
||||
final json = {
|
||||
'id': note.getId(),
|
||||
'title': note.getTitle(),
|
||||
'creationDate': note.getCreationDate(),
|
||||
'lastModificationDate': note.getLastModificationDate(),
|
||||
'arrayPromemoria': note.getArrayPromemoria(),
|
||||
'description': note.getDescription(),
|
||||
};
|
||||
|
||||
await docNote.update(json);
|
||||
}
|
||||
|
||||
Future updatePromemoria(Promemoria promemoria) async {
|
||||
final docPromemoria = FirebaseFirestore.instance.collection('promemoria').doc(promemoria.getId());
|
||||
|
||||
final json = {
|
||||
'id': docPromemoria.id,
|
||||
'title': promemoria.getTitle(),
|
||||
'creationDate': promemoria.getCreationDate(),
|
||||
'lastModificationDate': promemoria.getLastModificationDate(),
|
||||
'expirationDate': promemoria.getExpirationDate(),
|
||||
'arrayPromemoria': promemoria.getArrayPromemoria(),
|
||||
'description': promemoria.getDescription(),
|
||||
'priority': promemoria.getPriority(),
|
||||
'color': promemoria.getColor(),
|
||||
};
|
||||
|
||||
await docPromemoria.update(json);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
Future deleteNoteById(String id) async {
|
||||
final docNote = FirebaseFirestore.instance.collection('note').doc(id);
|
||||
|
||||
await docNote.delete();
|
||||
}
|
||||
|
||||
Future deletePromemoriaById(String id) async {
|
||||
final docPromemoria = FirebaseFirestore.instance.collection('promemoria').doc(id);
|
||||
|
||||
await docPromemoria.delete();
|
||||
}
|
||||
|
||||
Future deleteAllNotes() async {
|
||||
var notes = await FirebaseFirestore.instance.collection('note').get();
|
||||
|
||||
for (var note in notes.docs) {
|
||||
await deleteNoteById(note.id);
|
||||
}
|
||||
}
|
||||
|
||||
Future deleteAllPromemoria() async {
|
||||
var promemorias = await FirebaseFirestore.instance.collection('promemoria').get();
|
||||
|
||||
for (var promemoria in promemorias.docs) {
|
||||
await deletePromemoriaById(promemoria.id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
import 'package:path/path.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
// Models
|
||||
import 'package:progetto_m335_flutter/model/note.dart';
|
||||
import '../model/note.dart';
|
||||
import 'FireDb.dart';
|
||||
import 'package:progetto_m335_flutter/model/promemoria.dart';
|
||||
|
||||
class NoteDatabase {
|
||||
static final NoteDatabase instance = NoteDatabase._init();
|
||||
static Database? _database;
|
||||
|
||||
// Zero args constructor needed to extend this class
|
||||
NoteDatabase();
|
||||
FireDb fireDb = FireDb();
|
||||
|
||||
NoteDatabase._init();
|
||||
|
||||
@@ -22,141 +19,38 @@ class NoteDatabase {
|
||||
}
|
||||
|
||||
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();
|
||||
// Directory databasePath = await getApplicationDocumentsDirectory();
|
||||
|
||||
final path = join(databasePath, filePath);
|
||||
return await openDatabase(path, version: 1, onCreate: _createDB);
|
||||
}
|
||||
|
||||
Future _createDB(Database database, int version) async {
|
||||
//check if the database is created
|
||||
if (database.query(noteTable) != null) {
|
||||
print("Database already created");
|
||||
|
||||
}else{
|
||||
print("demo data inserting");
|
||||
await database.execute('''CREATE TABLE promemoria (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
creationDate TEXT NOT NULL,
|
||||
lastModificationDate TEXT,
|
||||
expirationDate TEXT,
|
||||
description TEXT,
|
||||
priority TEXT,
|
||||
color TEXT
|
||||
);
|
||||
await database.execute('''CREATE TABLE promemoria (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
creationDate TEXT NOT NULL,
|
||||
lastModificationDate TEXT,
|
||||
expirationDate TEXT,
|
||||
arrayPromemoria TEXT,
|
||||
description TEXT,
|
||||
priority TEXT,
|
||||
color TEXT
|
||||
);
|
||||
''');
|
||||
|
||||
await database.execute('''CREATE TABLE note (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
creationDate TEXT NOT NULL,
|
||||
lastModificationDate TEXT,
|
||||
description TEXT
|
||||
);
|
||||
await database.execute('''CREATE TABLE note (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
creationDate TEXT NOT NULL,
|
||||
lastModificationDate TEXT,
|
||||
arrayPromemoria TEXT,
|
||||
description TEXT
|
||||
);
|
||||
''');
|
||||
|
||||
print("database created");
|
||||
}
|
||||
|
||||
|
||||
await fillDemoData(database, version);
|
||||
}
|
||||
|
||||
Future fillDemoData(Database database, int version) async {
|
||||
|
||||
print("boh speriamo funzioni");
|
||||
// Add some fake accounts
|
||||
|
||||
|
||||
// Add fake categories
|
||||
await database.execute('''
|
||||
INSERT INTO note (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
description
|
||||
) VALUES (
|
||||
'Nota 2',
|
||||
'2023-09-28',
|
||||
'2023-09-28',
|
||||
'Questo è un esempio di nota 2.'
|
||||
)
|
||||
''');
|
||||
|
||||
|
||||
await database.execute('''
|
||||
INSERT INTO note (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
description
|
||||
) VALUES (
|
||||
'Nota 2',
|
||||
'2023-09-28',
|
||||
'2023-09-28',
|
||||
'Questo è un esempio di nota 2.'
|
||||
)
|
||||
''');
|
||||
|
||||
// Add currencies
|
||||
await database.execute('''
|
||||
INSERT INTO promemoria (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
expirationDate,
|
||||
description,
|
||||
priority,
|
||||
color
|
||||
) VALUES (
|
||||
'Promemoria 1',
|
||||
'2023-09-27',
|
||||
'2023-09-27',
|
||||
'2023-10-05',
|
||||
'Questo è un esempio di promemoria 1.',
|
||||
'Alta',
|
||||
'Rosso'
|
||||
)
|
||||
''');
|
||||
|
||||
// Add fake budgets
|
||||
await database.execute('''
|
||||
INSERT INTO promemoria (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
expirationDate,
|
||||
description,
|
||||
priority,
|
||||
color
|
||||
) VALUES (
|
||||
'Promemoria 2',
|
||||
'2023-09-28',
|
||||
'2023-09-28',
|
||||
'2023-10-10',
|
||||
'Questo è un esempio di promemoria 2.',
|
||||
'Media',
|
||||
'Verde'
|
||||
)
|
||||
''');
|
||||
print("Demo data inserted");
|
||||
}
|
||||
|
||||
Future clearDatabase() async {
|
||||
try {
|
||||
await _database?.transaction((txn) async {
|
||||
var batch = txn.batch();
|
||||
batch.delete(noteTable);
|
||||
batch.delete(promemoriaTable);
|
||||
await batch.commit();
|
||||
});
|
||||
} catch (error) {
|
||||
throw Exception('DbBase.cleanDatabase: $error');
|
||||
}
|
||||
print("database created");
|
||||
getDataFromFirebase(database, version);
|
||||
}
|
||||
|
||||
Future<List<Map>> selectAllPromemoria() async {
|
||||
@@ -167,15 +61,124 @@ class NoteDatabase {
|
||||
return maps;
|
||||
}
|
||||
|
||||
Future close() async {
|
||||
final database = await instance.database;
|
||||
database.close();
|
||||
Future<List<Note>> getAllNote() async {
|
||||
var notes = await _database?.query(noteTable);
|
||||
|
||||
if(notes == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
List<Note> noteList = notes.map((e) => Note.fromJson(e)).toList();
|
||||
return noteList;
|
||||
}
|
||||
|
||||
// WARNING: FOR DEV/TEST PURPOSES ONLY!!
|
||||
Future<void> deleteDatabase() async {
|
||||
final databasePath = await getDatabasesPath();
|
||||
final path = join(databasePath, 'note.db');
|
||||
databaseFactory.deleteDatabase(path);
|
||||
Future<List<Promemoria>> getAllPromemoria() async {
|
||||
var promemorias = await _database?.query(promemoriaTable);
|
||||
|
||||
if(promemorias == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
List<Promemoria> promemoriaList =
|
||||
promemorias.map((e) => Promemoria.fromJson(e)).toList();
|
||||
|
||||
|
||||
return promemoriaList;
|
||||
}
|
||||
|
||||
Future<Note> getNoteById(int id) async {
|
||||
var note = await _database?.query(noteTable, where: 'id = ?', whereArgs: [id]);
|
||||
return Note.fromJson(note!.first);
|
||||
}
|
||||
|
||||
Future<Promemoria> getPromemoriaById(int id) async {
|
||||
var promemoria =
|
||||
await _database?.query(promemoriaTable, where: 'id = ?', whereArgs: [id]);
|
||||
return Promemoria.fromJson(promemoria!.first);
|
||||
}
|
||||
|
||||
//add note
|
||||
void addNote(Note note) async {
|
||||
await _database?.execute('''
|
||||
INSERT INTO note (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
arrayPromemoria,
|
||||
description
|
||||
) VALUES (
|
||||
'${note.title}',
|
||||
'${note.creationDate}',
|
||||
'${note.lastModificationDate}',
|
||||
'${note.arrayPromemoria}',
|
||||
'${note.description}'
|
||||
)
|
||||
''');
|
||||
|
||||
syncData();
|
||||
}
|
||||
|
||||
//add Promemoria
|
||||
void addPromemoria(Promemoria promemoria) async {
|
||||
await _database?.execute('''
|
||||
INSERT INTO promemoria (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
expirationDate,
|
||||
arrayPromemoria,
|
||||
description,
|
||||
priority,
|
||||
color
|
||||
) VALUES (
|
||||
'${promemoria.title}',
|
||||
'${promemoria.creationDate}',
|
||||
'${promemoria.lastModificationDate}',
|
||||
'${promemoria.expirationDate}',
|
||||
'${promemoria.arrayPromemoria}',
|
||||
'${promemoria.description}',
|
||||
'${promemoria.priority}',
|
||||
'${promemoria.color}'
|
||||
)
|
||||
''');
|
||||
|
||||
syncData();
|
||||
}
|
||||
|
||||
void deleteAll() async {
|
||||
await _database?.execute('''
|
||||
DELETE FROM promemoria
|
||||
''');
|
||||
|
||||
await _database?.execute('''
|
||||
DELETE FROM note
|
||||
''');
|
||||
}
|
||||
|
||||
|
||||
void getDataFromFirebase(Database database, int version) async {
|
||||
this.deleteAll();
|
||||
|
||||
var promemorias = await fireDb.readAllPromemoria();
|
||||
var notes = await fireDb.readAllNotes();
|
||||
|
||||
for (var promemoria in promemorias) {
|
||||
this.addPromemoria(promemoria);
|
||||
}
|
||||
|
||||
for (var note in notes) {
|
||||
this.addNote(note);
|
||||
}
|
||||
}
|
||||
|
||||
void syncData() async {
|
||||
var promemorias = await getAllPromemoria();
|
||||
var notes = await getAllNote();
|
||||
|
||||
await fireDb.deleteAllPromemoria();
|
||||
await fireDb.deleteAllNotes();
|
||||
|
||||
await fireDb.createAllPromemoria(promemorias);
|
||||
await fireDb.createAllNotes(notes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../myApp.dart';
|
||||
import 'myApp.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
runApp(MyApp());
|
||||
}
|
||||
print("App started");
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
abstract class BaseEntity{
|
||||
static String id = 'id';
|
||||
static String title = 'Title';
|
||||
static String creationDate = 'CreationDate';
|
||||
static String lastEditDate = 'LastEditDate';
|
||||
|
||||
static String get getId{
|
||||
return id;
|
||||
}
|
||||
static String get getTitle{
|
||||
return title;
|
||||
}
|
||||
static String get getCreationDate{
|
||||
return creationDate;
|
||||
}
|
||||
static String get getLastEditDate{
|
||||
return lastEditDate;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,96 @@
|
||||
import 'base_entity.dart';
|
||||
|
||||
|
||||
const String noteTable = 'note';
|
||||
|
||||
class Note extends BaseEntity {
|
||||
static String id = BaseEntity.getId;
|
||||
static String title = BaseEntity.getTitle;
|
||||
static String creationDate = BaseEntity.getCreationDate;
|
||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||
static String arrayPromemoria = '';
|
||||
static String description = '';
|
||||
class Note{
|
||||
String id='';
|
||||
String title;
|
||||
String creationDate;
|
||||
String lastModificationDate;
|
||||
String? arrayPromemoria;
|
||||
String description;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'creationDate': creationDate,
|
||||
'lastModificationDate': lastModificationDate,
|
||||
'arrayPromemoria': arrayPromemoria,
|
||||
'description': description
|
||||
};
|
||||
}
|
||||
|
||||
Note(
|
||||
this.id,
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.arrayPromemoria,
|
||||
this.description,
|
||||
);
|
||||
|
||||
Note.newConstructor(
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.arrayPromemoria,
|
||||
this.description,
|
||||
);
|
||||
|
||||
String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void setId(String id1) {
|
||||
id = id1;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void setTitle(String title1) {
|
||||
title = title1;
|
||||
}
|
||||
|
||||
String getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
void setCreationDate(String creationDate1) {
|
||||
creationDate = creationDate1;
|
||||
}
|
||||
|
||||
String getLastModificationDate() {
|
||||
return lastModificationDate;
|
||||
}
|
||||
|
||||
void setLastModificationDate(String lastModificationDate1) {
|
||||
lastModificationDate = lastModificationDate1;
|
||||
}
|
||||
|
||||
String? getArrayPromemoria() {
|
||||
return arrayPromemoria;
|
||||
}
|
||||
|
||||
void setArrayPromemoria(String arrayPromemoria1) {
|
||||
arrayPromemoria = arrayPromemoria1;
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
void setDescription(String description1) {
|
||||
description = description1;
|
||||
}
|
||||
|
||||
static Note fromJson(Map<String, dynamic> data) => Note(
|
||||
data['id'].toString(),
|
||||
data['title'],
|
||||
data['creationDate'],
|
||||
data['lastModificationDate'],
|
||||
data['arrayPromemoria'],
|
||||
data['description']);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,156 @@
|
||||
import 'base_entity.dart';
|
||||
import 'identifiers/enum/color.dart';
|
||||
import 'identifiers/enum/priority.dart';
|
||||
|
||||
const String promemoriaTable = 'promemoria';
|
||||
|
||||
class Promemoria extends BaseEntity {
|
||||
static String expirationDate = '';
|
||||
static String arrayPromemoria = '';
|
||||
class Promemoria {
|
||||
String id = '';
|
||||
String title = '';
|
||||
String creationDate = '';
|
||||
String lastModificationDate = '';
|
||||
String expirationDate = '';
|
||||
String? arrayPromemoria = '';
|
||||
String description = '';
|
||||
static Priority priority = Priority.none;
|
||||
String priority = '';
|
||||
String color = '';
|
||||
|
||||
static Color color = Color.none;
|
||||
Promemoria(
|
||||
this.id,
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.expirationDate,
|
||||
this.arrayPromemoria,
|
||||
this.description,
|
||||
this.priority,
|
||||
this.color);
|
||||
|
||||
Promemoria(String description){
|
||||
this.description = description;
|
||||
Promemoria.newConstructor(
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.expirationDate,
|
||||
this.arrayPromemoria,
|
||||
this.description,
|
||||
this.priority,
|
||||
this.color
|
||||
);
|
||||
|
||||
Promemoria.today(
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.expirationDate,
|
||||
this.description,
|
||||
);
|
||||
|
||||
Promemoria.inbox(
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.description,
|
||||
);
|
||||
|
||||
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 id1) {
|
||||
id = id1;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void setTitle(String title1) {
|
||||
title = title1;
|
||||
}
|
||||
|
||||
String getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
void setCreationDate(String creationDate1) {
|
||||
creationDate = creationDate1;
|
||||
}
|
||||
|
||||
String getLastModificationDate() {
|
||||
return lastModificationDate;
|
||||
}
|
||||
|
||||
void setLastModificationDate(String lastModificationDate1) {
|
||||
lastModificationDate = lastModificationDate1;
|
||||
}
|
||||
|
||||
String getExpirationDate() {
|
||||
return expirationDate;
|
||||
}
|
||||
|
||||
void setExpirationDate(String expirationDate1) {
|
||||
expirationDate = expirationDate1;
|
||||
}
|
||||
|
||||
String? getArrayPromemoria() {
|
||||
return arrayPromemoria;
|
||||
}
|
||||
|
||||
void setArrayPromemoria(String arrayPromemoria1) {
|
||||
arrayPromemoria = arrayPromemoria1;
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
void setDescription(String description1) {
|
||||
description = description1;
|
||||
}
|
||||
|
||||
String getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
void setPriority(Priority priority1) {
|
||||
priority = priority1.toString();
|
||||
}
|
||||
|
||||
String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
void setColor(Color color1) {
|
||||
color = color1.toString();
|
||||
}
|
||||
|
||||
static Promemoria fromJson(Map<String, dynamic> data) {
|
||||
Promemoria promemoria = Promemoria(
|
||||
data['id'].toString(),
|
||||
data['title'],
|
||||
data['creationDate'],
|
||||
data['lastModificationDate'],
|
||||
data['expirationDate'],
|
||||
data['arrayPromemoria'],
|
||||
data['description'],
|
||||
data['priority'],
|
||||
data['color']);
|
||||
|
||||
print(promemoria.getId().toString());
|
||||
|
||||
return promemoria;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'navigation.dart';
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({ Key? key }) : super(key: key);
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'pages/testUI.dart';
|
||||
import 'pages/TodayView.dart';
|
||||
import 'pages/InboxView.dart';
|
||||
import 'pages/NotesView.dart';
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:progetto_m335_flutter/model/promemoria.dart';
|
||||
|
||||
class EditReminder extends StatefulWidget {
|
||||
const EditReminder({super.key});
|
||||
final Promemoria? promemoria;
|
||||
const EditReminder(this.promemoria, {super.key});
|
||||
|
||||
@override
|
||||
State<EditReminder> createState() => _EditReminderState();
|
||||
}
|
||||
|
||||
class _EditReminderState extends State<EditReminder> {
|
||||
String _title = "ciaciao";
|
||||
String _description = "description";
|
||||
final String _title = "ciaciao";
|
||||
String _description = "";
|
||||
DateTime? _date;
|
||||
|
||||
//Arraylist of promemoria
|
||||
|
||||
bool _hasDate = true;
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
_description = widget.promemoria?.description ?? "";
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -27,16 +33,23 @@ class _EditReminderState extends State<EditReminder> {
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
controller: TextEditingController(text: _title),
|
||||
TextFormField(
|
||||
initialValue: widget.promemoria?.title ?? "",
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Title',
|
||||
),
|
||||
onChanged: (text) {
|
||||
setState(() {
|
||||
widget.promemoria?.setTitle(text);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
TextFormField(
|
||||
initialValue: widget.promemoria?.description ?? "",
|
||||
onChanged: (text) {
|
||||
print(text);
|
||||
setState(() {
|
||||
_description = text;
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:progetto_m335_flutter/database/database.dart';
|
||||
|
||||
//import components
|
||||
import '../Components/Reminder.dart';
|
||||
@@ -16,13 +17,29 @@ class _TodayViewState extends State<TodayView> {
|
||||
|
||||
var _selectedDate = DateTime.now();
|
||||
|
||||
List<Promemoria> listaPromemoria = [
|
||||
new Promemoria("Primo promemoria"),
|
||||
new Promemoria("Secondo promemoria"),
|
||||
new Promemoria("Terzo promemoria"),
|
||||
];
|
||||
List<Promemoria> listaPromemoria = [];
|
||||
|
||||
NoteDatabase noteDatabase = NoteDatabase.instance;
|
||||
|
||||
/*[
|
||||
Promemoria.today("Primo promemoria", DateTime.now().toString(), DateTime.now().toString(), DateTime.now().toString(), "Descrizione primo promemoria"),
|
||||
Promemoria.today("Secondo promemoria", DateTime.now().toString(), DateTime.now().toString(), DateTime.now().toString(), "Descrizione secondo promemoria"),
|
||||
];*/
|
||||
|
||||
getAllPromemoria() async {
|
||||
final db = await noteDatabase.database;
|
||||
List<Promemoria> temp = await noteDatabase.getAllPromemoria() as List<Promemoria>;
|
||||
setState(() {
|
||||
listaPromemoria = temp;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
getAllPromemoria();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -30,30 +47,31 @@ class _TodayViewState extends State<TodayView> {
|
||||
appBar: AppBar(
|
||||
title: FilledButton(
|
||||
onPressed: () async {
|
||||
DateTime? newDate = await showDatePicker(context: context, initialDate: DateTime.now(), firstDate: DateTime(1), lastDate: DateTime(9999));
|
||||
DateTime? newDate = await showDatePicker(context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime(1),
|
||||
lastDate: DateTime(9999));
|
||||
if (newDate != null) {
|
||||
setState(() {
|
||||
_selectedDate = newDate;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text(_selectedDate.day.toString() + "/" + _selectedDate.month.toString() + "/" + _selectedDate.year.toString())
|
||||
child: Text("${_selectedDate.day}/${_selectedDate.month}/${_selectedDate.year}")
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ListView.builder(
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: listaPromemoria.length,
|
||||
itemBuilder: (BuildContext context, int index){
|
||||
return Reminder(
|
||||
listaPromemoria[index]
|
||||
);
|
||||
},
|
||||
),
|
||||
QuickReminder(),
|
||||
],
|
||||
body:
|
||||
ListView.builder(
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: (listaPromemoria!.length + 1),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index == listaPromemoria.length) {
|
||||
return QuickReminder();
|
||||
} else {
|
||||
return Reminder(listaPromemoria[index]);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:progetto_m335_flutter/database/database.dart';
|
||||
import 'package:progetto_m335_flutter/model/note.dart';
|
||||
import 'package:progetto_m335_flutter/model/promemoria.dart';
|
||||
|
||||
import '../database/database.dart';
|
||||
|
||||
@@ -22,11 +23,43 @@ class _TestState extends State<Test> {
|
||||
}
|
||||
|
||||
Future<void> _printdata() async {
|
||||
|
||||
|
||||
var nota = Note.newConstructor(
|
||||
"nota 5",
|
||||
"2023-09-56",
|
||||
"2028-03-1",
|
||||
"1,2,3,4,5",
|
||||
"Questo è un esempio di nota gesu benedetto 1.");
|
||||
|
||||
var promemoria = Promemoria.newConstructor(
|
||||
"promemoria 5",
|
||||
"2023-09-56",
|
||||
"2028-03-1",
|
||||
"2028-03-1",
|
||||
"1,2,3,4,5",
|
||||
"Questo è un esempio di promemoria gesu benedetto 1.",
|
||||
"alta",
|
||||
"rosso");
|
||||
|
||||
noteDatabase.addNote(nota);
|
||||
noteDatabase.addPromemoria(promemoria);
|
||||
|
||||
final db = await noteDatabase.database;
|
||||
|
||||
print("Printing data");
|
||||
print((await noteDatabase.getAllPromemoria()).first);
|
||||
print((await noteDatabase.getAllNote()).first);
|
||||
print("promemoria");
|
||||
print(await db.query(promemoriaTable));
|
||||
print("note");
|
||||
print(await db.query(noteTable));
|
||||
print("Data printed");
|
||||
|
||||
print("savedata from database to firebase");
|
||||
noteDatabase.syncData();
|
||||
print("data saved");
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user