chimon2000 / chimon2000/good_first_issue

Duplicate Code: Identical EmptyCard and InitialCard Widget Classes

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
19
Forks
29
Avg merge
6h 51m
Merged PRs (30d)
2

Description

*Analysis of commit eaf30ea*

## Summary

Two widget classes (`EmptyCard` and `InitialCard`) are completely identical in implementation, differing only in their class names. Both render an empty centered column with no children, representing 100% code duplication across 17 lines.

## Duplication Details

### Pattern: Identical Widget Classes
- **Severity**: High
- **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
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 [],
),
);
}
}
``````

## Impact Analysis

- **Maintainability**: Any changes to the UI structure must be duplicated across both files, increasing maintenance burden and risk of inconsistency
- **Bug Risk**: If one widget is updated but the other isn't, it could lead to inconsistent user experience between loading and empty states
- **Code Bloat**: 17 lines of completely redundant code that provides no additional value

## Refactoring Recommendations

### Option 1: Consolidate into Single Parameterized Widget (Recommended)
- Create a single `PlaceholderCard` widget that can be configured for different states
- Replace both `EmptyCard` and `InitialCard` with this unified widget
- Benefits: Single source of truth, easier to maintain and extend

``````dart
// lib/ui/widgets/placeholder_card.dart
import 'package:flutter/material.dart';

class PlaceholderCard extends StatelessWidget {
const PlaceholderCard({
Key? key,
this.message,
this.icon,
}) : super(key: key);

final String? message;
final IconData? icon;

`@override`
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (icon != null) Icon(icon, size: 48, color: Colors.grey),
if (message != null) ...[
const SizedBox(height: 16),
Text(message!, style: Theme.of(context).textTheme.bodyLarge),
],
],
),
);
}
}
``````

### Option 2: Use Type Aliases
- If the widgets truly need separate names for semantic clarity, use type aliases
- Keep single implementation, provide multiple names

``````dart
// lib/ui/widgets/placeholder_cards.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 [],
),
);
}
}

// Type aliases for semantic clarity
class EmptyCard extends _PlaceholderCard {
const EmptyCard({Key? key}) : super(key: key);
}

class InitialCard extends _PlaceholderCard {
const InitialCard({Key? key}) : super(key: key);
}
``````

## Implementation Checklist

- [ ] Review duplication findings
- [ ] Decide between consolidation approach (Option 1 recommended)
- [ ] Create unified widget implementation
- [ ] Update all references in `lib/ui/pages/home.dart`
- [ ] Remove duplicate widget files
- [ ] Update widget exports in `lib/ui/widgets/widgets.dart`
- [ ] Run tests to verify no functionality broken
- [ ] Consider adding visual content (icons, messages) to improve UX

## Analysis Metadata

- **Analyzed Files**: 32 Dart files
- **Detection Method**: Manual code review and pattern analysis
- **Commit**: eaf30ea
- **Analysis Date**: 2026-02-13

> AI generated by [Duplicate Code Detector](https://github.com/chimon2000/good_first_issue/actions/runs/21986010646)
>
> 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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.