You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
3 years ago
|
import 'package:aku_new_community/utils/hive_store.dart';
|
||
|
import 'package:hive/hive.dart';
|
||
3 years ago
|
import 'package:json_annotation/json_annotation.dart';
|
||
|
|
||
|
import 'china_region_model.dart';
|
||
|
|
||
|
part 'picked_city_model.g.dart';
|
||
|
|
||
|
@JsonSerializable()
|
||
3 years ago
|
@HiveType(typeId: 6)
|
||
3 years ago
|
class PickedCityModel {
|
||
3 years ago
|
@HiveField(0)
|
||
3 years ago
|
final ChinaRegionModel province;
|
||
3 years ago
|
@HiveField(1)
|
||
3 years ago
|
final ChinaRegionModel city;
|
||
3 years ago
|
@HiveField(2)
|
||
3 years ago
|
final ChinaRegionModel district;
|
||
|
factory PickedCityModel.fromJson(Map<String, dynamic> json) =>
|
||
|
_$PickedCityModelFromJson(json);
|
||
|
|
||
|
const PickedCityModel({
|
||
|
required this.province,
|
||
|
required this.city,
|
||
|
required this.district,
|
||
|
});
|
||
|
factory PickedCityModel.fromId(
|
||
|
{required int provinceId, required int cityId, required int distrctId}) {
|
||
|
var provinces =
|
||
3 years ago
|
HiveStore.dataBox!.get('cities').cast<ChinaRegionModel>().toList();
|
||
3 years ago
|
final _province =
|
||
|
provinces.firstWhere((element) => element.id == provinceId);
|
||
|
final _city =
|
||
|
_province.cityList.firstWhere((element) => element.id == cityId);
|
||
|
final _district =
|
||
|
_city.cityList.firstWhere((element) => element.id == distrctId);
|
||
|
|
||
|
return PickedCityModel(
|
||
|
province: _province,
|
||
|
city: _city,
|
||
|
district: _district,
|
||
|
);
|
||
|
}
|
||
|
|
||
|
String get address => province.name + city.name + district.name;
|
||
|
|
||
|
int get id => district.id;
|
||
|
}
|