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



@JsonSerializable() @JsonSerializable()
class Account { 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

..email = json['email'] as String ..email = json['email'] as String
..imageUrl = json['imageUrl'] as String ..imageUrl = json['imageUrl'] as String
..activated = json['activated'] as bool ..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; ..authorities = json['authorities'] as List;
} }


'email': instance.email, 'email': instance.email,
'imageUrl': instance.imageUrl, 'imageUrl': instance.imageUrl,
'activated': instance.activated, '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, 'authorities': instance.authorities,
}; };

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

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

import 'package:farm_tpf/custom_model/LocationUnit.dart';
import 'package:farm_tpf/custom_model/account.dart'; import 'package:farm_tpf/custom_model/account.dart';
import 'package:farm_tpf/data/repository/user_repository.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_loading.dart';
import 'package:farm_tpf/presentation/custom_widgets/widget_toast.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/actions/state_management_helper/change_supply.dart';
import 'package:farm_tpf/presentation/screens/location_unit/sc_location.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/presentation/screens/profile/sc_change_password.dart';
import 'package:farm_tpf/utils/const_color.dart'; import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/const_common.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/const_style.dart';
import 'package:farm_tpf/utils/validators.dart'; import 'package:farm_tpf/utils/validators.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
TextEditingController _fullNameController = TextEditingController(); TextEditingController _fullNameController = TextEditingController();
TextEditingController _emailController = TextEditingController(); TextEditingController _emailController = TextEditingController();
TextEditingController _addressController = TextEditingController(); TextEditingController _addressController = TextEditingController();
var checkChangeLocation = Get.put(CheckChangeAnotherDropdown());


PackageInfo _packageInfo = PackageInfo( PackageInfo _packageInfo = PackageInfo(
version: '1.0.0', version: '1.0.0',
@override @override
void initState() { void initState() {
super.initState(); super.initState();
checkChangeLocation.initValue();
_initPackageInfo(); _initPackageInfo();
flutterToast = FlutterToast(context); flutterToast = FlutterToast(context);
getAccountBloc.getAccount((data) { getAccountBloc.getAccount((data) {
_fullNameController.text = _account.fullName.toString(); _fullNameController.text = _account.fullName.toString();
_emailController.text = _account.email.toString(); _emailController.text = _account.email.toString();
_addressController.text = _account.address; _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) { }, (err) {
flutterToast.showToast(child: WidgetToast(message: "Lỗi tải dữ liệu")); flutterToast.showToast(child: WidgetToast(message: "Lỗi tải dữ liệu"));
}); });
} }


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


Widget _btnSelectProvince() { Widget _btnSelectProvince() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton( return FlatButton(
padding: padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () { 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( child: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
children: [ children: [
GetBuilder<ChangeSupply>( GetBuilder<ChangeSupply>(
builder: (_) => Expanded( builder: (_) => Expanded(
child: Text("sdfd" ?? "Tỉnh/Thành Phố",
child: Text(
checkChangeLocation.currentProvince.name ??
"Tỉnh/Thành Phố",
style: TextStyle( style: TextStyle(
fontSize: 14.0, color: Colors.black87)))), fontSize: 14.0, color: Colors.black87)))),
Icon( Icon(
} }


Widget _btnSelectDistrict() { Widget _btnSelectDistrict() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton( return FlatButton(
padding: padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () { 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( child: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
children: [ children: [
GetBuilder<ChangeSupply>( GetBuilder<ChangeSupply>(
builder: (_) => Expanded( builder: (_) => Expanded(
child: Text("sdfd" ?? "Quận/Huyện",
child: Text(
checkChangeLocation.currentDistrict.name ??
"Quận/Huyện",
style: TextStyle( style: TextStyle(
fontSize: 14.0, color: Colors.black87)))), fontSize: 14.0, color: Colors.black87)))),
Icon( Icon(
} }


Widget _btnSelectWard() { Widget _btnSelectWard() {
return GetBuilder<ChangeSupply>(builder: (data) {
return GetBuilder<CheckChangeAnotherDropdown>(builder: (data) {
return FlatButton( return FlatButton(
padding: padding:
EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0), EdgeInsets.only(top: 0.0, right: 0.0, bottom: 0.0, left: 0.0),
onPressed: () { 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( child: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
children: [ children: [
GetBuilder<ChangeSupply>( GetBuilder<ChangeSupply>(
builder: (_) => Expanded( builder: (_) => Expanded(
child: Text("sdfd" ?? "Phường/Xã",
child: Text(
checkChangeLocation.currentWard.name ??
"Phường/Xã",
style: TextStyle( style: TextStyle(
fontSize: 14.0, color: Colors.black87)))), fontSize: 14.0, color: Colors.black87)))),
Icon( Icon(

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

const String label_file_to_large = "Kích thước tập tin quá lớn"; 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_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 //Exception
const String exception_common = "Đã có lỗi xảy ra"; const String exception_common = "Đã có lỗi xảy ra";
const String exception_dio_cancle = "Truy vấn đến máy chủ bị huỷ"; const String exception_dio_cancle = "Truy vấn đến máy chủ bị huỷ";

Loading…
Cancel
Save