1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Can create countdown timers

This commit is contained in:
2020-04-25 08:23:52 +02:00
parent 60c135bf01
commit ba07247ec4
3 changed files with 58 additions and 1 deletions

View File

@ -49,11 +49,14 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
PostVisibilityLevel _postVisibilityLevel;
File _postImage;
List<int> _postPDF;
DateTime _timeEnd;
bool get hasImage => _postImage != null;
bool get hasPDF => _postPDF != null;
bool get hasTimeEnd => _timeEnd != null;
bool get canSubmitForm =>
!_isCreating && _postTextController.text.length > 5 ||
postKind != PostKind.TEXT;
@ -63,6 +66,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
return PostKind.IMAGE;
else if (hasPDF)
return PostKind.PDF;
else if (hasTimeEnd)
return PostKind.COUNTDOWN;
else
return PostKind.TEXT;
}
@ -116,6 +121,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
onTap: _pickPDFForPost,
),
// Add countdown timer
_PostOptionWidget(
icon: Icons.timer,
selected: postKind == PostKind.COUNTDOWN,
onTap: _pickCountdownTime,
),
Expanded(
child: Container(),
),
@ -174,6 +186,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
setState(() {
_postImage = null;
_postPDF = null;
_timeEnd = null;
});
}
@ -211,6 +224,41 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
}
}
/// Pick countdown time
Future<void> _pickCountdownTime() async {
final initialDate =
_timeEnd == null ? DateTime.now().add(Duration(minutes: 1)) : _timeEnd;
// Pick date
final newDate = await showDatePicker(
context: context,
initialDate: initialDate,
firstDate: DateTime.now(),
lastDate: DateTime.now().add(Duration(days: 5000)));
if (newDate == null) return;
// Pick time
final newTime = await showTimePicker(
context: context,
initialTime: TimeOfDay.fromDateTime(initialDate),
);
if (newTime == null) return;
// Apply new selection
_resetPostSelection();
setState(() {
_timeEnd = newDate.add(Duration(
hours: newTime.hour - newDate.hour,
minutes: newTime.minute - newDate.minute));
print(newDate.toString());
print(newTime);
print(_timeEnd);
});
}
/// Submit new post
Future<void> _submitForm() async {
if (!canSubmitForm)
@ -227,6 +275,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
kind: postKind,
image: _postImage,
pdf: _postPDF,
timeEnd: _timeEnd,
));
setState(() => _isCreating = false);