Duplicate Code: Identical Empty State Widgets (EmptyCard and InitialCard)
#44 aperta il 21 feb 2026
Metriche repository
- Star
- (16 stelle)
- Metriche merge PR
- (Metriche PR in attesa)
Descrizione
Analysis of commit eaf30ea
Summary
Two widget files contain nearly 100% identical code: EmptyCard and InitialCard both implement the exact same empty state widget structure with no meaningful differences. This is classic copy-paste duplication that increases maintenance burden and creates potential for inconsistent behavior.
Duplication Details
Pattern: Identical Widget Implementation
-
Severity: High
-
Occurrences: 2 files
-
Lines of Duplicated Code: 17 lines (100% identical)
-
Locations:
lib/ui/widgets/empty_card.dart(lines 1-17)lib/ui/widgets/initial_card.dart(lines 1-17)
-
Code Sample:
import 'package:flutter/material.dart';
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 byte-for-byte identical except for the class name.
Impact Analysis
- Maintainability: Any change to the empty state UI must be duplicated in both files, increasing the risk of inconsistency
- Bug Risk: If a bug is fixed in one widget, it must be remembered to fix it in the other
- Code Bloat: Two files where one would suffice, increasing codebase size unnecessarily
- Developer Confusion: Having two identical widgets with different names creates confusion about when to use which
Refactoring Recommendations
-
Consolidate into Single Widget
- Merge both widgets into a single
EmptyStateCardwidget - Location:
lib/ui/widgets/empty_state_card.dart - Update all import statements to use the consolidated widget
- Benefits: Single source of truth, reduced maintenance burden, clearer intent
- Merge both widgets into a single
-
Alternative: Parameterized Widget
- If the widgets are intended to have different appearances in the future, create a single parameterized widget
- Add optional parameters for customization (message, icon, etc.)
- Benefits: Maintains flexibility while eliminating duplication
Implementation Checklist
- Review duplication findings
- Decide on consolidation approach (single widget vs. parameterized)
- Create consolidated widget implementation
- Update all references in
lib/ui/pages/home.dartand other consumers - Remove duplicate widget files
- Update widget barrel exports in
lib/ui/widgets/widgets.dart - Run tests to verify no functionality broken
- Consider adding meaningful content to empty states (helpful message, illustration, etc.)
Analysis Metadata
- Analyzed Files: 33 Dart files
- Detection Method: Manual code review and semantic analysis
- Commit: eaf30ea
- Analysis Date: 2026-02-21
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.