Merge remote-tracking branch 'origin/Tito' into Zina
# Conflicts: # lib/database/database.dart # lib/model/note.dart # lib/model/promemoria.dart # lib/navigation.dart
This commit is contained in:
17
lib/Components/EditReminderButton.dart
Normal file
17
lib/Components/EditReminderButton.dart
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
lib/Components/Reminder.dart
Normal file
33
lib/Components/Reminder.dart
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../Components/EditReminderButton.dart';
|
||||||
|
|
||||||
|
class Reminder extends StatefulWidget {
|
||||||
|
const Reminder({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("Reminder"),
|
||||||
|
subtitle: Text(DateTime.now().toString()),
|
||||||
|
trailing: EditReminderButton(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +1,181 @@
|
|||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:progetto_m335_flutter/model/note.dart';
|
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
class Database{
|
// Models
|
||||||
static final Database _instance = Database._init();
|
import 'package:progetto_m335_flutter/model/note.dart';
|
||||||
|
import 'package:progetto_m335_flutter/model/promemoria.dart';
|
||||||
|
|
||||||
|
class NoteDatabase {
|
||||||
|
static final NoteDatabase instance = NoteDatabase._init();
|
||||||
static Database? _database;
|
static Database? _database;
|
||||||
|
|
||||||
Database._init();
|
// Zero args constructor needed to extend this class
|
||||||
|
NoteDatabase();
|
||||||
|
|
||||||
Future _createDB(Database database) async{
|
NoteDatabase._init();
|
||||||
const integerPrimaryKeyAutoincrement = 'INTEGER PRIMARY KEY AUTOINCREMENT';
|
|
||||||
const textNotNull = 'TEXT NOT NULL';
|
Future<Database> get database async {
|
||||||
const integerNotNull = 'INTEGER NOT NULL';
|
if (_database != null) return _database!;
|
||||||
const integer = 'INTEGER';
|
|
||||||
const real = 'REAL';
|
_database = await _initDB('note.db');
|
||||||
const text = 'TEXT';
|
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.
|
||||||
|
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 note (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
creationDate TEXT NOT NULL,
|
||||||
|
lastModificationDate 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('''
|
await database.execute('''
|
||||||
CREATE TABLE $Note (
|
INSERT INTO note (
|
||||||
${Note.id} $integerPrimaryKeyAutoincrement,
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(String s) {
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Map>> selectAllPromemoria() async {
|
||||||
|
final db = await database;
|
||||||
|
|
||||||
|
final List<Map<String, dynamic>> maps = await db.query(promemoriaTable);
|
||||||
|
|
||||||
|
return maps;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future close() async {
|
||||||
|
final database = await instance.database;
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: FOR DEV/TEST PURPOSES ONLY!!
|
||||||
|
Future<void> deleteDatabase() async {
|
||||||
|
final databasePath = await getDatabasesPath();
|
||||||
|
final path = join(databasePath, 'note.db');
|
||||||
|
databaseFactory.deleteDatabase(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ class Note extends BaseEntity {
|
|||||||
static String title = BaseEntity.getTitle;
|
static String title = BaseEntity.getTitle;
|
||||||
static String creationDate = BaseEntity.getCreationDate;
|
static String creationDate = BaseEntity.getCreationDate;
|
||||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||||
|
static String arrayPromemoria = '';
|
||||||
static String description = '';
|
static String description = '';
|
||||||
Map<String, dynamic> toMap() {
|
|
||||||
return {'id': id, 'title': title, 'desc': description,'CreationDate': creationDate, 'lastM': lastModificationDate };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'base_entity.dart';
|
import 'base_entity.dart';
|
||||||
import 'identifiers/enum/color.dart';
|
import 'identifiers/enum/color.dart';
|
||||||
import 'identifiers/enum/priority.dart';
|
import 'identifiers/enum/priority.dart';
|
||||||
@@ -12,12 +10,9 @@ class Promemoria extends BaseEntity{
|
|||||||
static String creationDate = BaseEntity.getCreationDate;
|
static String creationDate = BaseEntity.getCreationDate;
|
||||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||||
static String expirationDate = '';
|
static String expirationDate = '';
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ class MyApp extends StatelessWidget {
|
|||||||
title: 'My App',
|
title: 'My App',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
primaryColor: Colors.red,
|
|
||||||
),
|
),
|
||||||
home: Navigation()
|
home: Navigation()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'pages/testUI.dart';
|
import 'pages/testUI.dart';
|
||||||
import 'pages/TodayView.dart';
|
import 'pages/TodayView.dart';
|
||||||
@@ -29,16 +31,17 @@ class _NavigationState extends State<Navigation> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Center(child: _widgetOptions.elementAt(_selectedIndex)),
|
body: SafeArea(child: _widgetOptions.elementAt(_selectedIndex)),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
items: const <BottomNavigationBarItem>[
|
items: const <BottomNavigationBarItem>[
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.calendar_today), label: "today"),
|
icon: Icon(Icons.today), label: "today"),
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.inbox), label: "Inbox"),
|
BottomNavigationBarItem(icon: Icon(Icons.inbox), label: "Inbox"),
|
||||||
BottomNavigationBarItem(icon: Icon(Icons.note), label: "Notes"),
|
BottomNavigationBarItem(icon: Icon(Icons.note), label: "Notes"),
|
||||||
],
|
],
|
||||||
currentIndex: _selectedIndex,
|
currentIndex: _selectedIndex,
|
||||||
onTap: _onItemTapped,
|
onTap: _onItemTapped,
|
||||||
|
type: BottomNavigationBarType.fixed,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
54
lib/pages/EditReminder.dart
Normal file
54
lib/pages/EditReminder.dart
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class EditReminder extends StatefulWidget {
|
||||||
|
const EditReminder({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<EditReminder> createState() => _EditReminderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EditReminderState extends State<EditReminder> {
|
||||||
|
String _title = "ciaciao";
|
||||||
|
String _description = "description";
|
||||||
|
DateTime _date = DateTime.now();
|
||||||
|
@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: _title),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: 'Title',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Expanded(child: TextField(
|
||||||
|
onChanged: (text) {
|
||||||
|
setState(() {
|
||||||
|
_description = text;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
controller: TextEditingController(text: _description),
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
labelText: 'Description',
|
||||||
|
),
|
||||||
|
maxLines: 6,
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
|
),),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
//import components
|
||||||
|
import '../Components/Reminder.dart';
|
||||||
|
import '../Components/EditReminderButton.dart';
|
||||||
|
|
||||||
class TodayView extends StatefulWidget {
|
class TodayView extends StatefulWidget {
|
||||||
const TodayView({super.key});
|
const TodayView({super.key});
|
||||||
|
|
||||||
@@ -10,10 +14,11 @@ class TodayView extends StatefulWidget {
|
|||||||
class _TodayViewState extends State<TodayView> {
|
class _TodayViewState extends State<TodayView> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const Scaffold(
|
return ListView(
|
||||||
body: Center(
|
children: <Widget>[
|
||||||
child: Icon(Icons.calendar_today)
|
Reminder(),
|
||||||
)
|
Reminder(),
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
lib/pages/test.dart
Normal file
45
lib/pages/test.dart
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:progetto_m335_flutter/database/database.dart';
|
||||||
|
import 'package:progetto_m335_flutter/model/note.dart';
|
||||||
|
|
||||||
|
import '../database/database.dart';
|
||||||
|
|
||||||
|
class Test extends StatefulWidget {
|
||||||
|
const Test({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Test> createState() => _TestState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TestState extends State<Test> {
|
||||||
|
NoteDatabase noteDatabase = NoteDatabase.instance;
|
||||||
|
|
||||||
|
Future<void> _pressed() async {
|
||||||
|
print("Inserting demo data");
|
||||||
|
final db = await noteDatabase.database;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _printdata() async {
|
||||||
|
final db = await noteDatabase.database;
|
||||||
|
|
||||||
|
print("Printing data");
|
||||||
|
print(await db.query(noteTable));
|
||||||
|
print("Data printed");
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
FloatingActionButton(onPressed: _pressed),
|
||||||
|
FloatingActionButton(onPressed: _printdata)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,6 +37,9 @@ dependencies:
|
|||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
firebase_core: ^2.16.0
|
firebase_core: ^2.16.0
|
||||||
|
sqflite: ^2.3.0
|
||||||
|
path: ^1.8.3
|
||||||
|
sqflite_common_ffi: ^2.3.0+2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:progetto_m335_flutter/main.dart';
|
import 'package:progetto_m335_flutter/myApp.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
|
|||||||
Reference in New Issue
Block a user