Files
be_happy_public/lib/presentation/components/scooter/scooter_info_section.dart
2026-07-13 01:38:13 +03:00

87 lines
2.7 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:flutter/material.dart';
import 'scooter_info_item.dart';
class ScooterInfoSection extends StatelessWidget {
final double distance;
final String 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: '$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',
),
const SizedBox(width: 16),
ScooterInfoItem(
icon: 'assets/icons/time.png',
text: walkingText,
),
],
),
],
);
}
}