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.
aku_new_community/lib/saas_model/login/picked_city_model.dart

48 lines
1.3 KiB

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()
@HiveType(typeId: 6)
3 years ago
class PickedCityModel {
@HiveField(0)
3 years ago
final ChinaRegionModel province;
@HiveField(1)
3 years ago
final ChinaRegionModel city;
@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 =
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;
}