From 29a54bbcbcbeb023e2f8216fbc95bbd1e9dcd774 Mon Sep 17 00:00:00 2001 From: Tito Arrigo Date: Thu, 28 Sep 2023 09:49:09 +0200 Subject: [PATCH 1/3] grafica pagina TodayView.dart --- lib/Components/EditReminder.dart | 55 ++++++++++++++++++++++++++++++++ lib/Components/Reminder.dart | 33 +++++++++++++++++++ lib/myApp.dart | 3 +- lib/navigation.dart | 16 +++++----- lib/pages/TodayView.dart | 13 +++++--- 5 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 lib/Components/EditReminder.dart create mode 100644 lib/Components/Reminder.dart diff --git a/lib/Components/EditReminder.dart b/lib/Components/EditReminder.dart new file mode 100644 index 0000000..927e0c2 --- /dev/null +++ b/lib/Components/EditReminder.dart @@ -0,0 +1,55 @@ +import 'package:flutter/material.dart'; + +class EditReminder extends StatelessWidget{ + @override + Widget build(BuildContext context) { + return FloatingActionButton.small( + onPressed: () { + showModalBottomSheet( + context: context, + showDragHandle: true, + builder: (BuildContext context) { + return Container( + // Contenuto del BottomSheet modale + + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + title: const TextField( + decoration: InputDecoration( + hintText: "Title", + border: OutlineInputBorder(), + ), + ), + onTap: () { + // Azione da eseguire quando viene selezionato "Share" + Navigator.pop(context); + }, + ), + ListTile( + title: const TextField( + decoration: InputDecoration( + hintText: "Title", + border: OutlineInputBorder(), + ), + ), + onTap: () { + // Azione da eseguire quando viene selezionato "Share" + Navigator.pop(context); + }, + ), + //spacer + Container( + height: 600 + ), + ], + ), + ); + }, + ); + }, + child: Icon(Icons.edit), + ); + } +} diff --git a/lib/Components/Reminder.dart b/lib/Components/Reminder.dart new file mode 100644 index 0000000..fdddfa5 --- /dev/null +++ b/lib/Components/Reminder.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; + +import '../Components/EditReminder.dart'; + +class Reminder extends StatefulWidget { + const Reminder({super.key}); + + @override + State createState() => _ReminderState(); +} + +class _ReminderState extends State { + 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: EditReminder(), + ); + } +} diff --git a/lib/myApp.dart b/lib/myApp.dart index 2f9d223..afa1213 100644 --- a/lib/myApp.dart +++ b/lib/myApp.dart @@ -9,8 +9,7 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'My App', theme: ThemeData( - useMaterial3: true, - primaryColor: Colors.red, + useMaterial3: true, colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.orange, primary: Colors.blueAccent, background: Colors.white), ), home: Navigation() ); diff --git a/lib/navigation.dart b/lib/navigation.dart index 180a383..f43bebe 100644 --- a/lib/navigation.dart +++ b/lib/navigation.dart @@ -36,14 +36,14 @@ class _NavigationState extends State { ), body: Center(child: _widgetOptions.elementAt(_selectedIndex)), bottomNavigationBar: BottomNavigationBar( - items: const [ - BottomNavigationBarItem( - icon: Icon(Icons.calendar_today), label: "today"), - BottomNavigationBarItem(icon: Icon(Icons.inbox), label: "Inbox"), - BottomNavigationBarItem(icon: Icon(Icons.note), label: "Notes"), - ], - currentIndex: _selectedIndex, - onTap: _onItemTapped, + items: const [ + BottomNavigationBarItem( + icon: Icon(Icons.today), label: "today"), + BottomNavigationBarItem(icon: Icon(Icons.inbox), label: "Inbox"), + BottomNavigationBarItem(icon: Icon(Icons.note), label: "Notes"), + ], + currentIndex: _selectedIndex, + onTap: _onItemTapped, ), ); } diff --git a/lib/pages/TodayView.dart b/lib/pages/TodayView.dart index cad5346..a6a57f7 100644 --- a/lib/pages/TodayView.dart +++ b/lib/pages/TodayView.dart @@ -1,5 +1,9 @@ import 'package:flutter/material.dart'; +//import components +import '../Components/Reminder.dart'; +import '../Components/EditReminder.dart'; + class TodayView extends StatefulWidget { const TodayView({super.key}); @@ -10,10 +14,11 @@ class TodayView extends StatefulWidget { class _TodayViewState extends State { @override Widget build(BuildContext context) { - return const Scaffold( - body: Center( - child: Icon(Icons.calendar_today) - ) + return ListView( + children: [ + Reminder(), + Reminder(), + ] ); } } From e061871c4ff54f0ebbf4e589316fd7181e7845d2 Mon Sep 17 00:00:00 2001 From: Tito Arrigo Date: Thu, 28 Sep 2023 11:46:08 +0200 Subject: [PATCH 2/3] grafica pagina TodayView.dart --- lib/Components/EditReminder.dart | 55 -------------------------- lib/Components/EditReminderButton.dart | 17 ++++++++ lib/Components/Reminder.dart | 4 +- lib/myApp.dart | 2 +- lib/navigation.dart | 5 +-- lib/pages/EditReminder.dart | 54 +++++++++++++++++++++++++ lib/pages/TodayView.dart | 2 +- 7 files changed, 76 insertions(+), 63 deletions(-) delete mode 100644 lib/Components/EditReminder.dart create mode 100644 lib/Components/EditReminderButton.dart create mode 100644 lib/pages/EditReminder.dart diff --git a/lib/Components/EditReminder.dart b/lib/Components/EditReminder.dart deleted file mode 100644 index 927e0c2..0000000 --- a/lib/Components/EditReminder.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:flutter/material.dart'; - -class EditReminder extends StatelessWidget{ - @override - Widget build(BuildContext context) { - return FloatingActionButton.small( - onPressed: () { - showModalBottomSheet( - context: context, - showDragHandle: true, - builder: (BuildContext context) { - return Container( - // Contenuto del BottomSheet modale - - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ListTile( - title: const TextField( - decoration: InputDecoration( - hintText: "Title", - border: OutlineInputBorder(), - ), - ), - onTap: () { - // Azione da eseguire quando viene selezionato "Share" - Navigator.pop(context); - }, - ), - ListTile( - title: const TextField( - decoration: InputDecoration( - hintText: "Title", - border: OutlineInputBorder(), - ), - ), - onTap: () { - // Azione da eseguire quando viene selezionato "Share" - Navigator.pop(context); - }, - ), - //spacer - Container( - height: 600 - ), - ], - ), - ); - }, - ); - }, - child: Icon(Icons.edit), - ); - } -} diff --git a/lib/Components/EditReminderButton.dart b/lib/Components/EditReminderButton.dart new file mode 100644 index 0000000..cb38d88 --- /dev/null +++ b/lib/Components/EditReminderButton.dart @@ -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), + ); + } +} diff --git a/lib/Components/Reminder.dart b/lib/Components/Reminder.dart index fdddfa5..c9da672 100644 --- a/lib/Components/Reminder.dart +++ b/lib/Components/Reminder.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../Components/EditReminder.dart'; +import '../Components/EditReminderButton.dart'; class Reminder extends StatefulWidget { const Reminder({super.key}); @@ -27,7 +27,7 @@ class _ReminderState extends State { ), title: Text("Reminder"), subtitle: Text(DateTime.now().toString()), - trailing: EditReminder(), + trailing: EditReminderButton(), ); } } diff --git a/lib/myApp.dart b/lib/myApp.dart index afa1213..9cc3f55 100644 --- a/lib/myApp.dart +++ b/lib/myApp.dart @@ -9,7 +9,7 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'My App', theme: ThemeData( - useMaterial3: true, colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.orange, primary: Colors.blueAccent, background: Colors.white), + useMaterial3: true, ), home: Navigation() ); diff --git a/lib/navigation.dart b/lib/navigation.dart index f43bebe..0c212d5 100644 --- a/lib/navigation.dart +++ b/lib/navigation.dart @@ -31,10 +31,7 @@ class _NavigationState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text("BottomNavBar"), - ), - body: Center(child: _widgetOptions.elementAt(_selectedIndex)), + body: SafeArea(child: _widgetOptions.elementAt(_selectedIndex)), bottomNavigationBar: BottomNavigationBar( items: const [ BottomNavigationBarItem( diff --git a/lib/pages/EditReminder.dart b/lib/pages/EditReminder.dart new file mode 100644 index 0000000..cc08858 --- /dev/null +++ b/lib/pages/EditReminder.dart @@ -0,0 +1,54 @@ +import 'package:flutter/material.dart'; + +class EditReminder extends StatefulWidget { + const EditReminder({super.key}); + + @override + State createState() => _EditReminderState(); +} + +class _EditReminderState extends State { + 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: [ + 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), + ], + ), + ) + ), + ); + } +} diff --git a/lib/pages/TodayView.dart b/lib/pages/TodayView.dart index a6a57f7..fe3db07 100644 --- a/lib/pages/TodayView.dart +++ b/lib/pages/TodayView.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; //import components import '../Components/Reminder.dart'; -import '../Components/EditReminder.dart'; +import '../Components/EditReminderButton.dart'; class TodayView extends StatefulWidget { const TodayView({super.key}); From c2824c99a42016ca9ae0720c5ffc9a849c2a2e86 Mon Sep 17 00:00:00 2001 From: Tito Arrigo Date: Thu, 28 Sep 2023 13:04:42 +0200 Subject: [PATCH 3/3] merge --- lib/database/database.dart | 181 ++++++++++++++++++ lib/database/note.dart | 8 - lib/database/promemoria.dart | 11 -- lib/{database => model}/base_entity.dart | 0 .../identifiers/enum/color.dart | 0 .../identifiers/enum/priority.dart | 0 lib/{database => model}/identifiers/tag.dart | 0 lib/model/note.dart | 12 ++ lib/model/promemoria.dart | 18 ++ lib/navigation.dart | 2 + lib/pages/test.dart | 45 +++++ pubspec.yaml | 3 + test/widget_test.dart | 2 +- 13 files changed, 262 insertions(+), 20 deletions(-) create mode 100644 lib/database/database.dart delete mode 100644 lib/database/note.dart delete mode 100644 lib/database/promemoria.dart rename lib/{database => model}/base_entity.dart (100%) rename lib/{database => model}/identifiers/enum/color.dart (100%) rename lib/{database => model}/identifiers/enum/priority.dart (100%) rename lib/{database => model}/identifiers/tag.dart (100%) create mode 100644 lib/model/note.dart create mode 100644 lib/model/promemoria.dart create mode 100644 lib/pages/test.dart diff --git a/lib/database/database.dart b/lib/database/database.dart new file mode 100644 index 0000000..8d9aea3 --- /dev/null +++ b/lib/database/database.dart @@ -0,0 +1,181 @@ +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'; + +class NoteDatabase { + static final NoteDatabase instance = NoteDatabase._init(); + static Database? _database; + + // Zero args constructor needed to extend this class + NoteDatabase(); + + NoteDatabase._init(); + + Future get database async { + if (_database != null) return _database!; + + _database = await _initDB('note.db'); + return _database!; + } + + Future _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(''' + 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'); + } + } + + Future> selectAllPromemoria() async { + final db = await database; + + final List> maps = await db.query(promemoriaTable); + + return maps; + } + + Future close() async { + final database = await instance.database; + database.close(); + } + + // WARNING: FOR DEV/TEST PURPOSES ONLY!! + Future deleteDatabase() async { + final databasePath = await getDatabasesPath(); + final path = join(databasePath, 'note.db'); + databaseFactory.deleteDatabase(path); + } +} diff --git a/lib/database/note.dart b/lib/database/note.dart deleted file mode 100644 index ece0167..0000000 --- a/lib/database/note.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'base_entity.dart'; - -class Note extends BaseEntity{ - static String id = BaseEntity.getId; - static String Title = BaseEntity.getTitle; - static String CreationDate = BaseEntity.getCreationDate; - -} \ No newline at end of file diff --git a/lib/database/promemoria.dart b/lib/database/promemoria.dart deleted file mode 100644 index baa8ddd..0000000 --- a/lib/database/promemoria.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'base_entity.dart'; -import 'identifiers/enum/priority.dart'; - -class Note extends BaseEntity{ - static String id = BaseEntity.getId; - static String title = BaseEntity.getTitle; - static String creationDate = BaseEntity.getCreationDate; - static String expirationDate = 'expirationDate'; - Priority priority = Priority.low; -} - diff --git a/lib/database/base_entity.dart b/lib/model/base_entity.dart similarity index 100% rename from lib/database/base_entity.dart rename to lib/model/base_entity.dart diff --git a/lib/database/identifiers/enum/color.dart b/lib/model/identifiers/enum/color.dart similarity index 100% rename from lib/database/identifiers/enum/color.dart rename to lib/model/identifiers/enum/color.dart diff --git a/lib/database/identifiers/enum/priority.dart b/lib/model/identifiers/enum/priority.dart similarity index 100% rename from lib/database/identifiers/enum/priority.dart rename to lib/model/identifiers/enum/priority.dart diff --git a/lib/database/identifiers/tag.dart b/lib/model/identifiers/tag.dart similarity index 100% rename from lib/database/identifiers/tag.dart rename to lib/model/identifiers/tag.dart diff --git a/lib/model/note.dart b/lib/model/note.dart new file mode 100644 index 0000000..d542561 --- /dev/null +++ b/lib/model/note.dart @@ -0,0 +1,12 @@ +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 = ''; +} diff --git a/lib/model/promemoria.dart b/lib/model/promemoria.dart new file mode 100644 index 0000000..5326c1d --- /dev/null +++ b/lib/model/promemoria.dart @@ -0,0 +1,18 @@ +import 'base_entity.dart'; +import 'identifiers/enum/color.dart'; +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; +} diff --git a/lib/navigation.dart b/lib/navigation.dart index 0c212d5..b1f2cca 100644 --- a/lib/navigation.dart +++ b/lib/navigation.dart @@ -5,6 +5,7 @@ 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}); @@ -41,6 +42,7 @@ class _NavigationState extends State { ], currentIndex: _selectedIndex, onTap: _onItemTapped, + type: BottomNavigationBarType.fixed, ), ); } diff --git a/lib/pages/test.dart b/lib/pages/test.dart new file mode 100644 index 0000000..7cda250 --- /dev/null +++ b/lib/pages/test.dart @@ -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 createState() => _TestState(); +} + +class _TestState extends State { + NoteDatabase noteDatabase = NoteDatabase.instance; + + Future _pressed() async { + print("Inserting demo data"); + final db = await noteDatabase.database; + + + } + + Future _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) + ], + ) + ) + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 84d5e35..f735786 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,6 +36,9 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 firebase_core: ^2.16.0 + sqflite: ^2.3.0 + path: ^1.8.3 + sqflite_common_ffi: ^2.3.0+2 dev_dependencies: flutter_test: diff --git a/test/widget_test.dart b/test/widget_test.dart index 5e5d15e..bb5dffa 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:progetto_m335_flutter/main.dart'; +import 'package:progetto_m335_flutter/myApp.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async {