final
This commit is contained in:
@@ -5,7 +5,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:flutter_wisetronic/widgets/general/breadcrumbs.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 '../../constants.dart';
|
||||
import '../../events/eventbus.dart';
|
||||
@@ -20,10 +21,9 @@ import '../../utils/utils.dart';
|
||||
import '../../widgets/general/navigationbar.dart';
|
||||
|
||||
class DesktopEditAddress extends StatefulWidget {
|
||||
final Key key;
|
||||
final Address address;
|
||||
final Address? address;
|
||||
final int businessId;
|
||||
const DesktopEditAddress(this.address, {this.key, int businessId}) :
|
||||
const DesktopEditAddress(this.address, {Key? key, int? businessId}) :
|
||||
businessId = businessId ?? Constants.BUSINESS_ID;
|
||||
|
||||
@override
|
||||
@@ -45,12 +45,12 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
final emailController = TextEditingController();
|
||||
final faxController = TextEditingController();
|
||||
|
||||
String country;
|
||||
Gender _selectedGender;
|
||||
String? country;
|
||||
Gender? _selectedGender;
|
||||
|
||||
String _selectedProvince;
|
||||
String? _selectedProvince;
|
||||
|
||||
bool showLoading;
|
||||
bool showLoading = false;
|
||||
|
||||
double sideSpace = 0;
|
||||
double mainSpace = 1200;
|
||||
@@ -105,8 +105,8 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
.of(context)
|
||||
.contact_name,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value
|
||||
validator: (String? value) {
|
||||
if (value == null || value
|
||||
.trim()
|
||||
.isEmpty) {
|
||||
return S
|
||||
@@ -117,27 +117,25 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
},
|
||||
),
|
||||
),
|
||||
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(
|
||||
@@ -160,8 +158,8 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
.of(context)
|
||||
.mobile_phone_number,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value
|
||||
validator: (String? value) {
|
||||
if (value == null || value
|
||||
.trim()
|
||||
.isEmpty) {
|
||||
return S
|
||||
@@ -192,8 +190,8 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
.of(context)
|
||||
.street_line_1,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value
|
||||
validator: (String? value) {
|
||||
if (value == null || value
|
||||
.trim()
|
||||
.isEmpty) {
|
||||
return S
|
||||
@@ -246,8 +244,8 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
.of(context)
|
||||
.city,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value
|
||||
validator: (String? value) {
|
||||
if (value == null || value
|
||||
.trim()
|
||||
.isEmpty) {
|
||||
return S
|
||||
@@ -316,8 +314,8 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
.of(context)
|
||||
.postal_code,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value
|
||||
validator: (String? value) {
|
||||
if (value == null || value
|
||||
.trim()
|
||||
.isEmpty) {
|
||||
return S
|
||||
@@ -361,8 +359,8 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
.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;
|
||||
@@ -496,29 +494,29 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
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;
|
||||
@@ -532,7 +530,7 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
}
|
||||
},
|
||||
body: {
|
||||
'id': widget.address.id,
|
||||
'id': widget.address?.id,
|
||||
'name': contactNameController.text.trim(),
|
||||
'address_line1': streetLine1Controller.text.trim(),
|
||||
'address_line2': streetLine2Controller.text.trim(),
|
||||
@@ -562,7 +560,7 @@ class DesktopEditAddressState extends State<DesktopEditAddress> {
|
||||
showLoading = true;
|
||||
});
|
||||
}
|
||||
HttpUtil.httpDelete('v1/addresses/${widget.address.id}', (response) {
|
||||
HttpUtil.httpDelete('v1/addresses/${widget.address?.id}', (response) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
showLoading = false;
|
||||
|
||||
Reference in New Issue
Block a user