43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|