common_expand.dart 778 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'dart:ui';
  2. extension HexColor on String {
  3. Color get color => toColor();
  4. Color toColor() {
  5. String hex = replaceAll('#', '');
  6. if (hex.length == 6) {
  7. hex = 'FF$hex';
  8. }
  9. return Color(int.parse(hex, radix: 16));
  10. }
  11. }
  12. extension DoubleExtension on double {
  13. String toFormattedString(int fractionDigits) {
  14. if (this == toInt()) {
  15. return toInt().toString();
  16. } else {
  17. return toStringAsFixed(fractionDigits);
  18. }
  19. }
  20. double toFormattedDouble(int fractionDigits) {
  21. return double.parse(toStringAsFixed(fractionDigits));
  22. }
  23. }
  24. extension TrimAllExtension on String {
  25. String trimAll() {
  26. return replaceAll(RegExp(r'\s+'), '');
  27. }
  28. String trimAndReduceSpaces() {
  29. return trim().replaceAll(RegExp(r'\s+'), ' ');
  30. }
  31. }