feat: erweiterte Chat-Funktionalität, UI-Verbesserungen und Lokalisierungsupdates

- Chat: Nachrichten-Status (read/unread), WebSocket-Verbesserungen
- App: Login-Optimierung, Job-Übersicht verbessert, neue Übersetzungen
- Backend: Dialog-Styling, Invoice-Generator, Job-Verwaltung erweitert
- Mehrsprachigkeit: Neue Übersetzungen für DE, EN, ES, ET, FR, LT, LV, PL, RU, TR
This commit is contained in:
2026-04-04 10:30:36 +02:00
parent d6132fabe1
commit bba5733783
55 changed files with 2708 additions and 697 deletions

View File

@@ -34,6 +34,8 @@ class _LoginViewState extends State<LoginView> {
bool _logoutNoticeShown = false;
bool _hasNavigatedToJobs = false;
String _appVersion = '';
String? _pendingLoginEmail;
String? _pendingLoginPassword;
@override
void initState() {
@@ -52,7 +54,13 @@ class _LoginViewState extends State<LoginView> {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
_logoutNoticeShown = true;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context).loginSuccess), backgroundColor: Colors.green, duration: const Duration(seconds: 1)));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(context).loginSuccess),
backgroundColor: Colors.green,
duration: const Duration(seconds: 1),
),
);
});
}
}
@@ -86,70 +94,144 @@ class _LoginViewState extends State<LoginView> {
// Listen to connection status changes via dart_mq
// Note: Don't reset _isLoggingIn here - the login flow in _handleLogin
// manages button state through its own error/success handling.
_connectionStatusSubscription = DartMQ().subscribe<bool>(MQTopics.connectionStatus, (isConnected) {
if (mounted) {
setState(() {});
}
});
_connectionStatusSubscription = DartMQ().subscribe<bool>(
MQTopics.connectionStatus,
(isConnected) {
if (mounted) {
setState(() {});
}
},
);
// Listen to authentication responses via dart_mq
_authResponseSubscription = DartMQ().subscribe<Map<String, dynamic>>(MQTopics.authResponse, (response) {
final responseTime = DateTime.now();
developer.log('=== AUTHENTICATION RESPONSE RECEIVED ===', name: 'LoginView');
developer.log('Timestamp: ${responseTime.toIso8601String()}', name: 'LoginView');
developer.log('Response data: $response', name: 'LoginView');
_authResponseSubscription = DartMQ().subscribe<Map<String, dynamic>>(
MQTopics.authResponse,
(response) {
final responseTime = DateTime.now();
developer.log(
'=== AUTHENTICATION RESPONSE RECEIVED ===',
name: 'LoginView',
);
developer.log(
'Timestamp: ${responseTime.toIso8601String()}',
name: 'LoginView',
);
developer.log('Response data: $response', name: 'LoginView');
if (mounted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
setState(() {
_isLoggingIn = false;
if (mounted) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_handleAuthResponse(response);
});
} else {
developer.log(
'Widget not mounted - skipping UI updates for auth response',
name: 'LoginView',
);
}
if (response['success'] == true) {
// Prevent duplicate navigation from multiple auth responses
if (_hasNavigatedToJobs) {
developer.log('Already navigated to jobs view - ignoring duplicate auth response', name: 'LoginView');
return;
}
_hasNavigatedToJobs = true;
developer.log(
'Authentication response processing completed',
name: 'LoginView',
);
},
);
}
final message = response['message'] ?? 'Anmeldung erfolgreich';
final email = _emailController.text.trim();
final password = _passwordController.text;
void _clearPendingLoginCredentials() {
_pendingLoginEmail = null;
_pendingLoginPassword = null;
}
developer.log('=== LOGIN SUCCESS ===', name: 'LoginView');
developer.log('Email: $email', name: 'LoginView');
developer.log('Message: $message', name: 'LoginView');
Future<void> _handleAuthResponse(Map<String, dynamic> response) async {
if (!mounted) return;
// Store email as login identifier
_appState.setLoggedInEmail(email);
final pendingEmail = _pendingLoginEmail?.trim();
final pendingPassword = _pendingLoginPassword;
final hadPendingLogin =
pendingEmail != null &&
pendingEmail.isNotEmpty &&
pendingPassword != null &&
pendingPassword.isNotEmpty;
_clearPendingLoginCredentials();
// Save credentials for auto-login on app restart
DatabaseService().saveCredentials(email, password);
setState(() {
_isLoggingIn = false;
});
// Navigate directly to jobs view - jobs will be loaded there
developer.log('Navigating to jobs view - jobs will be loaded there...', name: 'LoginView');
Navigator.of(context).pushReplacementNamed('/jobs');
} else {
final errorMessage = response['message'] ?? 'Unbekannter Fehler';
final errorCode = response['code'] ?? 'No code';
developer.log('=== LOGIN FAILURE ===', name: 'LoginView');
developer.log('Error message: $errorMessage', name: 'LoginView');
developer.log('Error code: $errorCode', name: 'LoginView');
developer.log('Full error response: $response', name: 'LoginView');
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('${AppLocalizations.of(context).loginFailed}: $errorMessage'), backgroundColor: Colors.red, duration: const Duration(seconds: 1)));
}
});
} else {
developer.log('Widget not mounted - skipping UI updates for auth response', name: 'LoginView');
if (response['success'] == true) {
// Prevent duplicate navigation from multiple auth responses
if (_hasNavigatedToJobs) {
developer.log(
'Already navigated to jobs view - ignoring duplicate auth response',
name: 'LoginView',
);
return;
}
developer.log('Authentication response processing completed', name: 'LoginView');
});
final message = response['message'] ?? 'Anmeldung erfolgreich';
final savedCredentials = await DatabaseService().loadCredentials();
final effectiveEmail =
(pendingEmail != null && pendingEmail.isNotEmpty)
? pendingEmail
: (savedCredentials?.email ??
_appState.loggedInEmail ??
_emailController.text.trim());
final effectivePassword =
(pendingPassword != null && pendingPassword.isNotEmpty)
? pendingPassword
: (savedCredentials?.password ?? _passwordController.text);
developer.log('=== LOGIN SUCCESS ===', name: 'LoginView');
developer.log('Email: $effectiveEmail', name: 'LoginView');
developer.log('Message: $message', name: 'LoginView');
if (effectiveEmail.isNotEmpty) {
_appState.setLoggedInEmail(effectiveEmail);
}
if (effectiveEmail.isNotEmpty && effectivePassword.isNotEmpty) {
await DatabaseService().saveCredentials(
effectiveEmail,
effectivePassword,
);
}
if (!mounted) return;
_hasNavigatedToJobs = true;
// Navigate directly to jobs view - jobs will be loaded there
developer.log(
'Navigating to jobs view - jobs will be loaded there...',
name: 'LoginView',
);
Navigator.of(context).pushReplacementNamed('/jobs');
return;
}
final errorMessage = response['message'] ?? 'Unbekannter Fehler';
final errorCode = response['code'] ?? 'No code';
developer.log('=== LOGIN FAILURE ===', name: 'LoginView');
developer.log('Error message: $errorMessage', name: 'LoginView');
developer.log('Error code: $errorCode', name: 'LoginView');
developer.log('Full error response: $response', name: 'LoginView');
if (!hadPendingLogin || !mounted) {
developer.log(
'Ignoring auth failure in LoginView because no manual login attempt is pending',
name: 'LoginView',
);
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'${AppLocalizations.of(context).loginFailed}: $errorMessage',
),
backgroundColor: Colors.red,
duration: const Duration(seconds: 1),
),
);
}
Future<void> _handleLogin() async {
@@ -158,34 +240,62 @@ class _LoginViewState extends State<LoginView> {
developer.log('=== LOGIN ATTEMPT STARTED ===', name: 'LoginView');
developer.log('Session ID: $sessionId', name: 'LoginView');
developer.log('Timestamp: ${loginStartTime.toIso8601String()}', name: 'LoginView');
developer.log(
'Timestamp: ${loginStartTime.toIso8601String()}',
name: 'LoginView',
);
if (!_formKey.currentState!.validate()) {
developer.log('Login validation failed - form is invalid', name: 'LoginView');
developer.log(
'Login validation failed - form is invalid',
name: 'LoginView',
);
return;
}
if (_isLoggingIn) {
developer.log('Login already in progress - ignoring duplicate request', name: 'LoginView');
developer.log(
'Login already in progress - ignoring duplicate request',
name: 'LoginView',
);
return;
}
String email = _emailController.text.trim();
String password = _passwordController.text;
_pendingLoginEmail = email;
_pendingLoginPassword = password;
developer.log('Login attempt for email: $email', name: 'LoginView');
developer.log('Password length: ${_passwordController.text.length} characters', name: 'LoginView');
developer.log(
'Password length: ${_passwordController.text.length} characters',
name: 'LoginView',
);
// Capture ScaffoldMessenger and localizations before any async operations
final scaffoldMessenger = ScaffoldMessenger.of(context);
final localizations = AppLocalizations.of(context);
if (!_stompService.isConnected) {
developer.log('Not connected to STOMP server - establishing connection first', name: 'LoginView');
developer.log('STOMP service connection state: ${_stompService.isConnected}', name: 'LoginView');
developer.log(
'Not connected to STOMP server - establishing connection first',
name: 'LoginView',
);
developer.log(
'STOMP service connection state: ${_stompService.isConnected}',
name: 'LoginView',
);
// Always attempt connection to fixed STOMP endpoint (no discovery gating)
// Show connecting message
if (!widget.suppressConnectionSnack) {
scaffoldMessenger.showSnackBar(SnackBar(content: Text(localizations.connecting), backgroundColor: Colors.blue, duration: const Duration(seconds: 1)));
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text(localizations.connecting),
backgroundColor: Colors.blue,
duration: const Duration(seconds: 1),
),
);
}
// Set loading state
@@ -202,20 +312,29 @@ class _LoginViewState extends State<LoginView> {
// Wait for connection to be established with a timeout
try {
final completer = Completer<bool>();
final subscription = DartMQ().subscribe<bool>(MQTopics.connectionStatus, (isConnected) {
if (isConnected && !completer.isCompleted) {
completer.complete(true);
}
});
final subscription = DartMQ().subscribe<bool>(
MQTopics.connectionStatus,
(isConnected) {
if (isConnected && !completer.isCompleted) {
completer.complete(true);
}
},
);
await completer.future.timeout(const Duration(seconds: 12));
subscription.cancel();
developer.log('STOMP connection established - proceeding with login', name: 'LoginView');
developer.log(
'STOMP connection established - proceeding with login',
name: 'LoginView',
);
} on TimeoutException {
developer.log('STOMP connection timed out', name: 'LoginView');
}
} else {
developer.log('STOMP already connected after connect - proceeding with login', name: 'LoginView');
developer.log(
'STOMP already connected after connect - proceeding with login',
name: 'LoginView',
);
}
// Check if connection was successful
@@ -223,43 +342,74 @@ class _LoginViewState extends State<LoginView> {
setState(() {
_isLoggingIn = false;
});
scaffoldMessenger.showSnackBar(SnackBar(content: Text(localizations.connectionTimeout), backgroundColor: Colors.red, duration: const Duration(seconds: 2)));
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text(localizations.connectionTimeout),
backgroundColor: Colors.red,
duration: const Duration(seconds: 2),
),
);
_clearPendingLoginCredentials();
return;
}
} catch (e, stackTrace) {
setState(() {
_isLoggingIn = false;
});
developer.log('Error connecting to STOMP server: $e', name: 'LoginView');
developer.log(
'Error connecting to STOMP server: $e',
name: 'LoginView',
);
developer.log('Stack trace: $stackTrace', name: 'LoginView');
scaffoldMessenger.showSnackBar(SnackBar(content: Text('${localizations.connectionError}: $e'), backgroundColor: Colors.red, duration: const Duration(seconds: 1)));
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text('${localizations.connectionError}: $e'),
backgroundColor: Colors.red,
duration: const Duration(seconds: 1),
),
);
_clearPendingLoginCredentials();
return;
}
}
developer.log('Pre-login checks passed - initiating login request', name: 'LoginView');
developer.log('Connection status: connected=${_stompService.isConnected}', name: 'LoginView');
developer.log(
'Pre-login checks passed - initiating login request',
name: 'LoginView',
);
developer.log(
'Connection status: connected=${_stompService.isConnected}',
name: 'LoginView',
);
setState(() {
_isLoggingIn = true;
});
String password = _passwordController.text;
developer.log('Sending login request via STOMP service...', name: 'LoginView');
developer.log(
'Sending login request via STOMP service...',
name: 'LoginView',
);
try {
// Send login request via STOMP
await _stompService.login(email, password);
final requestSentTime = DateTime.now();
final requestDuration = requestSentTime.difference(loginStartTime).inMilliseconds;
developer.log('Login request sent successfully after ${requestDuration}ms', name: 'LoginView');
final requestDuration =
requestSentTime.difference(loginStartTime).inMilliseconds;
developer.log(
'Login request sent successfully after ${requestDuration}ms',
name: 'LoginView',
);
} catch (e, stackTrace) {
final errorTime = DateTime.now();
final errorDuration = errorTime.difference(loginStartTime).inMilliseconds;
developer.log('LOGIN ERROR: Exception during login request after ${errorDuration}ms', name: 'LoginView');
developer.log(
'LOGIN ERROR: Exception during login request after ${errorDuration}ms',
name: 'LoginView',
);
developer.log('Error: $e', name: 'LoginView');
developer.log('Stack trace: $stackTrace', name: 'LoginView');
@@ -267,16 +417,28 @@ class _LoginViewState extends State<LoginView> {
_isLoggingIn = false;
});
scaffoldMessenger.showSnackBar(SnackBar(content: Text('${localizations.loginError}: $e'), backgroundColor: Colors.red, duration: const Duration(seconds: 1)));
scaffoldMessenger.showSnackBar(
SnackBar(
content: Text('${localizations.loginError}: $e'),
backgroundColor: Colors.red,
duration: const Duration(seconds: 1),
),
);
_clearPendingLoginCredentials();
}
// The auth response will be handled by the stream listener
// _isLoggingIn will be set to false in the listener
developer.log('Login request phase completed - waiting for auth response', name: 'LoginView');
developer.log(
'Login request phase completed - waiting for auth response',
name: 'LoginView',
);
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
backgroundColor: Colors.grey[50],
body: Column(
@@ -293,25 +455,54 @@ class _LoginViewState extends State<LoginView> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Logo oder App-Name
Icon(Icons.account_circle, size: 100, color: Colors.deepPurple),
Icon(
Icons.account_circle,
size: 100,
color: Colors.deepPurple,
),
const SizedBox(height: 32),
Text(AppLocalizations.of(context).welcomeBack, style: Theme.of(context).textTheme.headlineMedium?.copyWith(fontWeight: FontWeight.bold, color: Colors.grey[800]), textAlign: TextAlign.center),
Text(
l10n.welcomeBack,
style: Theme.of(
context,
).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
color: Colors.grey[800],
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(AppLocalizations.of(context).loginSubtitle, style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: Colors.grey[600]), textAlign: TextAlign.center),
Text(
l10n.loginSubtitle,
style: Theme.of(context).textTheme.bodyLarge
?.copyWith(color: Colors.grey[600]),
textAlign: TextAlign.center,
),
const SizedBox(height: 32),
// E-Mail-Feld
TextFormField(
controller: _emailController,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(labelText: 'E-Mail-Adresse', hintText: 'Geben Sie Ihre E-Mail-Adresse ein', prefixIcon: const Icon(Icons.email_outlined), border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)), filled: true, fillColor: Colors.white),
decoration: InputDecoration(
labelText: l10n.emailAddress,
hintText: l10n.emailAddressHint,
prefixIcon: const Icon(Icons.email_outlined),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
filled: true,
fillColor: Colors.white,
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bitte geben Sie Ihre E-Mail-Adresse ein';
return l10n.emailAddressRequired;
}
if (!RegExp(r'^[A-Za-z0-9_.+-]+@[A-Za-z0-9-]+\.[A-Za-z0-9.-]+$').hasMatch(value)) {
return 'Bitte geben Sie eine gültige E-Mail-Adresse ein';
if (!RegExp(
r'^[A-Za-z0-9_.+-]+@[A-Za-z0-9-]+\.[A-Za-z0-9.-]+$',
).hasMatch(value)) {
return l10n.emailAddressInvalid;
}
return null;
},
@@ -323,27 +514,33 @@ class _LoginViewState extends State<LoginView> {
controller: _passwordController,
obscureText: !_isPasswordVisible,
decoration: InputDecoration(
labelText: 'Passwort',
hintText: 'Geben Sie Ihr Passwort ein',
labelText: l10n.password,
hintText: l10n.passwordHint,
prefixIcon: const Icon(Icons.lock_outlined),
suffixIcon: IconButton(
icon: Icon(_isPasswordVisible ? Icons.visibility : Icons.visibility_off),
icon: Icon(
_isPasswordVisible
? Icons.visibility
: Icons.visibility_off,
),
onPressed: () {
setState(() {
_isPasswordVisible = !_isPasswordVisible;
});
},
),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
filled: true,
fillColor: Colors.white,
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Bitte geben Sie Ihr Passwort ein';
return l10n.passwordRequired;
}
if (value.length < 6) {
return 'Das Passwort muss mindestens 6 Zeichen lang sein';
return l10n.passwordMinLength;
}
return null;
},
@@ -356,16 +553,71 @@ class _LoginViewState extends State<LoginView> {
child: TextButton(
onPressed: () {
// Hier würde die "Passwort vergessen" Funktionalität implementiert werden
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context).forgotPasswordMessage), duration: const Duration(seconds: 1)));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(l10n.forgotPasswordMessage),
duration: const Duration(seconds: 1),
),
);
},
child: Text(AppLocalizations.of(context).forgotPassword, style: const TextStyle(color: Colors.deepPurple, fontWeight: FontWeight.w500)),
child: Text(
l10n.forgotPassword,
style: const TextStyle(
color: Colors.deepPurple,
fontWeight: FontWeight.w500,
),
),
),
),
const SizedBox(height: 24),
// Verbindungsstatus
// Anmelden Button
ElevatedButton(onPressed: _isLoggingIn ? null : _handleLogin, style: ElevatedButton.styleFrom(backgroundColor: Colors.deepPurple, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 16), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), elevation: 2), child: _isLoggingIn ? Row(mainAxisAlignment: MainAxisAlignment.center, children: const [SizedBox(width: 18, height: 18, child: CircularProgressIndicator(strokeWidth: 2.5, valueColor: AlwaysStoppedAnimation<Color>(Colors.white))), SizedBox(width: 12), Text('Verbinden…', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600))]) : const Text('Anmelden', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600))),
ElevatedButton(
onPressed: _isLoggingIn ? null : _handleLogin,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.deepPurple,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 2,
),
child:
_isLoggingIn
? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(
strokeWidth: 2.5,
valueColor:
AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
),
const SizedBox(width: 12),
Text(
l10n.loggingIn,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
],
)
: Text(
l10n.login,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
),
const SizedBox(height: 24),
],
),
@@ -375,7 +627,15 @@ class _LoginViewState extends State<LoginView> {
),
),
// Version number at the bottom
if (_appVersion.isNotEmpty) Padding(padding: const EdgeInsets.only(bottom: 16.0), child: Text('Version $_appVersion', style: TextStyle(fontSize: 12, color: Colors.grey[500]), textAlign: TextAlign.center)),
if (_appVersion.isNotEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Text(
'Version $_appVersion',
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
textAlign: TextAlign.center,
),
),
],
),
);