mirror of
https://github.com/we-promise/sure.git
synced 2026-07-19 08:15:21 +00:00
* feat(mobile): add Flutter i18n foundation (gen_l10n Phase 1)
- Wire flutter_localizations + gen_l10n (pubspec.yaml + l10n.yaml)
- Bump intl ^0.18.1 → ^0.20.2 for Flutter 3.32 pin
- Add lib/l10n/app_en.arb with 9 seed keys (appTitle, 3 common*, 4 chatSuggestion*)
- Generate AppLocalizations via flutter gen-l10n
- Replace MaterialApp title: with onGenerateTitle + localizationsDelegates + supportedLocales
- Migrate suggested_questions.dart from const list to BuildContext function
- Update chat_conversation_screen.dart call site (one-line change at pre-designed seam)
* feat(mobile): migrate all hardcoded UI strings to gen_l10n ARB (Phase 2)
Extends the i18n foundation from Phase 1 to cover every remaining
hardcoded user-facing string across the mobile app.
Files changed (21 source files + ARB/generated):
- lib/l10n/app_en.arb: 226 keys (+~80 new keys covering all screens)
- lib/screens/dashboard_screen.dart
- lib/screens/calendar_screen.dart
- lib/screens/transactions_list_screen.dart
- lib/screens/backend_config_screen.dart
- lib/screens/recent_transactions_screen.dart
- lib/screens/biometric_lock_screen.dart
- lib/screens/chat_conversation_screen.dart
- lib/screens/chat_list_screen.dart
- lib/screens/log_viewer_screen.dart
- lib/screens/login_screen.dart
- lib/screens/main_navigation_screen.dart
- lib/screens/more_screen.dart
- lib/screens/settings_screen.dart
- lib/screens/sso_onboarding_screen.dart
- lib/screens/transaction_edit_screen.dart
- lib/screens/transaction_form_screen.dart
- lib/widgets/account_detail_header.dart
- lib/widgets/category_filter.dart
- lib/widgets/connectivity_banner.dart
- lib/widgets/currency_filter.dart
- lib/widgets/custom_proxy_headers_editor.dart
Notable patterns:
- ICU plural for connectivity pending-sync count
- Parameterised keys for greeting (firstName), update dialog
(version), cash chip (amount), delete confirmation (name),
show-N menu (count), proxy-headers count, multi-delete count
- AppLocalizations captured before async gaps; dialog builders
re-obtain from their own BuildContext
- const removed only from Text/InputDecoration/SnackBar/Row
widgets that directly reference localisation getters; sibling
const widgets preserved
116/116 unit tests pass; flutter analyze --no-fatal-infos: 0 errors.
* feat(mobile): migrate the remaining secondary UI strings to gen_l10n ARB
Completes the i18n migration by covering the lower-traffic strings the
earlier passes left behind — secondary dialogs, snackbars, settings
rows, validators, helper texts, and tooltips across 11 files.
- settings_screen.dart: reset/delete-account dialogs, clear-data and
proxy-header snackbars, list-tile titles/subtitles, theme-segment
tooltips, biometric prompt reason, debug-logs semantics label
- transaction_form_screen.dart: amount validators, session/success/
failure/generic-error snackbars, More/Less toggle, date/name/category
fields + helper texts, create button
- transaction_edit_screen.dart: session/update snackbars, validators,
category/merchant/tag fallbacks, synced-only notice
- login_screen.dart: API-key dialog, demo/sign-up TextSpan, MFA info +
validator, divider, server-URL heading, API-key + backend tooltip
- chat_list_screen.dart: multi-delete plural, result snackbars, error
heading, relative-time fallback
- chat_conversation_screen.dart: edit-title dialog, refresh tooltip,
load-error heading
- connectivity_banner.dart: sign-in / sync-success / sync-failure /
auth-failure snackbars (also resolves the const removals cleanly)
- main_navigation_screen.dart: enable-AI dialog + failure snackbar
- log_viewer_screen.dart: clear-logs confirmation dialog
- biometric_lock_screen.dart, transactions_list_screen.dart: snackbar
and edit tooltip
Adds 98 ARB keys (now 324 total), reusing common* and existing
screen keys where text matched. Interpolations use String/int
placeholders; multi-delete uses an ICU plural. AppLocalizations is
captured before async gaps and re-obtained inside dialog builders;
const removed only where a localisation getter is introduced, with
const restored on still-const siblings.
116/116 unit tests pass; flutter analyze --no-fatal-infos: 0 errors
(6 pre-existing infos unchanged). No remaining hardcoded user-facing
strings (verified by grep; only a doc-comment example remains).
* fix(mobile): address i18n review feedback and prune dead ARB keys
Resolves the still-valid CodeRabbit/Codex review findings on the i18n
migration; the majority were already handled by earlier commits.
- pubspec: switch intl to `any` so flutter_localizations selects the
SDK-pinned version (0.19.x on <3.32, 0.20.x on 3.32+). Pinning
^0.20.2 conflicted with the declared `flutter: '>=3.27.0'` floor and
would break `flutter pub get` on pre-3.32 SDKs.
- sso_onboarding: localize "Signed in as {email}" / "Google account
verified" / the link- and create-form notes; fix the first/last-name
validators that wrongly returned the "Email is required" message.
- backend_config: localize _testConnection / _saveAndContinue /
_validateUrl messages and the headers helper text (validator now
takes AppLocalizations; async methods capture it before awaits).
- recent_transactions: localize "Unknown Account"; locale-aware
timestamp.
- account_detail_header: localize the unavailable-details message via a
render-time flag (avoids touching inherited widgets in the
initState-driven load path); treat empty/whitespace securityName as
missing for the holding-name fallback.
- dashboard: wrap syncing/refreshing snackbar text in Expanded to avoid
overflow with long translations; use the distinct dashboardSyncError
key on the exception path.
- chat_list: localize relative-time labels (plural keys) and use a
locale-aware fallback date; calendar: locale-aware displayed dates and
weekday letters (map-key formats left fixed; Sunday-anchored grid
preserved).
- connectivity_banner: capture ScaffoldMessenger before the async gap
(removes use_build_context_synchronously); log_viewer: const Duration.
- Prune 55 unused ARB keys (never-wired scaffolding + superseded
duplicates). ARB now 298 keys, 0 unused.
116/116 tests pass; flutter analyze --no-fatal-infos: 0 errors, only 3
pre-existing infos in the untouched intro_screen_web.dart.
* fix(mobile): localize the log viewer empty-state string
The 'No logs yet' empty state was the last hardcoded user-facing string
(the logViewerEmpty key had been pruned before this string was migrated).
Re-add the key and route the empty state through AppLocalizations.
Closes the final CodeRabbit i18n-coverage thread. 0 analyze errors,
116 tests pass, ARB at 299 keys with 0 unused.
* fix(mobile): address i18n review feedback
- sso_onboarding: the "Accept Invitation" tab and submit buttons showed
the Terms-of-Service string (ssoOnboardingAcceptTerms) when a household
invitation was pending. Add ssoOnboardingAcceptInvitation and use it in
both spots; drop the now-unused ToS key (no ToS checkbox exists).
- transaction_form: restore the required-field indicator on the amount
label ("Amount *") that the migration dropped.
- settings: localize the "a newer version" fallback used in the update
dialog when the store version is unknown.
- ARB plurals: use the CLDR `one{}` category instead of the exact-match
`=1{}` so future non-English locales pluralize correctly. English output
is unchanged.
ARB at 300 keys, 0 unused. 116 tests pass; flutter analyze: no new issues.
* fix(mobile): reconcile i18n with design-system primitives after merge
The merge of main into this branch pulled in the design-system primitive
migrations (SureCard/SureChip/SureSegmentedControl/SureTextField/
SureListGroup), which collided with the i18n string migration and left
several files broken (compile errors / un-localized text).
Re-apply the i18n migration on top of the design-system versions:
- more_screen: SureListGroup/SureListRow rows now use l.more* keys
(was a mangled mix of _buildMenuItem + SureListGroup).
- transaction_form_screen: SureSegmentedControl segments + amount/date/
name/category labels, helpers, validators, and snackbars localized;
add transactionFormAmountHelper ("Required") for the amount helper text.
- custom_proxy_headers_editor: SureTextField label/hint params localized.
- currency_filter: the "All" chip is a SureChip again (the merge had left
it as a Material FilterChip) and uses l.commonAll.
- currency_filter_test / custom_proxy_headers_editor_test: add the
localization delegates the widgets now require.
ARB at 301 keys, 0 unused. 165 tests pass; flutter analyze: 0 errors.
---------
Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
429 lines
13 KiB
Dart
429 lines
13 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../models/category.dart' as models;
|
|
import '../models/merchant.dart';
|
|
import '../models/offline_transaction.dart';
|
|
import '../models/transaction_tag.dart';
|
|
import '../providers/auth_provider.dart';
|
|
import '../providers/categories_provider.dart';
|
|
import '../providers/merchants_provider.dart';
|
|
import '../providers/tags_provider.dart';
|
|
import '../providers/transactions_provider.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
|
|
class TransactionEditScreen extends StatefulWidget {
|
|
final OfflineTransaction transaction;
|
|
|
|
const TransactionEditScreen({super.key, required this.transaction});
|
|
|
|
@override
|
|
State<TransactionEditScreen> createState() => _TransactionEditScreenState();
|
|
}
|
|
|
|
class _TransactionEditScreenState extends State<TransactionEditScreen> {
|
|
static const _maxNameLength = 255;
|
|
static const _maxNotesLength = 2000;
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
late final TextEditingController _nameController;
|
|
late final TextEditingController _notesController;
|
|
String? _selectedCategoryId;
|
|
String? _selectedMerchantId;
|
|
late Set<String> _selectedTagIds;
|
|
bool _isSaving = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_nameController = TextEditingController(text: widget.transaction.name);
|
|
_notesController = TextEditingController(
|
|
text: widget.transaction.notes ?? '',
|
|
);
|
|
_selectedCategoryId = widget.transaction.categoryId;
|
|
_selectedMerchantId = widget.transaction.merchantId;
|
|
_selectedTagIds = widget.transaction.tagIds.toSet();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _loadMetadata());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_nameController.dispose();
|
|
_notesController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _loadMetadata() async {
|
|
final authProvider = Provider.of<AuthProvider>(context, listen: false);
|
|
final categoriesProvider = Provider.of<CategoriesProvider>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
final merchantsProvider = Provider.of<MerchantsProvider>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
final tagsProvider = Provider.of<TagsProvider>(context, listen: false);
|
|
final accessToken = await authProvider.getValidAccessToken();
|
|
if (accessToken == null || !mounted) return;
|
|
|
|
try {
|
|
await Future.wait([
|
|
categoriesProvider.fetchCategories(accessToken: accessToken),
|
|
merchantsProvider.fetchMerchants(accessToken: accessToken),
|
|
tagsProvider.fetchTags(accessToken: accessToken),
|
|
]);
|
|
} catch (_) {
|
|
// Providers expose their own error state; avoid an uncaught async error.
|
|
}
|
|
}
|
|
|
|
Future<void> _save() async {
|
|
final l = AppLocalizations.of(context);
|
|
if (!_formKey.currentState!.validate() || widget.transaction.id == null) {
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
_isSaving = true;
|
|
});
|
|
|
|
final authProvider = Provider.of<AuthProvider>(context, listen: false);
|
|
final transactionsProvider = Provider.of<TransactionsProvider>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
final accessToken = await authProvider.getValidAccessToken();
|
|
|
|
if (accessToken == null) {
|
|
if (!mounted) return;
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(l.transactionEditSessionExpired),
|
|
backgroundColor: Colors.red,
|
|
),
|
|
);
|
|
setState(() {
|
|
_isSaving = false;
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Empty notes intentionally clear the server-side note.
|
|
final notesText = _notesController.text.trim();
|
|
|
|
final success = await transactionsProvider.updateTransaction(
|
|
accessToken: accessToken,
|
|
transaction: widget.transaction,
|
|
name: _nameController.text.trim(),
|
|
notes: notesText,
|
|
categoryId: _selectedCategoryId,
|
|
merchantId: _selectedMerchantId,
|
|
tagIds: _selectedTagIds.toList(),
|
|
);
|
|
|
|
if (!mounted) return;
|
|
|
|
setState(() {
|
|
_isSaving = false;
|
|
});
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
success
|
|
? l.transactionEditUpdated
|
|
: transactionsProvider.error ?? l.transactionEditUpdateFailed,
|
|
),
|
|
backgroundColor: success ? Colors.green : Colors.red,
|
|
),
|
|
);
|
|
|
|
if (success) {
|
|
Navigator.pop(context, true);
|
|
}
|
|
}
|
|
|
|
String? _validateName(String? value) {
|
|
final l = AppLocalizations.of(context);
|
|
if (value == null || value.trim().isEmpty) {
|
|
return l.transactionEditNameRequired;
|
|
}
|
|
|
|
if (value.trim().length > _maxNameLength) {
|
|
return l.transactionEditNameMaxLength(_maxNameLength);
|
|
}
|
|
|
|
if (_containsControlCharacter(value)) {
|
|
return l.transactionEditNameInvalidChars;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
String? _validateNotes(String? value) {
|
|
final l = AppLocalizations.of(context);
|
|
if (value == null || value.trim().isEmpty) {
|
|
return null;
|
|
}
|
|
|
|
if (value.trim().length > _maxNotesLength) {
|
|
return l.transactionEditNotesMaxLength(_maxNotesLength);
|
|
}
|
|
|
|
if (_containsControlCharacter(value, allowWhitespace: true)) {
|
|
return l.transactionEditNotesInvalidChars;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
bool _containsControlCharacter(
|
|
String value, {
|
|
bool allowWhitespace = false,
|
|
}) {
|
|
for (final codeUnit in value.codeUnits) {
|
|
if (codeUnit == 127) return true;
|
|
if (codeUnit < 32) {
|
|
final allowedWhitespace = allowWhitespace &&
|
|
(codeUnit == 9 || codeUnit == 10 || codeUnit == 13);
|
|
if (!allowedWhitespace) return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
List<DropdownMenuItem<String?>> _categoryItems(
|
|
List<models.Category> categories,
|
|
) {
|
|
final l = AppLocalizations.of(context);
|
|
final items = <DropdownMenuItem<String?>>[];
|
|
if (_selectedCategoryId == null) {
|
|
items.add(
|
|
DropdownMenuItem<String?>(
|
|
value: null,
|
|
child: Text(l.transactionEditNoCategory),
|
|
),
|
|
);
|
|
}
|
|
|
|
final hasCurrent = _selectedCategoryId == null ||
|
|
categories.any((category) => category.id == _selectedCategoryId);
|
|
if (!hasCurrent) {
|
|
items.add(
|
|
DropdownMenuItem<String?>(
|
|
value: _selectedCategoryId,
|
|
child: Text(widget.transaction.categoryName ?? l.transactionEditCurrentCategory),
|
|
),
|
|
);
|
|
}
|
|
|
|
items.addAll(
|
|
categories.map((category) {
|
|
return DropdownMenuItem<String?>(
|
|
value: category.id,
|
|
child: Text(category.displayName),
|
|
);
|
|
}),
|
|
);
|
|
|
|
return items;
|
|
}
|
|
|
|
List<DropdownMenuItem<String?>> _merchantItems(List<Merchant> merchants) {
|
|
final l = AppLocalizations.of(context);
|
|
final items = <DropdownMenuItem<String?>>[];
|
|
if (_selectedMerchantId == null) {
|
|
items.add(
|
|
DropdownMenuItem<String?>(
|
|
value: null,
|
|
child: Text(l.transactionEditNoMerchant),
|
|
),
|
|
);
|
|
}
|
|
|
|
final hasCurrent = _selectedMerchantId == null ||
|
|
merchants.any((merchant) => merchant.id == _selectedMerchantId);
|
|
if (!hasCurrent) {
|
|
items.add(
|
|
DropdownMenuItem<String?>(
|
|
value: _selectedMerchantId,
|
|
child: Text(widget.transaction.merchantName ?? l.transactionEditCurrentMerchant),
|
|
),
|
|
);
|
|
}
|
|
|
|
items.addAll(
|
|
merchants.map((merchant) {
|
|
return DropdownMenuItem<String?>(
|
|
value: merchant.id,
|
|
child: Text(merchant.name),
|
|
);
|
|
}),
|
|
);
|
|
|
|
return items;
|
|
}
|
|
|
|
Widget _buildTags(List<TransactionTag> tags, {required bool enabled}) {
|
|
final l = AppLocalizations.of(context);
|
|
if (tags.isEmpty && _selectedTagIds.isEmpty) {
|
|
return Text(l.transactionEditNoTags);
|
|
}
|
|
|
|
final tagById = {for (final tag in tags) tag.id: tag};
|
|
final combinedTags = [...tags];
|
|
for (final selectedId in _selectedTagIds) {
|
|
if (!tagById.containsKey(selectedId)) {
|
|
final nameIndex = widget.transaction.tagIds.indexOf(selectedId);
|
|
final fallbackName =
|
|
nameIndex >= 0 && nameIndex < widget.transaction.tagNames.length
|
|
? widget.transaction.tagNames[nameIndex]
|
|
: '';
|
|
combinedTags.add(
|
|
TransactionTag(
|
|
id: selectedId,
|
|
name: fallbackName.isNotEmpty ? fallbackName : l.transactionEditUnknownTag,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
return Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: combinedTags.map((tag) {
|
|
final selected = _selectedTagIds.contains(tag.id);
|
|
return FilterChip(
|
|
label: Text(tag.name),
|
|
selected: selected,
|
|
onSelected: enabled
|
|
? (value) {
|
|
setState(() {
|
|
if (value) {
|
|
_selectedTagIds.add(tag.id);
|
|
} else {
|
|
_selectedTagIds.remove(tag.id);
|
|
}
|
|
});
|
|
}
|
|
: null,
|
|
);
|
|
}).toList(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
final canEdit = widget.transaction.id != null &&
|
|
widget.transaction.syncStatus == SyncStatus.synced;
|
|
|
|
final l = AppLocalizations.of(context);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(l.transactionEditTitle)),
|
|
body: Form(
|
|
key: _formKey,
|
|
child: ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
if (!canEdit) ...[
|
|
Card(
|
|
color: colorScheme.errorContainer,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Text(
|
|
l.transactionEditSyncedOnly,
|
|
style: TextStyle(color: colorScheme.onErrorContainer),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
],
|
|
TextFormField(
|
|
controller: _nameController,
|
|
enabled: canEdit && !_isSaving,
|
|
validator: _validateName,
|
|
maxLength: _maxNameLength,
|
|
decoration: InputDecoration(
|
|
labelText: l.transactionEditNameLabel,
|
|
prefixIcon: const Icon(Icons.label),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextFormField(
|
|
controller: _notesController,
|
|
enabled: canEdit && !_isSaving,
|
|
validator: _validateNotes,
|
|
maxLength: _maxNotesLength,
|
|
minLines: 2,
|
|
maxLines: 4,
|
|
decoration: InputDecoration(
|
|
labelText: l.transactionEditNotesLabel,
|
|
prefixIcon: const Icon(Icons.notes),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Consumer<CategoriesProvider>(
|
|
builder: (context, categoriesProvider, _) {
|
|
return DropdownButtonFormField<String?>(
|
|
value: _selectedCategoryId,
|
|
decoration: InputDecoration(
|
|
labelText: l.transactionEditCategoryLabel,
|
|
prefixIcon: const Icon(Icons.category),
|
|
helperText: l.transactionEditCategoryHelper,
|
|
),
|
|
isExpanded: true,
|
|
items: _categoryItems(categoriesProvider.categories),
|
|
onChanged: canEdit && !_isSaving
|
|
? (value) => setState(() => _selectedCategoryId = value)
|
|
: null,
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 16),
|
|
Consumer<MerchantsProvider>(
|
|
builder: (context, merchantsProvider, _) {
|
|
return DropdownButtonFormField<String?>(
|
|
value: _selectedMerchantId,
|
|
decoration: InputDecoration(
|
|
labelText: l.transactionEditMerchantLabel,
|
|
prefixIcon: const Icon(Icons.storefront),
|
|
helperText: l.transactionEditMerchantHelper,
|
|
),
|
|
isExpanded: true,
|
|
items: _merchantItems(merchantsProvider.merchants),
|
|
onChanged: canEdit && !_isSaving
|
|
? (value) => setState(() => _selectedMerchantId = value)
|
|
: null,
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 24),
|
|
Text(l.transactionEditTagsLabel, style: Theme.of(context).textTheme.titleMedium),
|
|
const SizedBox(height: 8),
|
|
Consumer<TagsProvider>(
|
|
builder: (context, tagsProvider, _) =>
|
|
_buildTags(tagsProvider.tags, enabled: canEdit && !_isSaving),
|
|
),
|
|
const SizedBox(height: 32),
|
|
ElevatedButton.icon(
|
|
onPressed: canEdit && !_isSaving ? _save : null,
|
|
icon: _isSaving
|
|
? const SizedBox(
|
|
width: 20,
|
|
height: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(Icons.save),
|
|
label: Text(_isSaving ? l.transactionEditSaving : l.commonSave),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|