Skip to content

Commit

Permalink
fix: remove validation check for basic info fields (#3794)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudhanva-Nadiger committed Apr 8, 2023
1 parent 441305b commit 9ccfcf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
26 changes: 0 additions & 26 deletions packages/smooth_app/lib/pages/product/add_basic_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ class AddBasicDetailsPage extends StatefulWidget {
final Product product;
final bool isLoggedInMandatory;

/// Returns true if the [field] is valid (= not empty).
static bool _isProductFieldValid(final String? field) =>
field != null && field.trim().isNotEmpty;

/// Returns true if the [product] basic details are valid (= not empty).
static bool isProductBasicValid(final Product product) =>
_isProductFieldValid(product.productName) &&
_isProductFieldValid(product.brands);

@override
State<AddBasicDetailsPage> createState() => _AddBasicDetailsPageState();
}
Expand Down Expand Up @@ -106,26 +97,12 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
controller: _productNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.product_name,
validator: (String? value) {
if (!AddBasicDetailsPage._isProductFieldValid(value)) {
return appLocalizations
.add_basic_details_product_name_error;
}
return null;
},
),
SizedBox(height: _heightSpace),
SmoothTextFormField(
controller: _brandNameController,
type: TextFieldTypes.PLAIN_TEXT,
hintText: appLocalizations.brand_name,
validator: (String? value) {
if (!AddBasicDetailsPage._isProductFieldValid(value)) {
return appLocalizations
.add_basic_details_brand_name_error;
}
return null;
},
),
SizedBox(height: _heightSpace),
SmoothTextFormField(
Expand All @@ -149,9 +126,6 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
positiveAction: SmoothActionButton(
text: appLocalizations.save,
onPressed: () async {
if (!_formKey.currentState!.validate()) {
return;
}
AnalyticsHelper.trackProductEdit(
AnalyticsEditEvents.basicDetails,
_product.barcode!,
Expand Down
14 changes: 12 additions & 2 deletions packages/smooth_app/lib/pages/product/add_new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ class _AddNewProductPageState extends State<AddNewProductPage> {

final ProductList _history = ProductList.history();

/// Returns true if the [field] is valid (= not empty).
static bool _isProductFieldValid(final String? field) =>
field != null && field.trim().isNotEmpty;

/// Returns true if the [product] basic details are valid (= not empty).
static bool isProductBasicValid(final Product product) =>
_isProductFieldValid(product.productName) ||
_isProductFieldValid(product.brands);

bool get _nutritionFactsAdded => _product.nutriments?.isEmpty() == false;
bool get _basicDetailsAdded =>
AddBasicDetailsPage.isProductBasicValid(_product);
bool get _basicDetailsAdded => isProductBasicValid(_product);

bool _alreadyPushedtToHistory = false;

Expand Down Expand Up @@ -126,6 +134,8 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
if (_basicDetailsAdded ||
_uploadedImages.isNotEmpty ||
_otherUploadedImages.isNotEmpty) {
_product.productName = _product.productName?.trim();
_product.brands = _product.brands?.trim();
await _daoProductList.push(_history, _product.barcode!);
_alreadyPushedtToHistory = true;
}
Expand Down

0 comments on commit 9ccfcf1

Please sign in to comment.