This commit is contained in:
2026-07-13 01:38:13 +03:00
parent 9eda119527
commit 98c5a7a1d1
54 changed files with 860 additions and 454 deletions

View File

@@ -4,22 +4,81 @@ import 'scooter_info_item.dart';
class ScooterInfoSection extends StatelessWidget {
final double distance;
final String location;
const ScooterInfoSection({super.key, required this.distance, required this.location});
final int batteryLevel;
const ScooterInfoSection({
super.key,
required this.distance,
required this.location,
required this.batteryLevel,
});
@override
Widget build(BuildContext context) {
// 1. Расчет оставшегося расстояния (макс. 62 км)
final double remainingKm = (62 * batteryLevel) / 100;
// Красиво форматируем: если число целое — убираем точку (например, 31 км вместо 31.0 км)
final String kmText = remainingKm % 1 == 0
? '${remainingKm.toInt()} км'
: '${remainingKm.toStringAsFixed(1)} км';
// 2. Расчет оставшегося времени (макс. 2.5 часа = 150 минут)
final int totalMinutes = ((150 * batteryLevel) / 100).round();
final int hours = totalMinutes ~/ 60;
final int minutes = totalMinutes % 60;
// Формируем строку времени в зависимости от получившихся значений
String timeText = '';
if (hours > 0 && minutes > 0) {
timeText = '$hours ч $minutes мин';
} else if (hours > 0) {
timeText = '$hours ч';
} else {
timeText = '$minutes мин';
}
final int walkingMinutes = (distance / 80).round().clamp(1, 999);
final int walkHours = walkingMinutes ~/ 60;
final int walkMins = walkingMinutes % 60;
String walkingText = '';
if (walkHours > 0 && walkMins > 0) {
walkingText = '$walkHours ч $walkMins мин';
} else if (walkHours > 0) {
walkingText = '$walkHours ч';
} else {
walkingText = '$walkingMinutes мин';
}
return Column(
children: [
ScooterInfoItem(icon: 'assets/icons/bolt.png', text: '47 км или 4 часа 17 минут'),
ScooterInfoItem(icon: 'assets/icons/speed.png', text: 'max = 25 км/ч'),
ScooterInfoItem(icon: 'assets/icons/location.png', text: location),
// Динамическая строка с зарядом
ScooterInfoItem(
icon: 'assets/icons/bolt.png',
text: '$kmText или $timeText',
),
ScooterInfoItem(
icon: 'assets/icons/speed.png',
text: 'max = 25 км/ч',
),
ScooterInfoItem(
icon: 'assets/icons/location.png',
text: location,
),
Row(
children: [
ScooterInfoItem(icon: 'assets/icons/person.png', text: distance.toInt() >= 1000
? '${((distance.toInt()) / 1000).toStringAsFixed(1)} km'
: '${distance.toInt()} m',),
SizedBox(width: 16),
ScooterInfoItem(icon: 'assets/icons/time.png', text: '1 минута'),
ScooterInfoItem(
icon: 'assets/icons/person.png',
text: distance.toInt() >= 1000
? '${((distance.toInt()) / 1000).toStringAsFixed(1)} km'
: '${distance.toInt()} m',
),
const SizedBox(width: 16),
ScooterInfoItem(
icon: 'assets/icons/time.png',
text: walkingText,
),
],
),
],