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

@@ -19,10 +19,9 @@ import '../../widgets/general/attribute/radio_options.dart';
class MobileAttributeSelection extends StatefulWidget {
final Product product;
final Business business;
final Key key;
final GlobalKey startKey;
final GlobalKey? startKey;
const MobileAttributeSelection({@required this.product, @required this.business, this.key, this.startKey})
const MobileAttributeSelection({required this.product, required this.business, Key? key, this.startKey})
: super(key: key);
@override
@@ -33,18 +32,18 @@ class MobileAttributeSelection extends StatefulWidget {
}
class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
Product product;
int index;
TextButton previousButton;
TextButton nextButton;
bool previousButtonEnable;
bool nextButtonEnable;
Product? product;
int? index;
TextButton? previousButton;
TextButton? nextButton;
bool previousButtonEnable = false;
bool nextButtonEnable = false;
String productDesc;
double productPrice;
String? productDesc;
double? productPrice;
String nextText;
String finishText;
String? nextText;
String? finishText;
Map<String, dynamic> selections = new Map();
@@ -80,8 +79,8 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
previousButton,
nextButton
previousButton!,
nextButton!
],
),
),
@@ -96,8 +95,8 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
product = widget.product;
previousButtonEnable = false;
nextButtonEnable = false;
productDesc = product.description;
productPrice = product.price;
productDesc = product!.description;
productPrice = product!.price;
});
eventBus.on<OnAttributeSelectionsChanged>().listen((event) {
@@ -118,31 +117,31 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
extendDescription.add(key + ': ' + opt.join(', '));
});
ProductAttribute pa = product.productAttributes[index];
ProductAttribute pa = product!.productAttributes![index!];
if (pa.required && Utils.selectionsNotEmptyAt(selections, pa.name)) {
setState(() {
nextButtonEnable = true;
productDesc = product.description + ', ' + extendDescription.join('; ');
productPrice = product.price + extendPrice;
productDesc = (product!.description ?? '') + ', ' + extendDescription.join('; ');
productPrice = product!.price! + extendPrice;
});
} else if (!pa.required){
setState(() {
nextButtonEnable = true;
productDesc = product.description + ', ' + extendDescription.join('; ');
productPrice = product.price + extendPrice;
productDesc = (product!.description ?? '') + ', ' + extendDescription.join('; ');
productPrice = product!.price! + extendPrice;
});
} else {
setState(() {
nextButtonEnable = false;
productDesc = product.description + ', ' + extendDescription.join('; ');
productPrice = product.price + extendPrice;
productDesc = (product!.description ?? '') + ', ' + extendDescription.join('; ');
productPrice = product!.price! + extendPrice;
});
}
});
}
bool _checkCanGoNext() {
ProductAttribute pa = product.productAttributes[index];
ProductAttribute pa = product!.productAttributes![index!];
if (pa.required && Utils.selectionsNotEmptyAt(selections, pa.name)) {
return true;
} else if (!pa.required){
@@ -167,7 +166,7 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
nextButton = TextButton(
onPressed: nextButtonEnable ? _goNext : null,
child: new Text(
product.productAttributes.length > index + 1 ? nextText : finishText
'${product!.productAttributes!.length > index! + 1 ? nextText : finishText}'
),
);
@@ -180,7 +179,7 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
padding: new EdgeInsets.all(10.0),
width: 70.0,
height: 70.0,
child: Util.showImage(product.imagePath,
child: Util.showImage(product!.imagePath ?? '',
width: 70.0,
height: 70.0,
fit: BoxFit.fill,
@@ -194,7 +193,7 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
new Container(
padding: new EdgeInsets.all(10.0).copyWith(left: 0.0).copyWith(bottom: 0.0),
child: new Text(
product.name,
product!.name ?? '',
style: new TextStyle(
fontSize: 15.0,
),
@@ -205,7 +204,7 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
new Container(
padding: new EdgeInsets.only(right: 10.0),
child: new Text(
productDesc,
productDesc ?? '',
style: new TextStyle(
fontSize: 9.0,
color: new Color(0xFFCDCDCD)
@@ -223,7 +222,7 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
width: 70.0,
child:
new Text(
productPrice.toStringAsFixed(2),
productPrice!.toStringAsFixed(2),
textAlign: TextAlign.right,
style: new TextStyle(
fontSize: 18.0,
@@ -239,14 +238,14 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
Widget _getOptionsView() {
Widget optionsView;
ProductAttribute productAttribute = product.productAttributes[index];
ProductAttribute productAttribute = product!.productAttributes![index!];
if (productAttribute.byQuantity) {
optionsView = new QtyOptions(product: product, index: index, selections: selections);
optionsView = new QtyOptions(product: product!, index: index!, selections: selections);
} else {
if (productAttribute.singleSelection) {
optionsView = new RadioOptions(product: product, index: index, selections: selections);
optionsView = new RadioOptions(product: product!, index: index!, selections: selections);
} else {
optionsView = new CheckOptions(product: product, index: index, selections: selections);
optionsView = new CheckOptions(product: product!, index: index!, selections: selections);
}
}
@@ -254,27 +253,27 @@ class MobileAttributeSelectionState extends State<MobileAttributeSelection> {
}
void _goNext() {
if (index + 1 < product.productAttributes.length) {
if (index! + 1 < product!.productAttributes!.length) {
setState(() {
index = index + 1;
previousButtonEnable = index >= 1;
index = index! + 1;
previousButtonEnable = index! >= 1;
nextButtonEnable = _checkCanGoNext();
});
} else if (product.productAttributes.length == index + 1) {
eventBus.fire(new OnProductWillAddToCart(product, selections, productPrice, productDesc, widget.business, buttonKey: widget.startKey));
} else if (product!.productAttributes!.length == index! + 1) {
eventBus.fire(new OnProductWillAddToCart(product!, selections, productPrice!, productDesc ?? '', widget.business, buttonKey: widget.startKey));
Navigator.pop(context);
}
eventBus.fire(new OnAttributePageChanged(index));
eventBus.fire(new OnAttributePageChanged(index!));
}
void _goPrevious() {
if (index - 1 >= 0) {
if (index! - 1 >= 0) {
setState(() {
index = index - 1;
previousButtonEnable = index > 0;
index = index! - 1;
previousButtonEnable = index! > 0;
nextButtonEnable = _checkCanGoNext();
});
eventBus.fire(new OnAttributePageChanged(index));
eventBus.fire(new OnAttributePageChanged(index!));
}
}