73 lines
1.5 KiB
Dart
73 lines
1.5 KiB
Dart
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
class ShippingRate {
|
|
String name;
|
|
double price;
|
|
List<Rate> rates;
|
|
|
|
ShippingRate.fromJson(Map<String, dynamic> json)
|
|
: name = json['name'],
|
|
price = double.parse(json['price'].toString()),
|
|
rates = (json['rates'] as List).map((e) => Rate.fromJson(e)).toList();
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'name': name,
|
|
'price': price,
|
|
'rates': rates,
|
|
};
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is ShippingRate &&
|
|
runtimeType == other.runtimeType &&
|
|
name == other.name &&
|
|
price.toStringAsFixed(2) == other.price.toStringAsFixed(2) &&
|
|
listEquals(rates, other.rates);
|
|
|
|
@override
|
|
String toString() {
|
|
return json.encode(this);
|
|
}
|
|
|
|
@override
|
|
int get hashCode =>
|
|
name.hashCode ^
|
|
price.hashCode ^
|
|
rates.hashCode;
|
|
}
|
|
|
|
class Rate {
|
|
String name;
|
|
double rate;
|
|
|
|
Rate.fromJson(Map<String, dynamic> json)
|
|
: name = json['name'],
|
|
rate = double.parse(json['rate'].toString());
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'name': name,
|
|
'rate': rate,
|
|
};
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
identical(this, other) ||
|
|
other is Rate &&
|
|
runtimeType == other.runtimeType &&
|
|
name == other.name &&
|
|
rate.toStringAsFixed(2) == other.rate.toStringAsFixed(2);
|
|
|
|
@override
|
|
String toString() {
|
|
return json.encode(this);
|
|
}
|
|
|
|
@override
|
|
int get hashCode =>
|
|
name.hashCode ^
|
|
rate.hashCode;
|
|
} |