Repeat after improvements

This commit is contained in:
konrad 2019-03-17 15:42:23 +01:00
parent 76149c315e
commit 9bc5f30345
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B

View File

@ -100,13 +100,20 @@ class _TaskEditPageState extends State<TaskEditPage> {
onSaved: (endDate) => _endDate = endDate,
),
Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Row(children: [
padding: EdgeInsets.symmetric(vertical: 10.0),
child: Row(
children: [
Expanded(
flex: 2,
child: TextFormField(
keyboardType: TextInputType.number,
initialValue: _repeatAfterValue == null ? null : _repeatAfterValue.toString(),
onSaved: (repeatAfter) => _repeatAfter = _makeDurationFromType(int.parse(repeatAfter), _repeatAfterType),
initialValue: _repeatAfterValue == null
? null
: _repeatAfterValue.toString(),
onSaved: (repeatAfter) => _repeatAfter =
_makeDurationFromType(
repeatAfter,
_repeatAfterType),
decoration: new InputDecoration(
labelText: 'Repeat after',
border: InputBorder.none,
@ -114,30 +121,32 @@ class _TaskEditPageState extends State<TaskEditPage> {
),
),
),
Container(
// width: 100,
child: DropdownButton<String>(
value: _repeatAfterType,
onChanged: (String newValue) {
setState(() {
_repeatAfterType = newValue;
});
},
items: <String>[
'Hours',
'Days',
'Weeks',
'Months',
'Years'
].map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
))
])),
Expanded(
child: DropdownButton<String>(
isExpanded: true,
value: _repeatAfterType,
onChanged: (String newValue) {
setState(() {
_repeatAfterType = newValue;
});
},
items: <String>[
'Hours',
'Days',
'Weeks',
'Months',
'Years'
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
],
),
),
Builder(
builder: (context) => Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
@ -197,18 +206,26 @@ class _TaskEditPageState extends State<TaskEditPage> {
});
}
_makeDurationFromType(int value, String type) {
_makeDurationFromType(String value, String type) {
// Return an empty duration if either of the values is not set
if (value == null || value == '' || type == null || type == '') {
return Duration();
}
int val = int.parse(value);
switch (type) {
case 'Hours':
return Duration(seconds: value * 60);
return Duration(seconds: val * 60);
case 'Days':
return Duration(seconds: value * 60 * 24);
return Duration(seconds: val * 60 * 24);
case 'Weeks':
return Duration(seconds: value * 60 * 24 * 7);
return Duration(seconds: val * 60 * 24 * 7);
case 'Months':
return Duration(seconds: value * 60 * 24 * 7 * 30);
return Duration(seconds: val * 60 * 24 * 7 * 30);
case 'Years':
return Duration(seconds: value * 60 * 24 * 7 * 365);
return Duration(seconds: val * 60 * 24 * 7 * 365);
}
}
}