Skip to content

Commit

Permalink
Update add event feature
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoSilva11 committed Jun 10, 2022
1 parent e1c67c5 commit 32294f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
4 changes: 4 additions & 0 deletions lib/model/entities/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ class Event {
this.delivery = true;
subject = delivery.subject;
}

void setTitle(String title) {
this.title = title;
}
}
59 changes: 20 additions & 39 deletions lib/view/Widgets/add_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class AddEvent extends StatefulWidget {
class AddEventWidget extends State<AddEvent> {
final _formKey = GlobalKey<FormState>();

String title;
DateTime time;
TextEditingController textFieldController = TextEditingController();

@override
void dispose() {
textFieldController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
Expand All @@ -31,65 +36,41 @@ class AddEventWidget extends State<AddEvent> {
backgroundColor: Colors.grey[900],
automaticallyImplyLeading: true,
),
resizeToAvoidBottomInset: false,
body: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 4.0,
),
child: TextFormField(
controller: textFieldController,
decoration: const InputDecoration(
icon: const Icon(Icons.calendar_today),
hintText: 'Enter a name for the new event',
labelText: 'Name',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
title = value;
return null;
},
onSaved: (val) => textFieldController.text = val.toString(),
),
),
Container(
margin: const EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 4.0,
horizontal: 12.0,
vertical: 13.0,
),
child: TextFormField(
decoration: const InputDecoration(
icon: const Icon(Icons.access_time),
hintText: 'Enter an hour (HH:mm)',
labelText: 'Hour',
child: FloatingActionButton.extended(
label: Text(
'Confirmar',
style: TextStyle(color: Colors.white),
),
validator: (value) {
if (value.isNotEmpty && value.length == 5) {
int y = widget.selectedDay.year;
int m = widget.selectedDay.month;
int d = widget.selectedDay.day;
int h = int.parse(value.substring(0, 2));
int min = int.parse(value.substring(3, 5));
time = DateTime(y, m, d, h, m);
}
return null;
},
),
),
Container(
padding: const EdgeInsets.only(left: 150.0, top: 40.0),
child: ElevatedButton(
child: const Text('OK'),
icon: Icon(Icons.check_rounded, color: Colors.white),
backgroundColor: Colors.grey[900],
onPressed: () {
if (_formKey.currentState.validate()) {
final event = Event('tauas', DateTime(2022, 6, 11, 12, 00));
Navigator.pop(context, event);
}
String title = textFieldController.text;
Navigator.pop(
context, Event(title, DateTime(2022, 6, 11, 12, 00)));
},
),
),
Expand Down
5 changes: 4 additions & 1 deletion lib/view/Widgets/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ class CalendarWidget extends State<Calendar> {
if (event.getTitle() != '') {
widget.events.add(event);
}
setState(() {});
setState(() {
_selectedEvents =
ValueNotifier(_getEventsForDay(_selectedDay));
});
},
),
),
Expand Down

0 comments on commit 32294f0

Please sign in to comment.