Browse Source

parse location from api

master
daivph 5 years ago
parent
commit
09ea4d35c4
5 changed files with 228 additions and 64 deletions
  1. +30
    -21
      lib/custom_model/account.dart
  2. +16
    -0
      lib/custom_model/account.g.dart
  3. +76
    -0
      lib/presentation/screens/profile/controller/check_change_another_dropdown.dart
  4. +99
    -43
      lib/presentation/screens/profile/sc_update_profile.dart
  5. +7
    -0
      lib/utils/const_string.dart

+ 30
- 21
lib/custom_model/account.dart View File

@@ -4,26 +4,35 @@ part 'account.g.dart';

@JsonSerializable()
class Account {
Account();
Account();

num id;
String login;
String firstName;
String lastName;
String midleName;
String fullName;
String telephone;
String address;
String avartar;
num vaiTroId;
String tenVaiTro;
num donViCanhTacId;
String tenDonVi;
String email;
String imageUrl;
bool activated;
List authorities;
factory Account.fromJson(Map<String,dynamic> json) => _$AccountFromJson(json);
Map<String, dynamic> toJson() => _$AccountToJson(this);
num id;
String login;
String firstName;
String lastName;
String midleName;
String fullName;
String telephone;
String address;
String avartar;
num vaiTroId;
String tenVaiTro;
num donViCanhTacId;
String tenDonVi;
String email;
String imageUrl;
bool activated;
int countryId;
String countryName;
int cityId;
String cityName;
int districtId;
String districtName;
int wardId;
String wardName;
List authorities;

factory Account.fromJson(Map<String, dynamic> json) =>
_$AccountFromJson(json);
Map<String, dynamic> toJson() => _$AccountToJson(this);
}

+ 16
- 0
lib/custom_model/account.g.dart View File

@@ -24,6 +24,14 @@ Account _$AccountFromJson(Map<String, dynamic> json) {
..email = json['email'] as String
..imageUrl = json['imageUrl'] as String
..activated = json['activated'] as bool
..countryId = json['countryId'] as num
..countryName = json['countryName'] as String
..cityId = json['cityId'] as num
..cityName = json['cityName'] as String
..districtId = json['districtId'] as num
..districtName = json['districtName'] as String
..wardId = json['wardId'] as num
..wardName = json['wardName'] as String
..authorities = json['authorities'] as List;
}

@@ -44,5 +52,13 @@ Map<String, dynamic> _$AccountToJson(Account instance) => <String, dynamic>{
'email': instance.email,
'imageUrl': instance.imageUrl,
'activated': instance.activated,
'countryId': instance.countryId,
'countryName': instance.countryName,
'cityId': instance.cityId,
'cityName': instance.cityName,
'districtId': instance.districtId,
'districtName': instance.districtName,
'wardId': instance.wardId,
'wardName': instance.wardName,
'authorities': instance.authorities,
};

+ 76
- 0
lib/presentation/screens/profile/controller/check_change_another_dropdown.dart View File

@@ -0,0 +1,76 @@
import 'package:farm_tpf/custom_model/LocationUnit.dart';
import 'package:get/state_manager.dart';

class CheckChangeAnotherDropdown extends GetxController {
LocationUnit currentCountry;
LocationUnit currentProvince;
LocationUnit currentDistrict;
LocationUnit currentWard;

void initValue() {
currentCountry = LocationUnit();
currentProvince = LocationUnit();
currentDistrict = LocationUnit();
currentWard = LocationUnit();
}

void changeCountry(LocationUnit country) {
currentCountry = country;
currentProvince = LocationUnit();
currentDistrict = LocationUnit();
currentWard = LocationUnit();
update();
}

void changeCountryByIdAndName(int id, String name) {
currentCountry = LocationUnit()
..id = id
..name = name;
currentProvince = LocationUnit();
currentDistrict = LocationUnit();
currentWard = LocationUnit();
update();
}

void changeProvince(LocationUnit province) {
currentProvince = province;
currentDistrict = LocationUnit();
currentWard = LocationUnit();
update();
}

void changeProvinceByIdAndName(int id, String name) {
currentProvince = LocationUnit()
..id = id
..name = name;
currentDistrict = LocationUnit();
currentWard = LocationUnit();
update();
}

void changeDistrict(LocationUnit district) {
currentDistrict = district;
currentWard = LocationUnit();
update();
}

void changeDistrictByIdAndName(int id, String name) {
currentDistrict = LocationUnit()
..id = id
..name = name;
currentWard = LocationUnit();
update();
}

void changeWard(LocationUnit ward) {
currentWard = ward;
update();
}

void changeWardByIdAndName(int id, String name) {
currentWard = LocationUnit()
..id = id
..name = name;
update();
}
}

+ 99
- 43
lib/presentation/screens/profile/sc_update_profile.dart View File

@@ -1,12 +1,15 @@
import 'package:farm_tpf/custom_model/LocationUnit.dart';
import 'package:farm_tpf/custom_model/account.dart';
import 'package:farm_tpf/data/repository/user_repository.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_toast.dart';
import 'package:farm_tpf/presentation/screens/actions/state_management_helper/change_supply.dart';
import 'package:farm_tpf/presentation/screens/location_unit/sc_location.dart';
import 'package:farm_tpf/presentation/screens/profile/controller/check_change_another_dropdown.dart';
import 'package:farm_tpf/presentation/screens/profile/sc_change_password.dart';
import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_string.dart';
import 'package:farm_tpf/utils/const_style.dart';
import 'package:farm_tpf/utils/validators.dart';
import 'package:flutter/material.dart';
@@ -38,6 +41,7 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
TextEditingController _fullNameController = TextEditingController();
TextEditingController _emailController = TextEditingController();
TextEditingController _addressController = TextEditingController();
var checkChangeLocation = Get.put(CheckChangeAnotherDropdown());

PackageInfo _packageInfo = PackageInfo(
version: '1.0.0',
@@ -54,6 +58,7 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
@override
void initState() {
super.initState();
checkChangeLocation.initValue();
_initPackageInfo();
flutterToast = FlutterToast(context);
getAccountBloc.getAccount((data) {
@@ -62,6 +67,14 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
_fullNameController.text = _account.fullName.toString();
_emailController.text = _account.email.toString();
_addressController.text = _account.address;
checkChangeLocation.changeCountryByIdAndName(
_account.countryId, _account.countryName);
checkChangeLocation.changeProvinceByIdAndName(
_account.cityId, _account.cityName);
checkChangeLocation.changeDistrictByIdAndName(
_account.districtId, _account.districtName);
checkChangeLocation.changeWardByIdAndName(
_account.wardId, _account.wardName);
}, (err) {
flutterToast.showToast(child: WidgetToast(message: "Lỗi tải dữ liệu"));
});
@@ -146,21 +159,27 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
}

Widget _btnSelectCountry() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton(
padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {
if (Get.isSnackbarOpen) {
Get.back();
}
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Quốc gia",
type: LocationType.country,
filterId: null,
selectedId: null),
selectedId: checkChangeLocation.currentCountry.id),
fullscreenDialog: false))
.then((value) {
if (value != null) {}
if (value != null) {
var result = value as LocationUnit;
checkChangeLocation.changeCountry(result);
}
});
},
child: Container(
@@ -173,7 +192,9 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
children: [
GetBuilder<ChangeSupply>(
builder: (_) => Expanded(
child: Text("sdfd" ?? "Quốc gia",
child: Text(
checkChangeLocation.currentCountry.name ??
"Quốc gia",
style: TextStyle(
fontSize: 14.0, color: Colors.black87)))),
Icon(
@@ -186,22 +207,33 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
}

Widget _btnSelectProvince() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton(
padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Tỉnh/Thành phố",
type: LocationType.province,
filterId: 1,
selectedId: null),
fullscreenDialog: false))
.then((value) {
if (value != null) {}
});
if (Get.isSnackbarOpen) {
Get.back();
}
if (checkChangeLocation.currentCountry.id != null) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Tỉnh/Thành phố",
type: LocationType.province,
filterId: checkChangeLocation.currentCountry.id,
selectedId: checkChangeLocation.currentProvince.id),
fullscreenDialog: false))
.then((value) {
if (value != null) {
var result = value as LocationUnit;
checkChangeLocation.changeProvince(result);
}
});
} else {
Get.snackbar(label_country_empty, label_country_empty_message,
snackPosition: SnackPosition.BOTTOM);
}
},
child: Container(
padding: EdgeInsets.only(
@@ -213,7 +245,9 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
children: [
GetBuilder<ChangeSupply>(
builder: (_) => Expanded(
child: Text("sdfd" ?? "Tỉnh/Thành Phố",
child: Text(
checkChangeLocation.currentProvince.name ??
"Tỉnh/Thành Phố",
style: TextStyle(
fontSize: 14.0, color: Colors.black87)))),
Icon(
@@ -226,22 +260,31 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
}

Widget _btnSelectDistrict() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton(
padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Quận/Huyện",
type: LocationType.district,
filterId: 79,
selectedId: null),
fullscreenDialog: false))
.then((value) {
if (value != null) {}
});
if (Get.isSnackbarOpen) Get.back();
if (checkChangeLocation.currentProvince.id != null) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Quận/Huyện",
type: LocationType.district,
filterId: checkChangeLocation.currentProvince.id,
selectedId: checkChangeLocation.currentDistrict.id),
fullscreenDialog: false))
.then((value) {
if (value != null) {
var result = value as LocationUnit;
checkChangeLocation.changeDistrict(result);
}
});
} else {
Get.snackbar(label_province_empty, label_province_empty_message,
snackPosition: SnackPosition.BOTTOM);
}
},
child: Container(
padding: EdgeInsets.only(
@@ -253,7 +296,9 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
children: [
GetBuilder<ChangeSupply>(
builder: (_) => Expanded(
child: Text("sdfd" ?? "Quận/Huyện",
child: Text(
checkChangeLocation.currentDistrict.name ??
"Quận/Huyện",
style: TextStyle(
fontSize: 14.0, color: Colors.black87)))),
Icon(
@@ -266,22 +311,31 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
}

Widget _btnSelectWard() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton(
padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Phường/Xã",
type: LocationType.ward,
filterId: 760,
selectedId: null),
fullscreenDialog: false))
.then((value) {
if (value != null) {}
});
if (Get.isSnackbarOpen) Get.back();
if (checkChangeLocation.currentDistrict.id != null) {
Navigator.of(context)
.push(MaterialPageRoute(
builder: (_) => LocationScreen(
titleName: "Phường/Xã",
type: LocationType.ward,
filterId: checkChangeLocation.currentDistrict.id,
selectedId: checkChangeLocation.currentWard.id),
fullscreenDialog: false))
.then((value) {
if (value != null) {
var result = value as LocationUnit;
checkChangeLocation.changeWard(result);
}
});
} else {
Get.snackbar(label_district_empty, label_district_empty_message,
snackPosition: SnackPosition.BOTTOM);
}
},
child: Container(
padding: EdgeInsets.only(
@@ -293,7 +347,9 @@ class _UpdateProfileScreenState extends State<UpdateProfileScreen> {
children: [
GetBuilder<ChangeSupply>(
builder: (_) => Expanded(
child: Text("sdfd" ?? "Phường/Xã",
child: Text(
checkChangeLocation.currentWard.name ??
"Phường/Xã",
style: TextStyle(
fontSize: 14.0, color: Colors.black87)))),
Icon(

+ 7
- 0
lib/utils/const_string.dart View File

@@ -39,6 +39,13 @@ const String label_add_success = "Thêm thành công";
const String label_file_to_large = "Kích thước tập tin quá lớn";
const String label_file_size_suggest = "Vui lòng chọn tập tin nhỏ hơn 1024 Kb";

const String label_country_empty = "Vui lòng chọn Quốc gia";
const String label_country_empty_message = "Quốc gia đang trống";
const String label_province_empty = "Vui lòng chọn Tỉnh/thành phố";
const String label_province_empty_message = "Tỉnh/thành phố đang trống";
const String label_district_empty = "Vui lòng chọn Quận/Huyện";
const String label_district_empty_message = "Quận/Huyện đang trống";

//Exception
const String exception_common = "Đã có lỗi xảy ra";
const String exception_dio_cancle = "Truy vấn đến máy chủ bị huỷ";

Loading…
Cancel
Save