2024-12-21 22:56:48 +04:00

43 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:course_work/components/locale/l10n/app_localizations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class Formatter {
static String formatPrice(int price) {
return '${NumberFormat.decimalPattern('ru').format(price)}';
}
static IconData getStarIconForRating(double? rating) {
if (rating == null) {
return Icons.star_border;
}
if (rating == 0.0) {
return Icons.star_border;
}
if (rating < 5) {
return Icons.star_half;
}
return Icons.star;
}
static String getReviewString(AppLocale locale, int reviewCount) {
switch (locale.localeName) {
case 'ru':
if (reviewCount % 10 == 0 || (reviewCount % 100 >= 10 && reviewCount % 100 <= 20) || (reviewCount % 10 >= 5 && reviewCount % 10 <= 9)) {
return '${locale.apiReviewCount}ов';
}
if (reviewCount % 10 >= 2 && reviewCount % 10 <= 4) {
return '${locale.apiReviewCount}а';
}
return locale.apiReviewCount;
case 'en':
if (reviewCount == 1) {
return locale.apiReviewCount;
}
return '${locale.apiReviewCount}s';
default:
return locale.apiReviewCount;
}
}
}