Files
JustAMassenger/client/lib/screens/login_screen.dart
T
SashegDev 2347f382c6 сборка: APK (Android) + Linux Desktop
- Исправлены ошибки Flutter анализа (withOpacity, pbkdf2, импорты)
- Упрощён pubspec.yaml (только нужные зависимости)
- Android APK собран: build/app/outputs/flutter-apk/app-release.apk (22MB)
- Linux Desktop собран: build/linux/x64/release/bundle/jam_client

Для Windows: кросс-компиляция невозможна с Linux.
Нужен Windows хост для flutter build windows.
2026-06-06 23:07:57 +00:00

177 lines
5.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/connection_service.dart';
import '../services/theme_service.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _usernameController = TextEditingController();
final _serverUrlController = TextEditingController(text: 'ws://localhost:8443/ws');
bool _loading = false;
String? _error;
@override
void dispose() {
_usernameController.dispose();
_serverUrlController.dispose();
super.dispose();
}
Future<void> _connect() async {
setState(() {
_loading = true;
_error = null;
});
try {
final conn = context.read<ConnectionService>();
conn.serverUrl = _serverUrlController.text.trim();
await conn.connect();
final username = _usernameController.text.trim();
if (username.isNotEmpty) {
conn.authenticate(username: username);
}
await Future.delayed(const Duration(seconds: 1));
if (mounted) {
Navigator.pushReplacementNamed(context, '/home');
}
} catch (e) {
setState(() => _error = 'Connection failed: $e');
} finally {
if (mounted) setState(() => _loading = false);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: ThemeService.backgroundPrimary,
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 72,
height: 72,
decoration: BoxDecoration(
color: ThemeService.primary,
borderRadius: BorderRadius.circular(18),
),
child: const Center(
child: Text('JAM',
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.w800)),
),
),
const SizedBox(height: 32),
const Text(
'Welcome to JustAMessenger',
style: TextStyle(
color: ThemeService.textPrimary,
fontSize: 24,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 8),
const Text(
'Connect to a server to get started',
style: TextStyle(
color: ThemeService.textSecondary,
fontSize: 14,
),
),
const SizedBox(height: 32),
TextField(
controller: _serverUrlController,
decoration: const InputDecoration(
labelText: 'Server URL',
hintText: 'ws://localhost:8443/ws',
prefixIcon: Icon(Icons.dns_outlined),
),
style: const TextStyle(color: ThemeService.textPrimary),
),
const SizedBox(height: 16),
TextField(
controller: _usernameController,
decoration: const InputDecoration(
labelText: 'Username',
hintText: 'Enter your username',
prefixIcon: Icon(Icons.person_outline),
),
style: const TextStyle(color: ThemeService.textPrimary),
textCapitalization: TextCapitalization.none,
),
if (_error != null) ...[
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: ThemeService.danger.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: ThemeService.danger.withOpacity(0.3)),
),
child: Row(
children: [
const Icon(Icons.error_outline,
color: ThemeService.danger, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(_error!,
style: const TextStyle(
color: ThemeService.danger, fontSize: 13)),
),
],
),
),
],
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
height: 48,
child: ElevatedButton(
onPressed: _loading ? null : _connect,
style: ElevatedButton.styleFrom(
backgroundColor: ThemeService.primary,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 0,
),
child: _loading
? const SizedBox(
width: 22,
height: 22,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: const Text('Connect',
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.w600)),
),
),
],
),
),
),
);
}
}