exts.dart 748 B

123456789101112131415161718192021222324252627282930
  1. extension MapExt<K, V> on Map<K, V> {
  2. T? getCheck<T>(K? key) {
  3. if (key == null || !containsKey(key)) {
  4. return null;
  5. }
  6. var value = this[key];
  7. if (value is! T) {
  8. return null;
  9. }
  10. return value as T?;
  11. }
  12. }
  13. extension StringExt on String? {
  14. bool get isNullOrEmpty {
  15. return this == null || this!.isEmpty;
  16. }
  17. }
  18. extension ListExt<T> on List<T>? {
  19. bool get isNullOrEmpty {
  20. return this == null || this!.isEmpty;
  21. }
  22. }
  23. extension DateTimeExt on DateTime {
  24. String get yyyyMMddHHmmss =>
  25. "$year-${month < 10 ? "$month".padLeft(2, "0") : month}-$day ${hour < 10 ? "$hour".padLeft(2, "0") : hour}:${minute < 10 ? "$minute".padLeft(2, "0") : minute}:${second < 10 ? "$second".padLeft(2, "0") : second}";
  26. }