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

@@ -14,7 +14,7 @@ import 'rules.dart';
import 'options_base.dart';
class CheckOptions extends OptionsBase {
CheckOptions({@required Product product, @required int index, @required Map<String, dynamic> selections})
CheckOptions({required Product product, required int index, required Map<String, dynamic> selections})
: super(product: product, index: index, selections: selections);
@override
@@ -50,14 +50,14 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(
S.of(context).check_option_select_token(product.productAttributes[this.index].name),
S.of(context).check_option_select_token(product!.productAttributes![this.index!].name),
style: new TextStyle(
fontSize: 12.5,
),
overflow: TextOverflow.ellipsis,
),
new Text(
product.productAttributes[this.index].required ? S.of(context).check_option_is_required : S.of(context).check_option_is_optional,
product!.productAttributes![this.index!].required ? S.of(context).check_option_is_required : S.of(context).check_option_is_optional,
style: new TextStyle(
fontSize: 10.0,
color: new Color(0xFF999999)
@@ -95,25 +95,25 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
'adjust_amount': adjustAmount
};
var cloneSelections = json.decode(json.encode(selections));
int idx = Utils.selectionsContains(cloneSelections, product.productAttributes[index].name, name);
int idx = Utils.selectionsContains(cloneSelections, product!.productAttributes![index!].name, name);
if (idx != -1) {
(cloneSelections[product.productAttributes[index].name.toUpperCase()] as List).removeAt(idx);
} else if (cloneSelections.containsKey(product.productAttributes[index].name.toUpperCase())) {
(cloneSelections[product.productAttributes[index].name.toUpperCase()] as List).add(opt);
(cloneSelections[product!.productAttributes![index!].name.toUpperCase()] as List).removeAt(idx);
} else if (cloneSelections.containsKey(product!.productAttributes![index!].name.toUpperCase())) {
(cloneSelections[product!.productAttributes![index!].name.toUpperCase()] as List).add(opt);
} else {
cloneSelections[product.productAttributes[index].name.toUpperCase()] = [opt];
cloneSelections[product!.productAttributes![index!].name.toUpperCase()] = [opt];
}
if (idx != -1 && (cloneSelections[product.productAttributes[index].name.toUpperCase()] as List).length == 0) {
cloneSelections.remove(product.productAttributes[index].name.toUpperCase());
if (idx != -1 && (cloneSelections[product!.productAttributes![index!].name.toUpperCase()] as List).length == 0) {
cloneSelections.remove(product!.productAttributes![index!].name.toUpperCase());
}
setOptionsStateDisabled(product.productAttributes[index].name, false);
setOptionsStateDisabled(product!.productAttributes![index!].name, false);
setState(() {
selections = cloneSelections;
});
eventBus.fire(new OnAttributeSelectionsChanged(selections));
eventBus.fire(new OnAttributeSelectionsChanged(selections!));
}
Widget _getOptionWidget() {
@@ -121,20 +121,20 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
children: <Widget>[],
);
List<ProductOption> productOptions = product.productAttributes[index].productOptions;
List<ProductOption> productOptions = product!.productAttributes![index!].productOptions;
if (!optionsState.containsKey(product.productAttributes[index].name)) {
if (!optionsState.containsKey(product!.productAttributes![index!].name)) {
List<Map<String, dynamic>> optionState = [];
for (var i = 0; i < productOptions.length; i++) {
optionState.add({'name': product.productAttributes[index].productOptions[i].name, 'disabled': false, 'check': false});
optionState.add({'name': product!.productAttributes![index!].productOptions[i].name, 'disabled': false, 'check': false});
}
optionsState[product.productAttributes[index].name] = optionState;
optionsState[product!.productAttributes![index!].name] = optionState;
}
if (selections.containsKey(product.productAttributes[index].name.toUpperCase())) {
if (selections!.containsKey(product!.productAttributes![index!].name.toUpperCase())) {
Map<String, dynamic> attrExtraJson = Utils.stringToJson(
product.productAttributes[index].extra);
Map<String, dynamic>? attrExtraJson = Utils.stringToJson(
product!.productAttributes![index!].extra);
if (attrExtraJson != null) {
var selectLimitIfFieldEqualsTo = Rule.getRule(
attrExtraJson, Rule.RULE_SELECT_LIMIT_IF_FIELD_EQUALS_TO);
@@ -147,15 +147,15 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
int limitQty = selectLimitIfFieldEqualsTo1[Rule
.RULE_KEY_FORCE_LIMITED];
thisLimitQty = limitQty;
if ((selections[product.productAttributes[index].name
if ((selections![product!.productAttributes![index!].name
.toUpperCase()] as List).length >= limitQty) {
disableOptionIfNotSelected();
}
} else if (Utils.getSelectedAttributeValue(selections, selectLimitIfFieldEqualsTo1[Rule.RULE_KEY_FIELD_KEY]).length > 0) {
if (selectLimitIfFieldEqualsTo1.containsKey(Utils.getSelectedAttributeValue(selections, selectLimitIfFieldEqualsTo1[Rule.RULE_KEY_FIELD_KEY])[0])) {
int limitQty = selectLimitIfFieldEqualsTo1[Utils.getSelectedAttributeValue(selections, selectLimitIfFieldEqualsTo1[Rule.RULE_KEY_FIELD_KEY])[0]];
} else if (Utils.getSelectedAttributeValue(selections!, selectLimitIfFieldEqualsTo1[Rule.RULE_KEY_FIELD_KEY]).length > 0) {
if (selectLimitIfFieldEqualsTo1.containsKey(Utils.getSelectedAttributeValue(selections!, selectLimitIfFieldEqualsTo1[Rule.RULE_KEY_FIELD_KEY])[0])) {
int limitQty = selectLimitIfFieldEqualsTo1[Utils.getSelectedAttributeValue(selections!, selectLimitIfFieldEqualsTo1[Rule.RULE_KEY_FIELD_KEY])[0]];
thisLimitQty = limitQty;
if ((selections[product.productAttributes[index].name
if ((selections![product!.productAttributes![index!].name
.toUpperCase()] as List).length >= limitQty) {
disableOptionIfNotSelected();
}
@@ -168,15 +168,15 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
int limitQty = selectLimitIfFieldEqualsTo[Rule
.RULE_KEY_FORCE_LIMITED];
thisLimitQty = limitQty;
if ((selections[product.productAttributes[index].name
if ((selections![product!.productAttributes![index!].name
.toUpperCase()] as List).length >= limitQty) {
disableOptionIfNotSelected();
}
} else if (Utils.getSelectedAttributeValue(selections, selectLimitIfFieldEqualsTo[Rule.RULE_KEY_FIELD_KEY]).length > 0) {
if (selectLimitIfFieldEqualsTo.containsKey(Utils.getSelectedAttributeValue(selections, selectLimitIfFieldEqualsTo[Rule.RULE_KEY_FIELD_KEY])[0])) {
int limitQty = selectLimitIfFieldEqualsTo[Utils.getSelectedAttributeValue(selections, selectLimitIfFieldEqualsTo[Rule.RULE_KEY_FIELD_KEY])[0]];
} else if (Utils.getSelectedAttributeValue(selections!, selectLimitIfFieldEqualsTo[Rule.RULE_KEY_FIELD_KEY]).length > 0) {
if (selectLimitIfFieldEqualsTo.containsKey(Utils.getSelectedAttributeValue(selections!, selectLimitIfFieldEqualsTo[Rule.RULE_KEY_FIELD_KEY])[0])) {
int limitQty = selectLimitIfFieldEqualsTo[Utils.getSelectedAttributeValue(selections!, selectLimitIfFieldEqualsTo[Rule.RULE_KEY_FIELD_KEY])[0]];
thisLimitQty = limitQty;
if ((selections[product.productAttributes[index].name
if ((selections![product!.productAttributes![index!].name
.toUpperCase()] as List).length >= limitQty) {
disableOptionIfNotSelected();
}
@@ -187,7 +187,7 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
}
for (var i = 0; i < productOptions.length; i++) {
Map<String, dynamic> extraJson = Utils.stringToJson(
Map<String, dynamic>? extraJson = Utils.stringToJson(
productOptions[i].extra);
if (extraJson != null) {
Map<String, dynamic> exclusiveRule = Rule.getRule(
@@ -195,12 +195,12 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
Map<String, dynamic> multiItemRule = Rule.getRule(extraJson, Rule.RULE_ACTUAL_QTY_IS);
if (exclusiveRule != null) {
if (thisLimitQty > 0 && !_checkOptionIsCheck(productOptions[i].name)) {
optionsState[product.productAttributes[index].name][i]['disabled'] = true;
optionsState[product!.productAttributes![index!].name][i]['disabled'] = true;
} else {
if (_checkOptionIsCheck(productOptions[i].name)) {
setOptionsStateDisabled(
product.productAttributes[index].name, true);
optionsState[product.productAttributes[index]
product!.productAttributes![index!].name, true);
optionsState[product!.productAttributes![index!]
.name][i]['disabled'] = false;
break;
}
@@ -208,12 +208,12 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
}
if (multiItemRule != null) {
if (_checkOptionIsCheck(productOptions[i].name)) {
if (multiItemRule[Rule.RULE_ACTUAL_QTY_IS] > thisLimitQty - (selections[product.productAttributes[index].name.toUpperCase()] as List).length) {
if (multiItemRule[Rule.RULE_ACTUAL_QTY_IS] > thisLimitQty - (selections![product!.productAttributes![index!].name.toUpperCase()] as List).length) {
disableOptionIfNotSelected();
}
} else {
if (multiItemRule[Rule.RULE_ACTUAL_QTY_IS] > thisLimitQty - (selections[product.productAttributes[index].name.toUpperCase()] as List).length) {
optionsState[product.productAttributes[index]
if (multiItemRule[Rule.RULE_ACTUAL_QTY_IS] > thisLimitQty - (selections![product!.productAttributes![index!].name.toUpperCase()] as List).length) {
optionsState[product!.productAttributes![index!]
.name][i]['disabled'] = true;
}
}
@@ -222,26 +222,26 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
}
}
List<Map<String, dynamic>> optionState = optionsState[product.productAttributes[index].name];
List<Map<String, dynamic>> optionState = optionsState[product!.productAttributes![index!].name];
for (var i = 0; i < optionState.length; i++) {
Widget optionWidget = _getOptionCheck(
product.productAttributes[index].productOptions[i], optionState[i]['disabled'], i);
product!.productAttributes![index!].productOptions[i], optionState[i]['disabled'], i);
row.children.add(optionWidget);
}
return row;
}
void disableOptionIfNotSelected() {
setOptionsStateDisabled(product.productAttributes[index].name, true);
for (var i = 0; i < optionsState[product.productAttributes[index].name].length; i++) {
if (Utils.selectionsContains(selections, product.productAttributes[index].name, optionsState[product.productAttributes[index].name][i]['name']) != -1) {
optionsState[product.productAttributes[index].name][i]['disabled'] = false;
setOptionsStateDisabled(product!.productAttributes![index!].name, true);
for (var i = 0; i < optionsState[product!.productAttributes![index!].name].length; i++) {
if (Utils.selectionsContains(selections!, product!.productAttributes![index!].name, optionsState[product!.productAttributes![index!].name][i]['name']) != -1) {
optionsState[product!.productAttributes![index!].name][i]['disabled'] = false;
}
}
}
bool _checkOptionIsCheck(String name) {
if (Utils.selectionsContains(selections, product.productAttributes[index].name, name) != -1) {
if (Utils.selectionsContains(selections!, product!.productAttributes![index!].name, name) != -1) {
return true;
}
return false;
@@ -251,7 +251,7 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
bool disabled = optDisabled;
bool check = _checkOptionIsCheck(productOption.name);
Map<String, dynamic> extraJson = Utils.stringToJson(productOption.extra);
Map<String, dynamic>? extraJson = Utils.stringToJson(productOption.extra);
// Utils.jsonPrettyPrint(extraJson);
double extraAdjustAmount = 0.0;
@@ -262,13 +262,13 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
if (sizeBaseAdjustment is List) {
for (var i = 0; i < (sizeBaseAdjustment as List).length; i++) {
Map<String, dynamic> sizeBaseAdjustment1 = sizeBaseAdjustment[i];
List<String> attValues = Utils.getSelectedAttributeValue(selections, sizeBaseAdjustment1[Rule.RULE_KEY_FIELD_KEY]);
List<String> attValues = Utils.getSelectedAttributeValue(selections!, sizeBaseAdjustment1[Rule.RULE_KEY_FIELD_KEY]);
if (attValues.length > 0 && sizeBaseAdjustment1.containsKey(attValues[0])) {
extraAdjustAmount += sizeBaseAdjustment1[attValues[0]];
}
}
} else {
List<String> attValues = Utils.getSelectedAttributeValue(selections, sizeBaseAdjustment[Rule.RULE_KEY_FIELD_KEY]);
List<String> attValues = Utils.getSelectedAttributeValue(selections!, sizeBaseAdjustment[Rule.RULE_KEY_FIELD_KEY]);
if (attValues.length > 0 && sizeBaseAdjustment.containsKey(attValues[0])) {
extraAdjustAmount += sizeBaseAdjustment[attValues[0]];
}
@@ -282,7 +282,7 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
for (var i = 0; i < (disabledRule as List).length; i++) {
Map<String, dynamic> disabledRule1 = disabledRule[i];
List<String> attValues = Utils.getSelectedAttributeValue(
selections, disabledRule1[Rule.RULE_KEY_FIELD_KEY]);
selections!, disabledRule1[Rule.RULE_KEY_FIELD_KEY]);
if (attValues.length > 0 &&
disabledRule1.containsKey(attValues[0])) {
disabled = true;
@@ -301,7 +301,7 @@ class CheckOptionsState extends OptionsBaseState<CheckOptions> {
}
} else {
List<String> attValues = Utils.getSelectedAttributeValue(
selections, disabledRule[Rule.RULE_KEY_FIELD_KEY]);
selections!, disabledRule[Rule.RULE_KEY_FIELD_KEY]);
if (attValues.length > 0) {
for (String s in attValues) {
if (disabledRule.containsKey(s) && disabledRule[s]) {