mirror of
https://github.com/we-promise/sure.git
synced 2026-07-21 01:05:28 +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>
451 lines
15 KiB
Dart
451 lines
15 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../models/custom_proxy_header.dart';
|
|
import '../services/api_config.dart';
|
|
import '../services/custom_proxy_headers_service.dart';
|
|
import '../services/log_service.dart';
|
|
import '../widgets/custom_proxy_headers_editor.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
|
|
class BackendConfigScreen extends StatefulWidget {
|
|
final VoidCallback? onConfigSaved;
|
|
|
|
const BackendConfigScreen({super.key, this.onConfigSaved});
|
|
|
|
@override
|
|
State<BackendConfigScreen> createState() => _BackendConfigScreenState();
|
|
}
|
|
|
|
class _BackendConfigScreenState extends State<BackendConfigScreen> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
final _urlController = TextEditingController();
|
|
bool _isLoading = false;
|
|
bool _isTesting = false;
|
|
bool _hasLoadedConfig = false;
|
|
String? _errorMessage;
|
|
String? _successMessage;
|
|
List<CustomProxyHeader> _customHeaders = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadSavedUrl();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_urlController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _loadSavedUrl() async {
|
|
String urlToShow = ApiConfig.baseUrl;
|
|
List<CustomProxyHeader> headers = const [];
|
|
try {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final savedUrl = prefs.getString('backend_url');
|
|
headers = await CustomProxyHeadersService.instance.loadHeaders();
|
|
if (savedUrl != null && savedUrl.isNotEmpty) {
|
|
urlToShow = savedUrl;
|
|
}
|
|
} catch (e) {
|
|
// Swallow storage failures so the screen still becomes interactive with
|
|
// sensible defaults; the user can re-enter and re-save.
|
|
LogService.instance.warning(
|
|
'BackendConfigScreen',
|
|
'Failed to load saved backend config with ${e.runtimeType}',
|
|
);
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
_urlController.text = urlToShow;
|
|
_customHeaders = headers;
|
|
_hasLoadedConfig = true;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _testConnection() async {
|
|
if (!_formKey.currentState!.validate()) return;
|
|
|
|
final l = AppLocalizations.of(context);
|
|
|
|
setState(() {
|
|
_isTesting = true;
|
|
_errorMessage = null;
|
|
_successMessage = null;
|
|
});
|
|
|
|
final previousHeaders = ApiConfig.customProxyHeaders;
|
|
try {
|
|
// Normalize base URL by removing trailing slashes
|
|
final normalizedUrl = _urlController.text.trim().replaceAll(
|
|
RegExp(r'/+$'),
|
|
'',
|
|
);
|
|
|
|
// Apply the unsaved edits only for the duration of this probe so the
|
|
// test reflects what the user is about to save. Restored in `finally`.
|
|
ApiConfig.setCustomProxyHeaders(_customHeaders);
|
|
|
|
// Check /sessions/new page to verify it's a Sure backend
|
|
final sessionsUrl = Uri.parse('$normalizedUrl/sessions/new');
|
|
final sessionsResponse =
|
|
await http.get(sessionsUrl, headers: ApiConfig.htmlHeaders()).timeout(
|
|
const Duration(seconds: 10),
|
|
onTimeout: () {
|
|
throw Exception(l.backendConfigTimeout);
|
|
},
|
|
);
|
|
|
|
if (sessionsResponse.statusCode >= 200 &&
|
|
sessionsResponse.statusCode < 400) {
|
|
if (mounted) {
|
|
setState(() {
|
|
_successMessage = l.backendConfigSuccess;
|
|
});
|
|
}
|
|
} else {
|
|
if (mounted) {
|
|
setState(() {
|
|
_errorMessage =
|
|
l.backendConfigServerError(sessionsResponse.statusCode);
|
|
});
|
|
}
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
setState(() {
|
|
_errorMessage = l.backendConfigConnectionFailed(e.toString());
|
|
});
|
|
}
|
|
} finally {
|
|
ApiConfig.setCustomProxyHeaders(previousHeaders);
|
|
if (mounted) {
|
|
setState(() {
|
|
_isTesting = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> _saveAndContinue() async {
|
|
if (!_formKey.currentState!.validate()) return;
|
|
|
|
final l = AppLocalizations.of(context);
|
|
|
|
setState(() {
|
|
_isLoading = true;
|
|
_errorMessage = null;
|
|
});
|
|
|
|
try {
|
|
// Normalize base URL by removing trailing slashes
|
|
final normalizedUrl = _urlController.text.trim().replaceAll(
|
|
RegExp(r'/+$'),
|
|
'',
|
|
);
|
|
|
|
// Save URL to SharedPreferences
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString('backend_url', normalizedUrl);
|
|
|
|
// Save custom proxy headers
|
|
await CustomProxyHeadersService.instance.saveHeaders(_customHeaders);
|
|
ApiConfig.setCustomProxyHeaders(_customHeaders);
|
|
|
|
// Update ApiConfig
|
|
ApiConfig.setBaseUrl(normalizedUrl);
|
|
|
|
// Notify parent that config is saved
|
|
if (mounted && widget.onConfigSaved != null) {
|
|
widget.onConfigSaved!();
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
setState(() {
|
|
_errorMessage = l.backendConfigSaveFailed(e.toString());
|
|
});
|
|
}
|
|
} finally {
|
|
if (mounted) {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
String? _validateUrl(String? value, AppLocalizations l) {
|
|
if (value == null || value.isEmpty) {
|
|
return l.backendConfigUrlRequired;
|
|
}
|
|
|
|
final trimmedValue = value.trim();
|
|
|
|
// Check if it starts with http:// or https://
|
|
if (!trimmedValue.startsWith('http://') &&
|
|
!trimmedValue.startsWith('https://')) {
|
|
return l.backendConfigUrlScheme;
|
|
}
|
|
|
|
// Basic URL validation
|
|
try {
|
|
final uri = Uri.parse(trimmedValue);
|
|
if (!uri.hasScheme || uri.host.isEmpty) {
|
|
return l.backendConfigUrlInvalid;
|
|
}
|
|
} catch (e) {
|
|
return l.backendConfigUrlInvalid;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l = AppLocalizations.of(context);
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const SizedBox(height: 48),
|
|
// Logo/Title
|
|
Icon(
|
|
Icons.settings_outlined,
|
|
size: 80,
|
|
color: colorScheme.primary,
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
l.backendConfigTitle,
|
|
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
color: colorScheme.primary,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
l.backendConfigSubtitle,
|
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 48),
|
|
|
|
// Info box
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.primaryContainer.withValues(alpha: 0.3),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(Icons.info_outline, color: colorScheme.primary),
|
|
const SizedBox(width: 12),
|
|
Text(
|
|
l.backendConfigExampleUrlsLabel,
|
|
style: TextStyle(
|
|
color: colorScheme.primary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(
|
|
'• https://demo.sure.am\n'
|
|
'• https://your-domain.com\n'
|
|
'• http://localhost:3000',
|
|
style: TextStyle(
|
|
color: colorScheme.onSurface,
|
|
fontFamily: 'monospace',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
|
|
// Error Message
|
|
if (_errorMessage != null)
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.errorContainer,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.error_outline, color: colorScheme.error),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
_errorMessage!,
|
|
style: TextStyle(
|
|
color: colorScheme.onErrorContainer,
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () {
|
|
setState(() {
|
|
_errorMessage = null;
|
|
});
|
|
},
|
|
iconSize: 20,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// Success Message
|
|
if (_successMessage != null)
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.green.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: Colors.green),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
const Icon(
|
|
Icons.check_circle_outline,
|
|
color: Colors.green,
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
_successMessage!,
|
|
style: TextStyle(color: Colors.green[800]),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () {
|
|
setState(() {
|
|
_successMessage = null;
|
|
});
|
|
},
|
|
iconSize: 20,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// URL Field
|
|
TextFormField(
|
|
controller: _urlController,
|
|
keyboardType: TextInputType.url,
|
|
autocorrect: false,
|
|
textInputAction: TextInputAction.done,
|
|
decoration: InputDecoration(
|
|
labelText: l.backendConfigUrlLabel,
|
|
prefixIcon: const Icon(Icons.cloud_outlined),
|
|
hintText: l.backendConfigUrlHint,
|
|
),
|
|
validator: (value) => _validateUrl(value, l),
|
|
onFieldSubmitted: (_) => _saveAndContinue(),
|
|
),
|
|
const SizedBox(height: 24),
|
|
ExpansionTile(
|
|
tilePadding: EdgeInsets.zero,
|
|
leading: const Icon(Icons.http_outlined),
|
|
title: Text(l.backendConfigProxyHeadersLabel),
|
|
subtitle: Text(
|
|
_customHeaders.isEmpty
|
|
? l.backendConfigProxyHeadersSubtitle
|
|
: l.backendConfigProxyHeadersCount(_customHeaders.length),
|
|
),
|
|
children: [
|
|
const SizedBox(height: 8),
|
|
if (_hasLoadedConfig)
|
|
CustomProxyHeadersEditor(
|
|
initialHeaders: _customHeaders,
|
|
onChanged: (headers) {
|
|
setState(() => _customHeaders = headers);
|
|
},
|
|
)
|
|
else
|
|
const Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
l.backendConfigHeadersHelp,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Test Connection Button
|
|
OutlinedButton.icon(
|
|
onPressed: _isTesting || _isLoading ? null : _testConnection,
|
|
icon: _isTesting
|
|
? const SizedBox(
|
|
height: 16,
|
|
width: 16,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(Icons.cable),
|
|
label: Text(_isTesting ? l.backendConfigTesting : l.backendConfigTestButton),
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
// Continue Button
|
|
ElevatedButton(
|
|
onPressed: _isLoading || _isTesting ? null : _saveAndContinue,
|
|
child: _isLoading
|
|
? const SizedBox(
|
|
height: 20,
|
|
width: 20,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: Text(l.backendConfigContinueButton),
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Info text
|
|
Text(
|
|
l.backendConfigChangeHint,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: colorScheme.onSurfaceVariant,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|