Aggiornamento note e pulsanti.
This commit is contained in:
@@ -1,7 +1,21 @@
|
|||||||
|
import 'dart:math';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'CreateNewNote.dart';
|
import 'CreateNewNote.dart';
|
||||||
import 'NoteDetailView.dart';
|
import 'NoteDetailView.dart';
|
||||||
|
|
||||||
|
class Note {
|
||||||
|
late String title;
|
||||||
|
late Map<String, dynamic> content;
|
||||||
|
late DateTime startDate;
|
||||||
|
late DateTime modifyDate;
|
||||||
|
|
||||||
|
Note({
|
||||||
|
required this.title,
|
||||||
|
required this.content,
|
||||||
|
required this.startDate,
|
||||||
|
required this.modifyDate,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
class NotesView extends StatefulWidget {
|
class NotesView extends StatefulWidget {
|
||||||
const NotesView({Key? key}) : super(key: key);
|
const NotesView({Key? key}) : super(key: key);
|
||||||
@@ -11,13 +25,44 @@ class NotesView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NotesViewState extends State<NotesView> {
|
class _NotesViewState extends State<NotesView> {
|
||||||
|
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<Note> generateRandomNotes(int count) {
|
||||||
|
final List<String> 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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final List<Note> notes = generateRandomNotes(10);
|
||||||
|
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Note', style: TextStyle(color: Colors.white),),
|
title: Text('Note'),
|
||||||
backgroundColor: Colors.lightBlue.shade900,
|
backgroundColor: Colors.blue,
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -27,21 +72,31 @@ class _NotesViewState extends State<NotesView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
child: Icon(Icons.add),
|
child: Icon(Icons.add),
|
||||||
backgroundColor: Colors.lightBlue.shade900,
|
backgroundColor: Colors.blue,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
||||||
body: Container(
|
body: Container(
|
||||||
|
color: Colors.blue[50],
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: 5,
|
itemCount: notes.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
final note = notes[index];
|
||||||
return Card(
|
return Card(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
|
elevation: 2.0,
|
||||||
|
margin: EdgeInsets.all(8.0),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text("ciao", style: TextStyle(color: Colors.lightBlue.shade900, fontWeight: FontWeight.bold),),
|
title: Text(
|
||||||
subtitle: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text('Descrizione della nota:'),],),
|
note.title,
|
||||||
|
style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
subtitle: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Descrizione della nota: ${notes.first.content}'),
|
||||||
|
],
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
sqflite:
|
||||||
|
path:
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
|
|||||||
Reference in New Issue
Block a user