Can this code snippet be simplified on the second line?
From:
GetBuilder<ProductController>(builder: (productController) {
return productController.reviewedProductList == null || productController.reviewedProductList.length != 0
? CategoryDrinksView(productController: productController, isPopular: true)
: SizedBox();
})
To:
GetBuilder<ProductController>(builder: (productController) {
return productController.reviewedProductList?.length != 0
? CategoryDrinksView(productController: productController, isPopular: true)
: SizedBox();
})
The IDE doesn't return any errors and everything seems to work, but I would like to know if this is common in Dart and can be considered good practice.
I don't think it's a good idea. You may get a 'NoSuchMethodError: The getter 'length' was called on null' error, if the value of reviewedProductList was null. So keep the double checking