|
- import 'package:farm_tpf/utils/const_common.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
-
- class Helpers {
- static void hideKeyboard(BuildContext context) {
- var currentFocus = FocusScope.of(context);
- if (!currentFocus.hasPrimaryFocus) {
- currentFocus.unfocus();
- }
- }
-
- static String getLetterInitial(String name) {
- try {
- var wordList = name.trim().split(' ');
- var letters = '';
- if (wordList.isEmpty) {
- letters = '';
- } else if (wordList.length == 1) {
- var firstWord = wordList[0];
- if (firstWord.characters.length > 1) {
- letters = wordList[0][0] + wordList[0][1];
- } else {
- letters = wordList[0][0];
- }
- } else {
- letters = wordList[0][0] + wordList[wordList.length - 1][0];
- }
- return letters.toUpperCase();
- } catch (_) {
- return '';
- }
- }
-
- static String getStampStatus(String status) {
- if (status.toUpperCase() == describeEnum(StampStatus.NEW)) {
- return 'Mới';
- } else if (status.toUpperCase() == describeEnum(StampStatus.ACTIVE)) {
- return 'Đã kích hoạt';
- } else if (status.toUpperCase() == describeEnum(StampStatus.CANCELED)) {
- return 'Đã huỷ';
- } else if (status.toUpperCase() == describeEnum(StampStatus.EXPIRED)) {
- return 'Hết hạn';
- }
- return '';
- }
-
- static String getTaskStatus(String status) {
- if (status.toLowerCase() == describeEnum(TaskStatus.completed)) {
- return 'Hoàn thành';
- } else if (status.toLowerCase() == describeEnum(TaskStatus.no_completed)) {
- return 'Chưa hoàn thành';
- }
- return '';
- }
-
- static bool isAfterToday(DateTime compareDate) {
- var now = DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day);
- var date = DateTime(compareDate.year, compareDate.month, compareDate.day);
- return date.isAfter(now);
- }
- }
|