final
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
import 'package:email_validator/email_validator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_wisetronic/widgets/general/breadcrumbs.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 '../../generated/l10n.dart';
|
||||
@@ -14,10 +15,9 @@ import '../../utils/http_util.dart';
|
||||
import '../../widgets/general/navigationbar.dart';
|
||||
|
||||
class DesktopNewAddress extends StatefulWidget {
|
||||
final Key key;
|
||||
final LocatedAddress locatedAddress;
|
||||
final int businessId;
|
||||
const DesktopNewAddress({this.key, this.locatedAddress, this.businessId}) : super(key: key);
|
||||
final LocatedAddress? locatedAddress;
|
||||
final int? businessId;
|
||||
const DesktopNewAddress({Key? key, this.locatedAddress, this.businessId}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -39,9 +39,9 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
final faxController = TextEditingController();
|
||||
|
||||
String country = 'CA';
|
||||
Gender _selectedGender;
|
||||
Gender? _selectedGender;
|
||||
|
||||
String _selectedProvince;
|
||||
String? _selectedProvince;
|
||||
|
||||
double sideSpace = 0;
|
||||
double mainSpace = 1200;
|
||||
@@ -97,31 +97,33 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
),
|
||||
labelText: S.of(context).contact_name,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).contact_name_is_required;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
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(left: 16.0, right: 16.0, top: 16.0, bottom: 0.0),
|
||||
@@ -141,8 +143,8 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
),
|
||||
labelText: S.of(context).mobile_phone_number,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).mobile_phone_number_is_required;
|
||||
}
|
||||
return null;
|
||||
@@ -166,8 +168,8 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
),
|
||||
labelText: S.of(context).street_line_1,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).street_line_1_is_required;
|
||||
}
|
||||
return null;
|
||||
@@ -210,8 +212,8 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
),
|
||||
labelText: S.of(context).city,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).city_is_required;
|
||||
}
|
||||
return null;
|
||||
@@ -256,8 +258,8 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
),
|
||||
labelText: S.of(context).postal_code,
|
||||
),
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).postal_code_is_required;
|
||||
}
|
||||
return null;
|
||||
@@ -291,8 +293,8 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
),
|
||||
labelText: S.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;
|
||||
}
|
||||
return null;
|
||||
@@ -377,15 +379,15 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
super.initState();
|
||||
setState(() {
|
||||
if (widget.locatedAddress != null) {
|
||||
if (provinces.contains(widget.locatedAddress.province)) {
|
||||
_selectedProvince = widget.locatedAddress.province;
|
||||
if (provinces.contains(widget.locatedAddress?.province)) {
|
||||
_selectedProvince = widget.locatedAddress?.province;
|
||||
}
|
||||
cityController.text = widget.locatedAddress.city;
|
||||
postalCodeController.text = widget.locatedAddress.postalCode;
|
||||
streetLine1Controller.text = (widget.locatedAddress.streetNumber != null
|
||||
&& widget.locatedAddress.streetNumber.isNotEmpty
|
||||
? widget.locatedAddress.streetNumber + ' ' : '')
|
||||
+ widget.locatedAddress.streetName;
|
||||
cityController.text = widget.locatedAddress?.city ?? '';
|
||||
postalCodeController.text = widget.locatedAddress?.postalCode ?? '';
|
||||
streetLine1Controller.text = (widget.locatedAddress?.streetNumber != null
|
||||
&& widget.locatedAddress!.streetNumber.isNotEmpty
|
||||
? widget.locatedAddress!.streetNumber + ' ' : '')
|
||||
+ widget.locatedAddress!.streetName;
|
||||
} else {
|
||||
_selectedProvince = 'Ontario';
|
||||
}
|
||||
@@ -395,11 +397,11 @@ class DesktopNewAddressState extends State<DesktopNewAddress> {
|
||||
}
|
||||
|
||||
void _saveNewAddress() {
|
||||
final FormState form = _formKey.currentState;
|
||||
if (form.validate()) {
|
||||
final FormState? form = _formKey.currentState;
|
||||
if (form != null && form.validate()) {
|
||||
|
||||
HttpUtil.httpPost('v1/addresses', (response) {
|
||||
if (widget.businessId > 0) {
|
||||
if (widget.businessId != null && widget.businessId! > 0) {
|
||||
Routes.router.navigateTo(context, '/checkout/${widget.businessId}', replace: true);
|
||||
} else {
|
||||
Routes.router.navigateTo(context, '/my-addresses/${widget.businessId}', replace: true);
|
||||
|
||||
Reference in New Issue
Block a user