generated from josiadmin/flutter-template-getx-provider
108 lines
2.8 KiB
Dart
108 lines
2.8 KiB
Dart
|
|
import 'dart:convert';
|
|
|
|
class TankModel {
|
|
final String documentId;
|
|
final String userId;
|
|
final String date;
|
|
final String odometer;
|
|
final String liters;
|
|
final String pricePerLiter;
|
|
final String location;
|
|
final String totalPrice;
|
|
TankModel({
|
|
required this.documentId,
|
|
required this.userId,
|
|
required this.date,
|
|
required this.odometer,
|
|
required this.liters,
|
|
required this.pricePerLiter,
|
|
required this.location,
|
|
required this.totalPrice,
|
|
});
|
|
|
|
TankModel copyWith({
|
|
String? documentId,
|
|
String? userId,
|
|
String? date,
|
|
String? odometer,
|
|
String? liters,
|
|
String? pricePerLiter,
|
|
String? location,
|
|
String? totalPrice,
|
|
}) {
|
|
return TankModel(
|
|
documentId: documentId ?? this.documentId,
|
|
userId: userId ?? this.userId,
|
|
date: date ?? this.date,
|
|
odometer: odometer ?? this.odometer,
|
|
liters: liters ?? this.liters,
|
|
pricePerLiter: pricePerLiter ?? this.pricePerLiter,
|
|
location: location ?? this.location,
|
|
totalPrice: totalPrice ?? this.totalPrice,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return <String, dynamic>{
|
|
'documentId': documentId,
|
|
'userId': userId,
|
|
'date': date,
|
|
'odometer': odometer,
|
|
'liters': liters,
|
|
'pricePerLiter': pricePerLiter,
|
|
'location': location,
|
|
'totalPrice': totalPrice,
|
|
};
|
|
}
|
|
|
|
factory TankModel.fromMap(Map<String, dynamic> map) {
|
|
return TankModel(
|
|
documentId: map['documentId'] as String,
|
|
userId: map['userId'] as String,
|
|
date: map['date'] as String,
|
|
odometer: map['odometer'] as String,
|
|
liters: map['liters'] as String,
|
|
pricePerLiter: map['pricePerLiter'] as String,
|
|
location: map['location'] as String,
|
|
totalPrice: map['totalPrice'] as String,
|
|
);
|
|
}
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
factory TankModel.fromJson(String source) => TankModel.fromMap(json.decode(source) as Map<String, dynamic>);
|
|
|
|
@override
|
|
String toString() {
|
|
return 'TankModel(documentId: $documentId, userId: $userId, date: $date, odometer: $odometer, liters: $liters, pricePerLiter: $pricePerLiter, location: $location, totalPrice: $totalPrice)';
|
|
}
|
|
|
|
@override
|
|
bool operator ==(covariant TankModel other) {
|
|
if (identical(this, other)) return true;
|
|
|
|
return
|
|
other.documentId == documentId &&
|
|
other.userId == userId &&
|
|
other.date == date &&
|
|
other.odometer == odometer &&
|
|
other.liters == liters &&
|
|
other.pricePerLiter == pricePerLiter &&
|
|
other.location == location &&
|
|
other.totalPrice == totalPrice;
|
|
}
|
|
|
|
@override
|
|
int get hashCode {
|
|
return documentId.hashCode ^
|
|
userId.hashCode ^
|
|
date.hashCode ^
|
|
odometer.hashCode ^
|
|
liters.hashCode ^
|
|
pricePerLiter.hashCode ^
|
|
location.hashCode ^
|
|
totalPrice.hashCode;
|
|
}
|
|
}
|