From 251e47ae56b79bb9c61d521abbdff0baaf6c1804 Mon Sep 17 00:00:00 2001 From: lama137 <99168742+lama137@users.noreply.github.com> Date: Thu, 28 Sep 2023 11:03:54 +0200 Subject: [PATCH] Aggiornamento note e pulsanti. --- lib/database/database.dart | 5 ++- lib/pages/NotesView.dart | 86 +++++++++++++++++++++++++++++++++++++- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/lib/database/database.dart b/lib/database/database.dart index 78b2ed5..71b71b4 100644 --- a/lib/database/database.dart +++ b/lib/database/database.dart @@ -1,4 +1,6 @@ +import 'package:path/path.dart'; import 'package:progetto_m335_flutter/model/note.dart'; +import 'package:sqflite/sqflite.dart'; class Database{ static final Database _instance = Database._init(); @@ -22,9 +24,10 @@ class Database{ ) '''); + } execute(String s) { } -} \ No newline at end of file +} diff --git a/lib/pages/NotesView.dart b/lib/pages/NotesView.dart index 6ae0886..391e535 100644 --- a/lib/pages/NotesView.dart +++ b/lib/pages/NotesView.dart @@ -1,6 +1,22 @@ +import 'dart:math'; import 'package:flutter/material.dart'; +import 'CreateNewNote.dart'; import 'NoteDetailView.dart'; +class Note { + late String title; + late Map content; + late DateTime startDate; + late DateTime modifyDate; + + Note({ + required this.title, + required this.content, + required this.startDate, + required this.modifyDate, + }); +} + class NotesView extends StatefulWidget { const NotesView({Key? key}) : super(key: key); @@ -9,23 +25,89 @@ class NotesView extends StatefulWidget { } class _NotesViewState extends State { + DateTime randomDate(DateTime start, DateTime end) { + final random = Random(); + final dayDifference = end.difference(start).inDays; + final randomDays = random.nextInt(dayDifference + 1); + return start.add(Duration(days: randomDays)); + } + + List generateRandomNotes(int count) { + final List titles = ["Nota 1", "Nota 2", "Nota 3", "Nota 4"]; + + final DateTime now = DateTime.now(); + + return List.generate(count, (index) { + final title = titles[index % titles.length]; + final content = { + 'Desc': 'Descrizione', + }; + final startDate = randomDate(DateTime(2023, 1, 1), now); + final modifyDate = randomDate(startDate, now); + + return Note( + title: title, + content: content, + startDate: startDate, + modifyDate: modifyDate, + ); + }); + } + @override Widget build(BuildContext context) { + final List notes = generateRandomNotes(10); + + return Scaffold( appBar: AppBar( title: Text('Note'), + backgroundColor: Colors.blue, ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.of(context).push( MaterialPageRoute( - builder: (context) => const NoteDetailView(), + builder: (context) => const CreateNewNote(), ), ); }, child: Icon(Icons.add), + backgroundColor: Colors.blue, + ), + body: Container( + color: Colors.blue[50], + child: ListView.builder( + itemCount: notes.length, + itemBuilder: (context, index) { + final note = notes[index]; + return Card( + color: Colors.white, + elevation: 2.0, + margin: EdgeInsets.all(8.0), + child: ListTile( + title: Text( + note.title, + style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold), + ), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('Descrizione della nota: ${notes.first.content}'), + ], + ), + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const NoteDetailView(), + ), + ); + }, + ), + ); + }, + ), ), ); } } -