This commit is contained in:
2026-07-12 04:33:48 +08:00
parent f8a90ad305
commit e7ce0f7bae
151 changed files with 2765 additions and 2947 deletions

View File

@@ -13,15 +13,15 @@ import 'package:flutter_wisetronic/store/store.dart';
import 'package:flutter_wisetronic/utils/http_util.dart';
import 'package:flutter_wisetronic/utils/utils.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gender_selection/gender_selection.dart';
import 'package:gender_picker/gender_picker.dart';
import 'package:gender_picker/source/enums.dart';
import '../../routes.dart';
class MobileEditAddress extends StatefulWidget {
final Key key;
final Address address;
final int businessId;
const MobileEditAddress(this.address, {this.key, int businessId}) :
final Address? address;
final int? businessId;
const MobileEditAddress(this.address, {Key? key, int? businessId}) :
businessId = businessId ?? Constants.BUSINESS_ID;
@override
@@ -43,12 +43,12 @@ class MobileEditAddressState extends State<MobileEditAddress> {
final emailController = TextEditingController();
final faxController = TextEditingController();
String country;
Gender _selectedGender;
String? country;
Gender? _selectedGender;
String _selectedProvince;
String? _selectedProvince;
bool showLoading;
bool showLoading = false;
@override
Widget build(BuildContext context) {
@@ -109,8 +109,8 @@ class MobileEditAddressState extends State<MobileEditAddress> {
.of(context)
.contact_name,
),
validator: (String value) {
if (value
validator: (String? value) {
if (value == null || value
.trim()
.isEmpty) {
return S
@@ -121,27 +121,25 @@ class MobileEditAddressState extends State<MobileEditAddress> {
},
),
),
GenderSelection(
maleText: S
.of(context)
.mr,
femaleText: S
.of(context)
.ms,
selectedGenderIconBackgroundColor: Colors.indigo,
checkIconAlignment: Alignment.bottomRight,
selectedGenderCheckIcon: Icons.check,
onChanged: (Gender gender) {
GenderPickerWithImage(
onChanged: (Gender? gender) {
_selectedGender = gender;
},
equallyAligned: true,
animationDuration: Duration(milliseconds: 400),
isCircular: true,
isSelectedGenderIconCircular: true,
opacityOfGradient: 0.6,
padding: const EdgeInsets.all(3.0),
size: 50,
maleText: S.of(context).mr,
femaleText: S.of(context).ms,
selectedGender: _selectedGender,
showOtherGender: false,
verticalAlignedText: false,
selectedGenderTextStyle: TextStyle(
color: Color(0xFF8b32a8), fontWeight: FontWeight.bold),
unSelectedGenderTextStyle: TextStyle(
color: Colors.white, fontWeight: FontWeight.normal),
equallyAligned: true,
animationDuration: Duration(milliseconds: 200),
isCircular: true,
opacityOfGradient: 0.5,
padding: const EdgeInsets.all(3),
size: 50,
),
Container(
padding: EdgeInsets.only(
@@ -164,8 +162,8 @@ class MobileEditAddressState extends State<MobileEditAddress> {
.of(context)
.mobile_phone_number,
),
validator: (String value) {
if (value
validator: (String? value) {
if (value == null || value
.trim()
.isEmpty) {
return S
@@ -196,8 +194,8 @@ class MobileEditAddressState extends State<MobileEditAddress> {
.of(context)
.street_line_1,
),
validator: (String value) {
if (value
validator: (String? value) {
if (value == null || value
.trim()
.isEmpty) {
return S
@@ -250,8 +248,8 @@ class MobileEditAddressState extends State<MobileEditAddress> {
.of(context)
.city,
),
validator: (String value) {
if (value
validator: (String? value) {
if (value == null || value
.trim()
.isEmpty) {
return S
@@ -320,8 +318,8 @@ class MobileEditAddressState extends State<MobileEditAddress> {
.of(context)
.postal_code,
),
validator: (String value) {
if (value
validator: (String? value) {
if (value == null || value
.trim()
.isEmpty) {
return S
@@ -365,8 +363,8 @@ class MobileEditAddressState extends State<MobileEditAddress> {
.of(context)
.email,
),
validator: (String value) {
if (value.isNotEmpty && !EmailValidator.validate(value)) {
validator: (String? value) {
if (value != null && value.isNotEmpty && !EmailValidator.validate(value)) {
return S
.of(context)
.email_is_not_valid;
@@ -472,43 +470,43 @@ class MobileEditAddressState extends State<MobileEditAddress> {
super.initState();
setState(() {
showLoading = false;
_selectedProvince = widget.address.state;
cityController.text = widget.address.city;
postalCodeController.text = widget.address.zip;
streetLine1Controller.text = widget.address.addressLine1;
streetLine2Controller.text = widget.address.addressLine2;
_selectedGender = widget.address.gender == 1 ? Gender.Male : Gender.Female;
country = widget.address.country;
contactNameController.text = widget.address.contactName;
phoneController.text = widget.address.phone;
emailController.text = widget.address.email;
faxController.text = widget.address.fax;
_selectedProvince = widget.address?.state;
cityController.text = widget.address?.city ?? '';
postalCodeController.text = widget.address?.zip ?? '';
streetLine1Controller.text = widget.address?.addressLine1 ?? '';
streetLine2Controller.text = widget.address?.addressLine2 ?? '';
_selectedGender = widget.address?.gender == 1 ? Gender.Male : Gender.Female;
country = widget.address?.country;
contactNameController.text = widget.address?.contactName ?? '';
phoneController.text = widget.address?.phone ?? '';
emailController.text = widget.address?.email ?? '';
faxController.text = widget.address?.fax ?? '';
});
}
void _saveEditAddress() {
final FormState form = _formKey.currentState;
if (form.validate()) {
final FormState? form = _formKey.currentState;
if (form != null && form.validate()) {
if (mounted) {
setState(() {
showLoading = true;
});
}
HttpUtil.httpPatch('v1/addresses/${widget.address.id}', (response) {
HttpUtil.httpPatch('v1/addresses/${widget.address?.id}', (response) {
if (mounted) {
setState(() {
showLoading = false;
});
}
eventBus.fire(OnAddressesUpdated());
if (widget.businessId > 0) {
if (widget.businessId != null && widget.businessId! > 0) {
Routes.router.navigateTo(context, '/checkout/${widget.businessId}', replace: true);
} else {
Navigator.of(context).pop();
}
},
body: {
'id': widget.address.id,
'id': widget.address?.id,
'name': contactNameController.text.trim(),
'address_line1': streetLine1Controller.text.trim(),
'address_line2': streetLine2Controller.text.trim(),
@@ -538,7 +536,7 @@ class MobileEditAddressState extends State<MobileEditAddress> {
showLoading = true;
});
}
HttpUtil.httpDelete('v1/addresses/${widget.address.id}', (response) {
HttpUtil.httpDelete('v1/addresses/${widget.address?.id}', (response) {
if (mounted) {
setState(() {
showLoading = false;