Files
be_happy_public/lib/domain/entities/fine.dart
Polyanka 182be1049b some fix
# Conflicts:
#	lib/presentation/navigation/app_router.dart
#	pubspec.yaml
2026-08-11 00:23:16 +03:00

76 lines
2.1 KiB
Dart

import 'package:equatable/equatable.dart';
class Fine extends Equatable {
final int id;
final String scooterNumber;
final String date;
final String description;
final double amount;
final String amountPrint;
final List<String> photoUrls;
final bool isPaid;
const Fine({
required this.id,
required this.scooterNumber,
required this.date,
required this.description,
required this.amount,
required this.amountPrint,
required this.photoUrls,
required this.isPaid,
});
factory Fine.fromJson(Map<String, dynamic> json, {String? scooterNumber}) {
final List<dynamic> filesJson = json['files'] ?? [];
final List<String> photos = filesJson
.map((file) => file['path'] as String? ?? file['filename'] as String? ?? '')
.where((path) => path.isNotEmpty)
.toList();
// Форматирование даты из createdAt (2026-08-07T09:15:26.565Z -> 07-08-2026)
String formattedDate = '';
if (json['createdAt'] != null) {
final parsedDate = DateTime.tryParse(json['createdAt'].toString());
if (parsedDate != null) {
final day = parsedDate.day.toString().padLeft(2, '0');
final month = parsedDate.month.toString().padLeft(2, '0');
final year = parsedDate.year;
formattedDate = '$day-$month-$year';
}
}
return Fine(
id: json['id'] as int? ?? 0,
scooterNumber: scooterNumber ?? '',
date: formattedDate,
description: json['description'] as String? ?? '',
amount: (json['value'] as num?)?.toDouble() ?? 0.0,
amountPrint: json['valuePrint'] as String? ?? '0,00 BYN',
photoUrls: photos,
isPaid: json['isPaid'] as bool? ?? false,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'description': description,
'value': amount,
'valuePrint': amountPrint,
'isPaid': isPaid,
};
}
@override
List<Object?> get props => [
id,
scooterNumber,
date,
description,
amount,
amountPrint,
photoUrls,
isPaid,
];
}