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

@@ -1,7 +1,8 @@
import 'package:email_validator/email_validator.dart';
import 'package:flutter/material.dart';
import 'package:gender_selection/gender_selection.dart';
import 'package:gender_picker/gender_picker.dart';
import 'package:gender_picker/source/enums.dart';
import '../../generated/l10n.dart';
import '../../models/located_address.dart';
@@ -11,10 +12,9 @@ import '../../store/store.dart';
import '../../utils/http_util.dart';
class MobileNewAddress extends StatefulWidget {
final Key key;
final LocatedAddress locatedAddress;
final int businessId;
const MobileNewAddress({this.key, this.locatedAddress, this.businessId}) : super(key: key);
final LocatedAddress? locatedAddress;
final int? businessId;
const MobileNewAddress({Key? key, this.locatedAddress, this.businessId}) : super(key: key);
@override
State<StatefulWidget> createState() {
@@ -36,9 +36,9 @@ class MobileNewAddressState extends State<MobileNewAddress> {
final faxController = TextEditingController();
String country = 'CA';
Gender _selectedGender;
Gender? _selectedGender;
String _selectedProvince;
String? _selectedProvince;
List<String> provinces = <String>[
'Ontario',
@@ -96,31 +96,33 @@ class MobileNewAddressState extends State<MobileNewAddress> {
),
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),
@@ -140,8 +142,8 @@ class MobileNewAddressState extends State<MobileNewAddress> {
),
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;
@@ -165,8 +167,8 @@ class MobileNewAddressState extends State<MobileNewAddress> {
),
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;
@@ -209,8 +211,8 @@ class MobileNewAddressState extends State<MobileNewAddress> {
),
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;
@@ -255,8 +257,8 @@ class MobileNewAddressState extends State<MobileNewAddress> {
),
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;
@@ -290,8 +292,8 @@ class MobileNewAddressState extends State<MobileNewAddress> {
),
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;
@@ -348,15 +350,15 @@ class MobileNewAddressState extends State<MobileNewAddress> {
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';
}
@@ -366,11 +368,11 @@ class MobileNewAddressState extends State<MobileNewAddress> {
}
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! > 0) {
Routes.router.navigateTo(context, '/checkout/${widget.businessId}', replace: true);
} else {
Routes.router.navigateTo(context, '/my-addresses/${widget.businessId}', replace: true);