Added Firebase
This commit is contained in:
@@ -2,6 +2,7 @@ plugins {
|
||||
id "com.android.application"
|
||||
id "kotlin-android"
|
||||
id "dev.flutter.flutter-gradle-plugin"
|
||||
id 'com.google.gms.google-services'
|
||||
}
|
||||
|
||||
def localProperties = new Properties()
|
||||
@@ -64,4 +65,7 @@ flutter {
|
||||
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 'myApp.dart';
|
||||
|
||||
void main() {
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp();
|
||||
runApp(MyApp());
|
||||
print("App started");
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ 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 {
|
||||
@@ -21,51 +21,68 @@ class Note extends BaseEntity {
|
||||
};
|
||||
}
|
||||
|
||||
Note(
|
||||
this.id,
|
||||
this.title,
|
||||
this.creationDate,
|
||||
this.lastModificationDate,
|
||||
this.arrayPromemoria,
|
||||
this.description,
|
||||
);
|
||||
|
||||
String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void setId(String id) {
|
||||
id = id;
|
||||
void setId(String id1) {
|
||||
id = id1;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
title = title;
|
||||
void setTitle(String title1) {
|
||||
title = title1;
|
||||
}
|
||||
|
||||
String getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
void setCreationDate(String creationDate) {
|
||||
creationDate = creationDate;
|
||||
void setCreationDate(String creationDate1) {
|
||||
creationDate = creationDate1;
|
||||
}
|
||||
|
||||
String getLastModificationDate() {
|
||||
return lastModificationDate;
|
||||
}
|
||||
|
||||
void setLastModificationDate(String lastModificationDate) {
|
||||
lastModificationDate = lastModificationDate;
|
||||
void setLastModificationDate(String lastModificationDate1) {
|
||||
lastModificationDate = lastModificationDate1;
|
||||
}
|
||||
|
||||
String getArrayPromemoria() {
|
||||
return arrayPromemoria;
|
||||
}
|
||||
|
||||
void setArrayPromemoria(String arrayPromemoria) {
|
||||
arrayPromemoria = arrayPromemoria;
|
||||
void setArrayPromemoria(String arrayPromemoria1) {
|
||||
arrayPromemoria = arrayPromemoria1;
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
void setDescription(String description) {
|
||||
description = description;
|
||||
void setDescription(String description1) {
|
||||
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';
|
||||
|
||||
class Promemoria extends BaseEntity {
|
||||
static String id = BaseEntity.getId;
|
||||
static String title = BaseEntity.getTitle;
|
||||
static String creationDate = BaseEntity.getCreationDate;
|
||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||
static String expirationDate = '';
|
||||
static String arrayPromemoria = '';
|
||||
static String description = '';
|
||||
static Priority priority = Priority.none;
|
||||
static Color color = Color.none;
|
||||
class Promemoria {
|
||||
String id = '';
|
||||
String title;
|
||||
String creationDate;
|
||||
String lastModificationDate;
|
||||
String expirationDate;
|
||||
String arrayPromemoria;
|
||||
String description;
|
||||
String priority;
|
||||
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() {
|
||||
return {
|
||||
@@ -29,69 +50,92 @@ class Promemoria extends BaseEntity {
|
||||
};
|
||||
}
|
||||
|
||||
String getId(){
|
||||
String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void setId(String id) {
|
||||
id = id;
|
||||
void setId(String id1) {
|
||||
id = id1;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
title = title;
|
||||
void setTitle(String title1) {
|
||||
title = title1;
|
||||
}
|
||||
|
||||
String getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
void setCreationDate(String creationDate) {
|
||||
creationDate = creationDate;
|
||||
void setCreationDate(String creationDate1) {
|
||||
creationDate = creationDate1;
|
||||
}
|
||||
|
||||
String getLastModificationDate() {
|
||||
return lastModificationDate;
|
||||
}
|
||||
|
||||
void setLastModificationDate(String lastModificationDate) {
|
||||
lastModificationDate = lastModificationDate;
|
||||
void setLastModificationDate(String lastModificationDate1) {
|
||||
lastModificationDate = lastModificationDate1;
|
||||
}
|
||||
|
||||
String getExpirationDate() {
|
||||
return expirationDate;
|
||||
}
|
||||
|
||||
void setExpirationDate(String expirationDate) {
|
||||
expirationDate = expirationDate;
|
||||
void setExpirationDate(String expirationDate1) {
|
||||
expirationDate = expirationDate1;
|
||||
}
|
||||
|
||||
String getArrayPromemoria() {
|
||||
return arrayPromemoria;
|
||||
}
|
||||
|
||||
void setArrayPromemoria(String arrayPromemoria) {
|
||||
arrayPromemoria = arrayPromemoria;
|
||||
void setArrayPromemoria(String arrayPromemoria1) {
|
||||
arrayPromemoria = arrayPromemoria1;
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
void setDescription(String description) {
|
||||
description = description;
|
||||
void setDescription(String description1) {
|
||||
description = description1;
|
||||
}
|
||||
|
||||
Priority getPriority() {
|
||||
String getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
void setPriority(Priority priority) {
|
||||
priority = 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'],
|
||||
data['title'],
|
||||
data['creationDate'],
|
||||
data['lastModificationDate'],
|
||||
data['expirationDate'],
|
||||
data['arrayPromemoria'],
|
||||
data['description'],
|
||||
data['priority'],
|
||||
data['color']);
|
||||
|
||||
print(promemoria.getId().toString());
|
||||
|
||||
return promemoria;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ dependencies:
|
||||
sqflite: ^2.3.0
|
||||
path: ^1.8.3
|
||||
sqflite_common_ffi: ^2.3.0+2
|
||||
cloud_firestore: ^4.9.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user