在ontap中添加if语句后,颤动按钮停止工作时出现空错误。这是我的颤动代码
import 'package:efood_multivendor/controller/product_controller.dart';
import 'package:efood_multivendor/util/dimensions.dart';
import 'package:flutter/material.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_instance/src/extension_instance.dart';
import 'package:get/get_utils/src/extensions/internacionalization.dart';
import 'custom_snackbar.dart';
class QuantityButton extends StatelessWidget {
final bool isIncrement;
final Function onTap;
final int quantity;
final int stock;
QuantityButton(
{@required this.isIncrement,
@required this.onTap,
@required this.quantity,
@required this.stock});
@override
Widget build(BuildContext context) {
return InkWell(
onTap : onTap({
if (!isIncrement && quantity > 1) {
Get.find<ProductController>().setQuantity(false),
} else if (isIncrement) {
if (quantity < stock) {
Get.find<ProductController>().setQuantity(true),
} else {
showCustomSnackBar('out_of_stock'.tr),
}
}
}),
child: Container(
height: 22,
width: 22,
margin: EdgeInsets.symmetric(horizontal: Dimensions.PADDING_SIZE_SMALL),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 1,
color: isIncrement
? Theme.of(context).primaryColor
: Theme.of(context).disabledColor),
color: isIncrement
? Theme.of(context).primaryColor
: Theme.of(context).disabledColor.withOpacity(0.2),
),
alignment: Alignment.center,
child: Icon(
isIncrement ? Icons.add : Icons.remove,
size: 15,
color: isIncrement
? Theme.of(context).cardColor
: Theme.of(context).disabledColor,
),
),
);
}
}如果我尝试删除if语句并添加按钮,它是工作的,我得到的Another exception was thrown: NoSuchMethodError: '<Unexpected Null Value>'错误仍然按钮不工作
发布于 2021-09-26 10:08:49
尝试将其包装在一个函数中,以获得清晰的代码。
将,替换为;以结束命令
InkWell(
onTap : (){
if (!isIncrement && quantity > 1) {
Get.find<ProductController>().setQuantity(false);
} else if (isIncrement) {
if (quantity < stock) {
Get.find<ProductController>().setQuantity(true);
} else {
showCustomSnackBar('out_of_stock'.tr);
}
}祝你好运。
https://stackoverflow.com/questions/69333780
复制相似问题