chimon2000 / chimon2000/good_first_issue
Duplicate Code: Identical EmptyCard and InitialCard Widget Classes
- Dominant language
- Dart
- Stars
- 19
- Forks
- 29
- Avg merge
- 6h 51m
- Merged PRs (30d)
- 2
Description
## Summary
Two widget classes (`EmptyCard` and `InitialCard`) contain identical code with only their class names differing. These 17-line files are exact duplicates and represent unnecessary code duplication.
## Duplication Details
### Pattern: Identical Widget Classes
- **Severity**: Medium
- **Occurrences**: 2 instances
- **Locations**:
- `lib/ui/widgets/empty_card.dart` (lines 1-17)
- `lib/ui/widgets/initial_card.dart` (lines 1-17)
- **Code Sample**:
``````dart
// Both files contain the exact same structure:
import 'package:flutter/material.dart';
class EmptyCard extends StatelessWidget { // InitialCard in the other file
const EmptyCard({
Key? key,
}) : super(key: key);
`@override`
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [],
),
);
}
}
``````
### Diff Analysis
The only difference between these files is the class name:
- `EmptyCard` vs `InitialCard`
- Constructor name: `const EmptyCard({` vs `const InitialCard({`
## Impact Analysis
- **Maintainability**: Any changes to the widget structure must be duplicated across both files
- **Bug Risk**: If one widget needs updates, developers might forget to update the other
- **Code Bloat**: 17 unnecessary lines of duplicated code
- **Confusion**: Two separate classes serve the same purpose with no functional difference
## Refactoring Recommendations
### Option 1: Single Parameterized Widget (Recommended)
Create a single `PlaceholderCard` widget that serves both purposes:
``````dart
// lib/ui/widgets/placeholder_card.dart
import 'package:flutter/material.dart';
class PlaceholderCard extends StatelessWidget {
const PlaceholderCard({
Key? key,
}) : super(key: key);
`@override`
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [],
),
);
}
}
``````
Then update usage sites:
- Replace `EmptyCard()` with `PlaceholderCard()` in `lib/ui/pages/home.dart:77`
- Replace `InitialCard()` with `PlaceholderCard()` in `lib/ui/pages/home.dart:75`
**Benefits**:
- Eliminates duplicate code
- Single source of truth for placeholder UI
- Easier to maintain and extend
**Estimated effort**: 15 minutes
### Option 2: Type Aliases (Alternative)
If semantic distinction is important, create one implementation and alias:
``````dart
// lib/ui/widgets/placeholder_card.dart
class PlaceholderCard extends StatelessWidget { /* implementation */ }
// lib/ui/widgets/empty_card.dart
export 'placeholder_card.dart' show PlaceholderCard as EmptyCard;
// lib/ui/widgets/initial_card.dart
export 'placeholder_card.dart' show PlaceholderCard as InitialCard;
``````
**Note**: This maintains backward compatibility but doesn't truly eliminate duplication.
### Option 3: Add Distinguishing Content
If these widgets should be different, add actual content to distinguish them:
``````dart
// Empty state: Show "No issues found" message
// Initial state: Show loading indicator or welcome message
``````
## Implementation Checklist
- [ ] Review duplication findings
- [ ] Choose refactoring approach (recommend Option 1)
- [ ] Create unified `PlaceholderCard` widget
- [ ] Update import statements in `home.dart`
- [ ] Replace `EmptyCard` and `InitialCard` usage
- [ ] Delete duplicate files
- [ ] Update widget barrel export in `lib/ui/widgets/widgets.dart`
- [ ] Run tests to verify no functionality broken
- [ ] Consider adding actual content to distinguish states
## Analysis Metadata
- **Analyzed Files**: 29 Dart files
- **Detection Method**: Manual code review and diff analysis
- **Commit**: eaf30ea
- **Analysis Date**: 2026-02-23
- **Lines Duplicated**: 17 lines (100% identical)
> AI generated by [Duplicate Code Detector](https://github.com/chimon2000/good_first_issue/actions/runs/22305247459)
>
> 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.