chimon2000 / chimon2000/good_first_issue
Duplicate Code: Identical Empty State Widgets (EmptyCard and InitialCard)
- Dominant language
- Dart
- Stars
- 19
- Forks
- 29
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 2
Description
*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**:
``````dart
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
1. **Consolidate into Single Widget**
- Merge both widgets into a single `EmptyStateCard` widget
- 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
2. **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.dart` and 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](https://github.com/chimon2000/good_first_issue/actions/runs/22256362402)
>
> To add this workflow in your repository, run `gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4`. See [usage guide](https://github.github.com/gh-aw/guides/packaging-imports/).
Contributor guide
Assessment
This issue has not been assessed yet.