Polished
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'Data.dart';
|
||||
import 'Dialogs.dart';
|
||||
|
||||
class NewJournal extends StatefulWidget {
|
||||
NewJournal({Key? key, this.title, this.text, this.date}) : super(key: key);
|
||||
@@ -18,11 +19,31 @@ class NewJournal extends StatefulWidget {
|
||||
|
||||
class _NewJournalState extends State<NewJournal> {
|
||||
bool editing =false;
|
||||
|
||||
DateTime date= DateTime.now();
|
||||
DateFormat dFormat = DateFormat('yyyy-MM-dd');
|
||||
_NewJournalState({String? title, String? text, DateTime? m_date}){
|
||||
if(m_date!= null){
|
||||
editing = true;
|
||||
date=m_date;
|
||||
oldDate =m_date;
|
||||
}else{
|
||||
bool foundEmptyDate = false;
|
||||
while(!foundEmptyDate) {
|
||||
bool exist = false;
|
||||
for (var element in User.journal) {
|
||||
if (dFormat.format(element.day) == dFormat.format(date)) {
|
||||
//Wat!
|
||||
exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
foundEmptyDate=true;
|
||||
}else{
|
||||
date = date.subtract(Duration(days: 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
titleController.text = title??'';
|
||||
@@ -33,7 +54,6 @@ class _NewJournalState extends State<NewJournal> {
|
||||
TextEditingController descriptionEditingController = TextEditingController();
|
||||
bool productive = true;
|
||||
Color pickerColor = Colors.blue;
|
||||
DateTime date= DateTime.now();
|
||||
DateTime oldDate = DateTime.now();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -57,8 +77,25 @@ class _NewJournalState extends State<NewJournal> {
|
||||
theme: DatePickerTheme(), onChanged: (date) {
|
||||
// print('change $date');
|
||||
}, onConfirm: (newDate){
|
||||
date = newDate;
|
||||
}, currentTime: DateTime.now(), locale: LocaleType.en);
|
||||
bool exist =false;
|
||||
for (var element in User.journal) {
|
||||
if(dFormat.format(element.day) == dFormat.format(newDate)){
|
||||
//Wat!
|
||||
exist=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(exist){
|
||||
Dialogs.showAlertDialog(context, 'Cant duplicate entries!', 'Journal entry was found on this date, Please edit that instead of adding new entry.');
|
||||
}else {
|
||||
date = newDate;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
|
||||
});
|
||||
}, currentTime: date, locale: LocaleType.en);
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 10),
|
||||
@@ -70,7 +107,7 @@ class _NewJournalState extends State<NewJournal> {
|
||||
Text('Date : '),
|
||||
SizedBox(width: 30,),
|
||||
Text(
|
||||
DateFormat('yyyy-MM-dd').format(date),
|
||||
dFormat.format(date),
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
SizedBox(width: 30,),
|
||||
@@ -146,6 +183,19 @@ class _NewJournalState extends State<NewJournal> {
|
||||
if(editing){
|
||||
await User.UserOperations.editJournal(oldDate,date,title,text);
|
||||
}else{
|
||||
bool exist =false;
|
||||
for (var element in User.journal) {
|
||||
if(element.day== date){
|
||||
//Wat!
|
||||
exist=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(exist){
|
||||
Dialogs.showAlertDialog(context, 'Cant duplicate entries!', 'Journal entry was found on this date, Please edit that instead of adding new entry.');
|
||||
return;
|
||||
}
|
||||
await User.UserOperations.addJournal(date, title, text);
|
||||
}
|
||||
Navigator.of(context).popUntil((route) {
|
||||
|
||||
Reference in New Issue
Block a user