Skip to content

πŸ› [Bug] Duplicate Conversion Constants β€” converter_screen.dart Bypasses AppConstantsΒ #6

Description

@Dr-Usman

πŸ› 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions