Added Firebase
This commit is contained in:
@@ -2,6 +2,7 @@ plugins {
|
|||||||
id "com.android.application"
|
id "com.android.application"
|
||||||
id "kotlin-android"
|
id "kotlin-android"
|
||||||
id "dev.flutter.flutter-gradle-plugin"
|
id "dev.flutter.flutter-gradle-plugin"
|
||||||
|
id 'com.google.gms.google-services'
|
||||||
}
|
}
|
||||||
|
|
||||||
def localProperties = new Properties()
|
def localProperties = new Properties()
|
||||||
@@ -64,4 +65,7 @@ flutter {
|
|||||||
source '../..'
|
source '../..'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {}
|
dependencies {
|
||||||
|
implementation platform('com.google.firebase:firebase-bom:32.3.1')
|
||||||
|
implementation 'com.google.firebase:firebase-analytics-ktx'
|
||||||
|
}
|
||||||
|
|||||||
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,7 +1,10 @@
|
|||||||
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter/material.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());
|
runApp(MyApp());
|
||||||
print("App started");
|
print("App started");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import 'base_entity.dart';
|
|||||||
|
|
||||||
const String noteTable = 'note';
|
const String noteTable = 'note';
|
||||||
|
|
||||||
class Note extends BaseEntity {
|
class Note{
|
||||||
static String id = BaseEntity.getId;
|
String id;
|
||||||
static String title = BaseEntity.getTitle;
|
String title;
|
||||||
static String creationDate = BaseEntity.getCreationDate;
|
String creationDate;
|
||||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
String lastModificationDate;
|
||||||
static String arrayPromemoria = '';
|
String arrayPromemoria;
|
||||||
static String description = '';
|
String description;
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
@@ -21,51 +21,68 @@ class Note extends BaseEntity {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Note(
|
||||||
|
this.id,
|
||||||
|
this.title,
|
||||||
|
this.creationDate,
|
||||||
|
this.lastModificationDate,
|
||||||
|
this.arrayPromemoria,
|
||||||
|
this.description,
|
||||||
|
);
|
||||||
|
|
||||||
String getId() {
|
String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setId(String id) {
|
void setId(String id1) {
|
||||||
id = id;
|
id = id1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTitle() {
|
String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTitle(String title) {
|
void setTitle(String title1) {
|
||||||
title = title;
|
title = title1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getCreationDate() {
|
String getCreationDate() {
|
||||||
return creationDate;
|
return creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCreationDate(String creationDate) {
|
void setCreationDate(String creationDate1) {
|
||||||
creationDate = creationDate;
|
creationDate = creationDate1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLastModificationDate() {
|
String getLastModificationDate() {
|
||||||
return lastModificationDate;
|
return lastModificationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLastModificationDate(String lastModificationDate) {
|
void setLastModificationDate(String lastModificationDate1) {
|
||||||
lastModificationDate = lastModificationDate;
|
lastModificationDate = lastModificationDate1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getArrayPromemoria() {
|
String getArrayPromemoria() {
|
||||||
return arrayPromemoria;
|
return arrayPromemoria;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setArrayPromemoria(String arrayPromemoria) {
|
void setArrayPromemoria(String arrayPromemoria1) {
|
||||||
arrayPromemoria = arrayPromemoria;
|
arrayPromemoria = arrayPromemoria1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDescription() {
|
String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDescription(String description) {
|
void setDescription(String description1) {
|
||||||
description = description;
|
description = description1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Note fromJson(Map<String, dynamic> data) => Note(
|
||||||
|
data['id'],
|
||||||
|
data['title'],
|
||||||
|
data['creationDate'],
|
||||||
|
data['lastModificationDate'],
|
||||||
|
data['arrayPromemoria'],
|
||||||
|
data['description']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,37 @@ import 'identifiers/enum/priority.dart';
|
|||||||
|
|
||||||
const String promemoriaTable = 'promemoria';
|
const String promemoriaTable = 'promemoria';
|
||||||
|
|
||||||
class Promemoria extends BaseEntity {
|
class Promemoria {
|
||||||
static String id = BaseEntity.getId;
|
String id = '';
|
||||||
static String title = BaseEntity.getTitle;
|
String title;
|
||||||
static String creationDate = BaseEntity.getCreationDate;
|
String creationDate;
|
||||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
String lastModificationDate;
|
||||||
static String expirationDate = '';
|
String expirationDate;
|
||||||
static String arrayPromemoria = '';
|
String arrayPromemoria;
|
||||||
static String description = '';
|
String description;
|
||||||
static Priority priority = Priority.none;
|
String priority;
|
||||||
static Color color = Color.none;
|
String color;
|
||||||
|
|
||||||
|
Promemoria(
|
||||||
|
this.id,
|
||||||
|
this.title,
|
||||||
|
this.creationDate,
|
||||||
|
this.lastModificationDate,
|
||||||
|
this.expirationDate,
|
||||||
|
this.arrayPromemoria,
|
||||||
|
this.description,
|
||||||
|
this.priority,
|
||||||
|
this.color);
|
||||||
|
|
||||||
|
Promemoria.newConstructor(
|
||||||
|
this.title,
|
||||||
|
this.creationDate,
|
||||||
|
this.lastModificationDate,
|
||||||
|
this.expirationDate,
|
||||||
|
this.arrayPromemoria,
|
||||||
|
this.description,
|
||||||
|
this.priority,
|
||||||
|
this.color);
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
@@ -33,65 +54,88 @@ class Promemoria extends BaseEntity {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setId(String id) {
|
void setId(String id1) {
|
||||||
id = id;
|
id = id1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTitle() {
|
String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTitle(String title) {
|
void setTitle(String title1) {
|
||||||
title = title;
|
title = title1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getCreationDate() {
|
String getCreationDate() {
|
||||||
return creationDate;
|
return creationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCreationDate(String creationDate) {
|
void setCreationDate(String creationDate1) {
|
||||||
creationDate = creationDate;
|
creationDate = creationDate1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getLastModificationDate() {
|
String getLastModificationDate() {
|
||||||
return lastModificationDate;
|
return lastModificationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLastModificationDate(String lastModificationDate) {
|
void setLastModificationDate(String lastModificationDate1) {
|
||||||
lastModificationDate = lastModificationDate;
|
lastModificationDate = lastModificationDate1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getExpirationDate() {
|
String getExpirationDate() {
|
||||||
return expirationDate;
|
return expirationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setExpirationDate(String expirationDate) {
|
void setExpirationDate(String expirationDate1) {
|
||||||
expirationDate = expirationDate;
|
expirationDate = expirationDate1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getArrayPromemoria() {
|
String getArrayPromemoria() {
|
||||||
return arrayPromemoria;
|
return arrayPromemoria;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setArrayPromemoria(String arrayPromemoria) {
|
void setArrayPromemoria(String arrayPromemoria1) {
|
||||||
arrayPromemoria = arrayPromemoria;
|
arrayPromemoria = arrayPromemoria1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getDescription() {
|
String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDescription(String description) {
|
void setDescription(String description1) {
|
||||||
description = description;
|
description = description1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Priority getPriority() {
|
String getPriority() {
|
||||||
return priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPriority(Priority priority) {
|
void setPriority(Priority priority1) {
|
||||||
priority = priority;
|
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'],
|
||||||
|
data['title'],
|
||||||
|
data['creationDate'],
|
||||||
|
data['lastModificationDate'],
|
||||||
|
data['expirationDate'],
|
||||||
|
data['arrayPromemoria'],
|
||||||
|
data['description'],
|
||||||
|
data['priority'],
|
||||||
|
data['color']);
|
||||||
|
|
||||||
|
print(promemoria.getId().toString());
|
||||||
|
|
||||||
|
return promemoria;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ dependencies:
|
|||||||
sqflite: ^2.3.0
|
sqflite: ^2.3.0
|
||||||
path: ^1.8.3
|
path: ^1.8.3
|
||||||
sqflite_common_ffi: ^2.3.0+2
|
sqflite_common_ffi: ^2.3.0+2
|
||||||
|
cloud_firestore: ^4.9.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user