This commit is contained in:
Giulia
2023-09-28 13:21:02 +02:00
committed by Joe Küng
parent 6eb06f6a05
commit a6ba19abdd
3 changed files with 75 additions and 65 deletions

View File

@@ -1,4 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'CreateNewNote.dart';
import 'NoteDetailView.dart';
class InboxView extends StatefulWidget { class InboxView extends StatefulWidget {
const InboxView({super.key}); const InboxView({super.key});
@@ -8,6 +10,14 @@ class InboxView extends StatefulWidget {
} }
class _InboxViewState extends State<InboxView> { class _InboxViewState extends State<InboxView> {
List<bool> _values = [false, false, false, false, false];
void _onChanged(int index, bool? newValue){
setState(() {
_values[index] = newValue ?? false;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@@ -19,7 +29,31 @@ class _InboxViewState extends State<InboxView> {
}, },
child: Icon(Icons.add), child: Icon(Icons.add),
), ),
body: Container(
child: ListView.builder(
itemCount: 5,
itemBuilder: (context, index) {
return Card(
color: Colors.white,
child: ListTile(
leading: Checkbox(
value: _values[index],
onChanged: (newValue) => _onChanged(index, newValue),
),
title: Text("ciao", style: TextStyle(color: Colors.lightBlue.shade900, fontWeight: FontWeight.bold)),
subtitle: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text('Descrizione della nota:')]),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const NoteDetailView(),
),
);
},
),
);
},
),
),
); );
} }
} }

31
lib/pages/Note.dart Normal file
View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'NoteDetailView.dart';
class Note extends StatefulWidget {
const Note({super.key});
@override
State<Note> createState() => _NotesViewState();
}
class _NotesViewState extends State<Note> {
@override
Widget build(BuildContext context) {
return Card(
color: Colors.white,
child: ListTile(
title: Text("ciao", style: TextStyle(color: Colors.lightBlue.shade900, fontWeight: FontWeight.bold),),
subtitle: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text('Descrizione della nota:'),],),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const NoteDetailView(),
),
);
},
),
);
}
}

View File

@@ -1,21 +1,7 @@
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);
@@ -25,44 +11,13 @@ 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'), title: Text('Note', style: TextStyle(color: Colors.white),),
backgroundColor: Colors.blue, backgroundColor: Colors.lightBlue.shade900,
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () {
@@ -72,31 +27,21 @@ class _NotesViewState extends State<NotesView> {
), ),
); );
}, },
child: Icon(Icons.add), child: Icon(Icons.add),
backgroundColor: Colors.blue, backgroundColor: Colors.lightBlue.shade900,
), ),
body: Container( body: Container(
color: Colors.blue[50],
child: ListView.builder( child: ListView.builder(
itemCount: notes.length, itemCount: 5,
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( title: Text("ciao", style: TextStyle(color: Colors.lightBlue.shade900, fontWeight: FontWeight.bold),),
note.title, subtitle: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text('Descrizione della nota:'),],),
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(