Skip to content

Commit cf626c7

Browse files
committed
fix: show legacy badge dialog and restore cliparts on import
- Add BadgeLoaderHelper.isLegacyBadge() to detect badges missing original text (created before BadgeTextStorage was introduced) - Show AlertDialog on edit attempt for legacy badges, offering a 'Create New' option instead of opening a broken editor session - Add legacyBadgeTitle, legacyBadgeMessage and createNew keys to app_en.arb for full i18n support Closes #1769
1 parent a1c9337 commit cf626c7

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

lib/bademagic_module/utils/badge_loader_helper.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import 'package:path_provider/path_provider.dart';
1010
/// Helper class for loading and parsing badge data and original text from disk.
1111
/// This class centralizes logic-heavy operations for badge editing, keeping UI code clean and testable.
1212
class BadgeLoaderHelper {
13+
/// Checks if a badge is a legacy badge (no stored original text).
14+
///
15+
/// [badgeFilename] is the filename of the badge JSON.
16+
static Future<bool> isLegacyBadge(String badgeFilename) async {
17+
final textFilename =
18+
badgeFilename.endsWith('.json') ? badgeFilename : '$badgeFilename.json';
19+
final text = await BadgeTextStorage.getOriginalText(textFilename);
20+
return text.isEmpty;
21+
}
22+
1323
/// Loads badge data and original text from disk for editing.
1424
///
1525
/// [badgeFilename] is the filename of the badge JSON (with or without .json extension).

lib/l10n/app_en.arb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,8 @@
232232
"shareQrImage": "Share QR image",
233233
"couldNotGenerateQrImage": "Could not generate QR image.",
234234
"couldNotShareQrImage": "Could not share QR image.",
235-
"qrShareInstruction": "Scan this code from another device, or tap share to send the QR image."
235+
"qrShareInstruction": "Scan this code from another device, or tap share to send the QR image.",
236+
"legacyBadgeTitle": "Old Badge Format",
237+
"legacyBadgeMessage": "This badge was created with an older version of the app and cannot be edited directly. Please create a new badge and recreate your design.",
238+
"createNew": "Create New"
236239
}

lib/view/widgets/save_badge_card.dart

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:badgemagic/bademagic_module/models/speed.dart';
2+
import 'package:badgemagic/bademagic_module/utils/badge_loader_helper.dart';
23
import 'package:badgemagic/bademagic_module/utils/byte_array_utils.dart';
34
import 'package:badgemagic/bademagic_module/utils/converters.dart';
45
import 'package:badgemagic/bademagic_module/utils/file_helper.dart';
@@ -109,11 +110,46 @@ class SaveBadgeCard extends StatelessWidget {
109110
),
110111
onPressed: () async {
111112
final navigator = Navigator.of(context);
112-
// Show confirmation dialog before editing
113+
final l10n =
114+
GetIt.instance.get<LocalizationService>().l10n;
115+
116+
// Check if this is a legacy badge (no stored text).
117+
final isLegacy = await BadgeLoaderHelper.isLegacyBadge(
118+
badgeData.key);
119+
if (isLegacy) {
120+
if (!context.mounted) return;
121+
await showDialog<void>(
122+
context: context,
123+
builder: (ctx) => AlertDialog(
124+
title: Text(l10n.legacyBadgeTitle),
125+
content: Text(l10n.legacyBadgeMessage),
126+
actions: [
127+
TextButton(
128+
onPressed: () => Navigator.pop(ctx),
129+
child: Text(l10n.cancel),
130+
),
131+
TextButton(
132+
onPressed: () {
133+
Navigator.pop(ctx);
134+
navigator.push(
135+
MaterialPageRoute(
136+
builder: (_) => const HomeScreen(),
137+
),
138+
);
139+
},
140+
child: Text(l10n.createNew),
141+
),
142+
],
143+
),
144+
);
145+
return;
146+
}
147+
148+
// Modern badge — show confirmation then open editor.
149+
if (!context.mounted) return;
113150
final confirmed =
114151
await provider.showEditBadgeConfirmation(context);
115152
if (confirmed) {
116-
// Navigate to HomeScreen for editing the badge
117153
navigator.push(
118154
MaterialPageRoute(
119155
builder: (context) => HomeScreen(

0 commit comments

Comments
 (0)