Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd5803e6fe | |||
| 64b4f64f8c | |||
| 52d7defb75 | |||
| 782bbebce9 | |||
| 05386ac20f | |||
| 9f26bc8595 | |||
|
|
c35684c8f1 | ||
| 205f575db5 | |||
| ecf7011302 | |||
| 58e013a709 |
@@ -1,25 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class QuickReminder extends StatefulWidget {
|
||||
const QuickReminder({super.key});
|
||||
|
||||
@override
|
||||
State<QuickReminder> createState() => _QuickReminderState();
|
||||
}
|
||||
|
||||
class _QuickReminderState extends State<QuickReminder> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const ListTile(
|
||||
leading: Checkbox(
|
||||
value: false,
|
||||
onChanged: null,
|
||||
),
|
||||
title: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'New Reminder',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/promemoria.dart';
|
||||
import '../pages/EditReminder.dart';
|
||||
|
||||
class Reminder extends StatefulWidget {
|
||||
final Promemoria? promemoria;
|
||||
const Reminder(this.promemoria, {super.key});
|
||||
|
||||
@override
|
||||
State<Reminder> createState() => _ReminderState();
|
||||
}
|
||||
|
||||
class _ReminderState extends State<Reminder> {
|
||||
bool _value = false;
|
||||
|
||||
void _onChanged(bool? newValue) {
|
||||
setState(() {
|
||||
_value = newValue ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Checkbox(
|
||||
value: _value,
|
||||
onChanged: _onChanged,
|
||||
),
|
||||
title: Text(widget.promemoria?.description ?? 'Nessun titolo'),
|
||||
subtitle: Text(DateTime.now().toString()),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => EditReminder(widget.promemoria)),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +1,40 @@
|
||||
import 'package:path/path.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
// Models
|
||||
import 'package:progetto_m335_flutter/model/note.dart';
|
||||
import 'package:progetto_m335_flutter/model/promemoria.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
class NoteDatabase {
|
||||
static final NoteDatabase instance = NoteDatabase._init();
|
||||
static Database? _database;
|
||||
|
||||
// Zero args constructor needed to extend this class
|
||||
NoteDatabase();
|
||||
|
||||
NoteDatabase._init();
|
||||
|
||||
Future<Database> get database async {
|
||||
if (_database != null) return _database!;
|
||||
|
||||
_database = await _initDB('note.db');
|
||||
return _database!;
|
||||
}
|
||||
|
||||
Future<Database> _initDB(String filePath) async {
|
||||
// On Android, it is typically data/data//databases.
|
||||
// On iOS and MacOS, it is the Documents directory.
|
||||
print("Initializing database");
|
||||
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,
|
||||
arrayPromemoria TEXT,
|
||||
description TEXT,
|
||||
priority TEXT,
|
||||
color TEXT
|
||||
@@ -55,49 +46,45 @@ class NoteDatabase {
|
||||
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,
|
||||
arrayPromemoria,
|
||||
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,
|
||||
arrayPromemoria,
|
||||
description
|
||||
) VALUES (
|
||||
'Nota 2',
|
||||
'2023-09-28',
|
||||
'2023-09-28',
|
||||
'',
|
||||
'Questo è un esempio di nota 2.'
|
||||
)
|
||||
''');
|
||||
@@ -109,6 +96,7 @@ class NoteDatabase {
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
expirationDate,
|
||||
arrayPromemoria,
|
||||
description,
|
||||
priority,
|
||||
color
|
||||
@@ -117,6 +105,7 @@ class NoteDatabase {
|
||||
'2023-09-27',
|
||||
'2023-09-27',
|
||||
'2023-10-05',
|
||||
'',
|
||||
'Questo è un esempio di promemoria 1.',
|
||||
'Alta',
|
||||
'Rosso'
|
||||
@@ -130,6 +119,7 @@ class NoteDatabase {
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
expirationDate,
|
||||
arrayPromemoria,
|
||||
description,
|
||||
priority,
|
||||
color
|
||||
@@ -138,6 +128,7 @@ class NoteDatabase {
|
||||
'2023-09-28',
|
||||
'2023-09-28',
|
||||
'2023-10-10',
|
||||
'',
|
||||
'Questo è un esempio di promemoria 2.',
|
||||
'Media',
|
||||
'Verde'
|
||||
@@ -159,6 +150,42 @@ class NoteDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
Future close() async {
|
||||
final database = await instance.database;
|
||||
database.close();
|
||||
}
|
||||
|
||||
Future<void> deleteDatabase() async {
|
||||
try {
|
||||
final databasePath = await getDatabasesPath();
|
||||
final path = join(databasePath, 'note.db');
|
||||
databaseFactory.deleteDatabase(path);
|
||||
} catch (error) {
|
||||
throw Exception('DbBase.deleteDatabase: $error');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createNote(Database database, Note note) async {
|
||||
await database.execute('''
|
||||
INSERT INTO note (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
arrayPromemoria,
|
||||
description,
|
||||
|
||||
) VALUES (
|
||||
'$note.title}',
|
||||
'$note.creationDate',
|
||||
'$note.lastModificationDate',
|
||||
'$note.arrayPromemoria.toString()',
|
||||
'$note.description',
|
||||
)
|
||||
''');
|
||||
|
||||
print('note $note.title inserted');
|
||||
}
|
||||
|
||||
Future<List<Map>> selectAllPromemoria() async {
|
||||
final db = await database;
|
||||
|
||||
@@ -167,15 +194,61 @@ class NoteDatabase {
|
||||
return maps;
|
||||
}
|
||||
|
||||
Future close() async {
|
||||
final database = await instance.database;
|
||||
database.close();
|
||||
Future<List<Map>> selectAllNotes() async {
|
||||
final db = await database;
|
||||
|
||||
final List<Map<String, dynamic>> maps = await db.query(noteTable);
|
||||
|
||||
return maps;
|
||||
}
|
||||
|
||||
// WARNING: FOR DEV/TEST PURPOSES ONLY!!
|
||||
Future<void> deleteDatabase() async {
|
||||
final databasePath = await getDatabasesPath();
|
||||
final path = join(databasePath, 'note.db');
|
||||
databaseFactory.deleteDatabase(path);
|
||||
Future<void> createPromemoria(
|
||||
Database database, 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.toString()',
|
||||
'$promemoria.description',
|
||||
'$promemoria.priority',
|
||||
'$promemoria.color'
|
||||
)
|
||||
''');
|
||||
|
||||
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, where: 'id = ?',
|
||||
// Pass the Dog's id as a whereArg to prevent SQL injection.
|
||||
// whereArgs: [dog.id],)
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ import 'myApp.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
print("App started");
|
||||
}
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
abstract class BaseEntity{
|
||||
String id = 'id';
|
||||
String title = 'Title';
|
||||
String creationDate = 'CreationDate';
|
||||
String lastEditDate = 'LastEditDate';
|
||||
static String id = 'id';
|
||||
static String title = 'Title';
|
||||
static String creationDate = 'CreationDate';
|
||||
static String lastEditDate = 'LastEditDate';
|
||||
|
||||
BaseEntity();
|
||||
static String get getId{
|
||||
return id;
|
||||
}
|
||||
static String get getTitle{
|
||||
return title;
|
||||
}
|
||||
static String get getCreationDate{
|
||||
return creationDate;
|
||||
}
|
||||
static String get getLastEditDate{
|
||||
return lastEditDate;
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,14 @@ 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 = '';
|
||||
String description = '';
|
||||
static String description = '';
|
||||
static Priority priority = Priority.none;
|
||||
|
||||
static Color color = Color.none;
|
||||
|
||||
Promemoria(String description) : super(){
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,15 +4,14 @@ import 'navigation.dart';
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({ Key? key }) : super(key: key);
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'My App',
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorSchemeSeed: Colors.blue,
|
||||
|
||||
|
||||
primaryColor: Colors.red,
|
||||
),
|
||||
home: Navigation()
|
||||
);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'pages/testUI.dart';
|
||||
import 'pages/TodayView.dart';
|
||||
import 'pages/InboxView.dart';
|
||||
import 'pages/NotesView.dart';
|
||||
|
||||
import 'pages/test.dart';
|
||||
|
||||
class Navigation extends StatefulWidget {
|
||||
const Navigation({super.key});
|
||||
@@ -15,11 +16,12 @@ class Navigation extends StatefulWidget {
|
||||
|
||||
class _NavigationState extends State<Navigation> {
|
||||
|
||||
int _selectedIndex = 0;
|
||||
int _selectedIndex = 3;
|
||||
static const List<Widget> _widgetOptions = <Widget>[
|
||||
TodayView(),
|
||||
InboxView(),
|
||||
NotesView(),
|
||||
Test()
|
||||
];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
@@ -31,17 +33,20 @@ class _NavigationState extends State<Navigation> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SafeArea(child: _widgetOptions.elementAt(_selectedIndex)),
|
||||
appBar: AppBar(
|
||||
title: Text("BottomNavBar"),
|
||||
),
|
||||
body: Center(child: _widgetOptions.elementAt(_selectedIndex)),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: const <BottomNavigationBarItem>[
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.today), label: "today"),
|
||||
icon: Icon(Icons.calendar_today), label: "today"),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.inbox), label: "Inbox"),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.note), label: "Notes"),
|
||||
BottomNavigationBarItem(icon: Icon(Icons.settings), label: "Settings")
|
||||
],
|
||||
currentIndex: _selectedIndex,
|
||||
onTap: _onItemTapped,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../model/promemoria.dart';
|
||||
|
||||
class EditReminder extends StatefulWidget {
|
||||
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";
|
||||
DateTime? _date;
|
||||
|
||||
//Arraylist of promemoria
|
||||
|
||||
bool _hasDate = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Edit Reminder"),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
TextField(
|
||||
controller: TextEditingController(text: widget.promemoria?.description ?? ""),
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Title',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TextField(
|
||||
onChanged: (text) {
|
||||
setState(() {
|
||||
_description = text;
|
||||
});
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Description',
|
||||
),
|
||||
maxLines: 6,
|
||||
keyboardType: TextInputType.multiline,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
DateTime? newDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime(1),
|
||||
lastDate: DateTime(9999));
|
||||
if (newDate != null) {
|
||||
setState(() {
|
||||
_date = newDate;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Row(children: [
|
||||
if (_date != null) Text("${_date?.day}/${_date?.month}/${_date?.year}"),
|
||||
//if (_date == null) Text("Add Date"),
|
||||
if (_date != null) const SizedBox(width: 10),
|
||||
const Icon(Icons.calendar_month)
|
||||
])),
|
||||
if (_date != null) IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_date = null;
|
||||
});
|
||||
print("setting _date to ${_date}");
|
||||
},
|
||||
icon: Icon(Icons.close)),
|
||||
if (_date == null) TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_date = DateTime.now();
|
||||
});
|
||||
print("setting _date to ${_date}");
|
||||
},
|
||||
child: const Row(
|
||||
children: [
|
||||
Icon(Icons.add),
|
||||
SizedBox(width: 5),
|
||||
Text("Add Today")
|
||||
],
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
print("ciao");
|
||||
},
|
||||
style: ButtonStyle(
|
||||
backgroundColor:
|
||||
MaterialStateProperty.all(Colors.red)),
|
||||
child: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.delete),
|
||||
Text("Delete"),
|
||||
],
|
||||
)),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Save"),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
//import components
|
||||
import '../Components/Reminder.dart';
|
||||
|
||||
class InboxView extends StatefulWidget {
|
||||
const InboxView({super.key});
|
||||
|
||||
@@ -13,15 +10,9 @@ class InboxView extends StatefulWidget {
|
||||
class _InboxViewState extends State<InboxView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Inbox'),
|
||||
),
|
||||
body: ListView(
|
||||
children: const <Widget>[
|
||||
/* Reminder(),
|
||||
Reminder(),*/
|
||||
],
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Icon(Icons.inbox),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
//import components
|
||||
import '../Components/Reminder.dart';
|
||||
import '../Components/QuickReminder.dart';
|
||||
import '../model/promemoria.dart';
|
||||
|
||||
class TodayView extends StatefulWidget {
|
||||
const TodayView({super.key});
|
||||
|
||||
@@ -13,49 +8,12 @@ class TodayView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TodayViewState extends State<TodayView> {
|
||||
|
||||
var _selectedDate = DateTime.now();
|
||||
|
||||
List<Promemoria> listaPromemoria = [
|
||||
new Promemoria("Primo promemoria"),
|
||||
new Promemoria("Secondo promemoria"),
|
||||
new Promemoria("Terzo promemoria"),
|
||||
new Promemoria("Quarto promemoria"),
|
||||
new Promemoria("Quinto promemoria"),
|
||||
new Promemoria("Sesto promemoria"),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: FilledButton(
|
||||
onPressed: () async {
|
||||
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())
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ListView.builder(
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
itemCount: listaPromemoria.length,
|
||||
itemBuilder: (BuildContext context, int index){
|
||||
return Reminder(
|
||||
listaPromemoria[index]
|
||||
);
|
||||
},
|
||||
),
|
||||
QuickReminder(),
|
||||
],
|
||||
),
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: Icon(Icons.calendar_today)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,14 @@ class _TestState extends State<Test> {
|
||||
print("Data printed");
|
||||
}
|
||||
|
||||
Future<void> _deletedatabase() async {
|
||||
final db = await noteDatabase.database;
|
||||
|
||||
print("Deleting database");
|
||||
await db.delete(noteTable);
|
||||
print("Database deleted");
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -36,7 +44,8 @@ class _TestState extends State<Test> {
|
||||
child: Column(
|
||||
children: [
|
||||
FloatingActionButton(onPressed: _pressed),
|
||||
FloatingActionButton(onPressed: _printdata)
|
||||
FloatingActionButton(onPressed: _printdata),
|
||||
FloatingActionButton(onPressed: _deletedatabase)
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user