π Bug: Duplicate Conversion Constants β converter_screen.dart Ignores AppConstants
π Description
The app has a dedicated constants class AppConstants in lib/constants/app_constants.dart designed as the single source of truth for gold unit conversion factors. However, lib/converter_screen.dart re-declares the exact same constants locally and never imports AppConstants β completely bypassing it.
This means there are two separate definitions of the same values in the codebase. If a conversion factor ever needs to be updated (e.g., correcting precision), a developer must update it in both files β and forgetting one will introduce a silent calculation discrepancy with no compile-time error.
π Evidence
lib/constants/app_constants.dart (the intended source of truth):
class AppConstants {
static const double tolaToGram = 11.66;
static const double mashaToGram = 0.972;
static const double anaToGram = 0.72875;
static const double rattiToGram = 0.1215;
}
lib/converter_screen.dart (duplicate β lines 32β35):
static const double tolaToGram = 11.66;
static const double mashaToGram = 0.972;
static const double anaToGram = 0.72875;
static const double rattiToGram = 0.1215;
converter_screen.dart does not import app_constants.dart and uses its own local copies.
β Current Risk
- Any future change to a conversion factor in
AppConstants will have zero effect on actual calculations, since converter_screen.dart uses its own copies
- This is a silent bug risk β calculations appear correct but the wrong values could be used without warning
- Violates the DRY (Don't Repeat Yourself) principle and makes maintenance error-prone
β
Expected Behavior
converter_screen.dart should import and reference AppConstants directly, with no local duplicate declarations.
π§ Fix Required
Step 1 β Add import to lib/converter_screen.dart:
import 'package:gold_weight_converter/constants/app_constants.dart';
Step 2 β Remove the 4 local constant declarations from converter_screen.dart (lines 32β35):
// DELETE these lines:
static const double tolaToGram = 11.66;
static const double mashaToGram = 0.972;
static const double anaToGram = 0.72875;
static const double rattiToGram = 0.1215;
Step 3 β Update all usages in converter_screen.dart to use AppConstants:
// Before:
totalGrams += tola * tolaToGram;
// After:
totalGrams += tola * AppConstants.tolaToGram;
π·οΈ Priority
π΄ High β This is a latent maintenance bug that will silently cause calculation errors if constants ever diverge between the two files.
π Flutter Files to Modify
| File |
Action |
lib/converter_screen.dart |
Remove duplicate constants, add AppConstants import, update all references |
lib/constants/app_constants.dart |
No changes needed β this is already correct |
π Bug: Duplicate Conversion Constants β
converter_screen.dartIgnoresAppConstantsπ Description
The app has a dedicated constants class
AppConstantsinlib/constants/app_constants.dartdesigned as the single source of truth for gold unit conversion factors. However,lib/converter_screen.dartre-declares the exact same constants locally and never importsAppConstantsβ completely bypassing it.This means there are two separate definitions of the same values in the codebase. If a conversion factor ever needs to be updated (e.g., correcting precision), a developer must update it in both files β and forgetting one will introduce a silent calculation discrepancy with no compile-time error.
π Evidence
lib/constants/app_constants.dart(the intended source of truth):lib/converter_screen.dart(duplicate β lines 32β35):converter_screen.dartdoes not importapp_constants.dartand uses its own local copies.β Current Risk
AppConstantswill have zero effect on actual calculations, sinceconverter_screen.dartuses its own copiesβ Expected Behavior
converter_screen.dartshould import and referenceAppConstantsdirectly, with no local duplicate declarations.π§ Fix Required
Step 1 β Add import to
lib/converter_screen.dart:Step 2 β Remove the 4 local constant declarations from
converter_screen.dart(lines 32β35):Step 3 β Update all usages in
converter_screen.dartto useAppConstants:π·οΈ Priority
π΄ High β This is a latent maintenance bug that will silently cause calculation errors if constants ever diverge between the two files.
π Flutter Files to Modify
lib/converter_screen.dartAppConstantsimport, update all referenceslib/constants/app_constants.dart