Skip to content

Duplicate Code: Identical Empty State Widgets (EmptyCard and InitialCard) #40

@github-actions

Description

@github-actions

Analysis of commit eaf30ea

Summary

Two nearly identical widget classes exist for displaying empty states: EmptyCard and InitialCard. Both widgets have identical implementations with only the class name differing, representing clear code duplication that increases maintenance burden.

Duplication Details

Pattern: Identical Empty State Widget Classes

  • Severity: Medium

  • Occurrences: 2 files

  • Total Duplicated Lines: 17 lines

  • Locations:

    • lib/ui/widgets/empty_card.dart (lines 1-17)
    • lib/ui/widgets/initial_card.dart (lines 1-17)
  • Code Sample:

class EmptyCard extends StatelessWidget {
  const EmptyCard({
    Key? key,
  }) : super(key: key);

  `@override`
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: const [],
      ),
    );
  }
}

The InitialCard widget is structurally identical with only the class name changed.

Impact Analysis

  • Maintainability: Any changes to the empty state display logic must be duplicated across both files, increasing the risk of inconsistency
  • Bug Risk: If a bug fix or enhancement is applied to one widget but not the other, it creates inconsistent behavior
  • Code Bloat: Two files and two widget exports for what is essentially the same component
  • Semantic Confusion: Having two separate classes suggests different purposes, but the implementations are identical

Refactoring Recommendations

  1. Consolidate into Single Widget (Recommended)

    • Keep only one widget class (suggest EmptyStateCard for clarity)
    • Update all references in lib/ui/pages/home.dart:75-77
    • Remove the unused widget file
    • Update the widgets barrel export file
    • Estimated effort: 15-30 minutes
    • Benefits: Eliminates duplication, clearer intent, easier maintenance
  2. Add Configuration Parameter

    • If there's a planned distinction between "empty" and "initial" states:
      • Add a message or icon parameter to the widget
      • Create named constructors or factory methods for different states
    • Estimated effort: 30-45 minutes
    • Benefits: Maintains semantic distinction while sharing implementation

Implementation Checklist

  • Review duplication findings
  • Determine if EmptyCard and InitialCard should have different behavior in the future
  • Choose refactoring approach (consolidate or parameterize)
  • Update all widget references in HomePage and other consumers
  • Remove unused widget file and update exports
  • Verify functionality with existing tests
  • Add content to the empty state (currently displays nothing)

Analysis Metadata

  • Analyzed Files: 32 .dart files
  • Detection Method: Semantic code analysis
  • Commit: eaf30ea
  • Analysis Date: 2026-02-19

AI generated by Duplicate Code Detector

To add this workflow in your repository, run gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4. See usage guide.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions