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.

33 lines
832B

  1. import 'package:flutter/material.dart';
  2. class Helpers {
  3. static void hideKeyboard(BuildContext context) {
  4. var currentFocus = FocusScope.of(context);
  5. if (!currentFocus.hasPrimaryFocus) {
  6. currentFocus.unfocus();
  7. }
  8. }
  9. static String getLetterInitial(String name) {
  10. try {
  11. var wordList = name.trim().split(' ');
  12. var letters = '';
  13. if (wordList.isEmpty) {
  14. letters = '';
  15. } else if (wordList.length == 1) {
  16. var firstWord = wordList[0];
  17. if (firstWord.characters.length > 1) {
  18. letters = wordList[0][0] + wordList[0][1];
  19. } else {
  20. letters = wordList[0][0];
  21. }
  22. } else {
  23. letters = wordList[0][0] + wordList[wordList.length - 1][0];
  24. }
  25. return letters.toUpperCase();
  26. } catch (_) {
  27. return '';
  28. }
  29. }
  30. }