You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.9KB

  1. import 'package:farm_tpf/utils/const_common.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. class Helpers {
  5. static void hideKeyboard(BuildContext context) {
  6. var currentFocus = FocusScope.of(context);
  7. if (!currentFocus.hasPrimaryFocus) {
  8. currentFocus.unfocus();
  9. }
  10. }
  11. static String getLetterInitial(String name) {
  12. try {
  13. var wordList = name.trim().split(' ');
  14. var letters = '';
  15. if (wordList.isEmpty) {
  16. letters = '';
  17. } else if (wordList.length == 1) {
  18. var firstWord = wordList[0];
  19. if (firstWord.characters.length > 1) {
  20. letters = wordList[0][0] + wordList[0][1];
  21. } else {
  22. letters = wordList[0][0];
  23. }
  24. } else {
  25. letters = wordList[0][0] + wordList[wordList.length - 1][0];
  26. }
  27. return letters.toUpperCase();
  28. } catch (_) {
  29. return '';
  30. }
  31. }
  32. static String getStampStatus(String status) {
  33. if (status.toUpperCase() == describeEnum(StampStatus.NEW)) {
  34. return 'Mới';
  35. } else if (status.toUpperCase() == describeEnum(StampStatus.ACTIVE)) {
  36. return 'Đã kích hoạt';
  37. } else if (status.toUpperCase() == describeEnum(StampStatus.CANCELED)) {
  38. return 'Đã huỷ';
  39. } else if (status.toUpperCase() == describeEnum(StampStatus.EXPIRED)) {
  40. return 'Hết hạn';
  41. }
  42. return '';
  43. }
  44. static String getTaskStatus(String status) {
  45. if (status.toLowerCase() == describeEnum(TaskStatus.completed)) {
  46. return 'Hoàn thành';
  47. } else if (status.toLowerCase() == describeEnum(TaskStatus.no_completed)) {
  48. return 'Chưa hoàn thành';
  49. }
  50. return '';
  51. }
  52. static bool isAfterToday(DateTime compareDate) {
  53. var now = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day);
  54. var date = DateTime(compareDate.year, compareDate.month, compareDate.day);
  55. return date.isAfter(now);
  56. }
  57. }