Files
JustAMassenger/client/lib/screens/login_screen.dart
T
SashegDev 096c4d0a2d Initial commit: JustAMessenger v0.1.0
Серверная часть (Go):
- WebSocket сервер с бинарным протоколом
- XChaCha20-Poly1305 шифрование
- zstd сжатие с дедупликацией (64KB чанки)
- SQLite хранилище (WAL режим)
- Управление гильдиями, каналами, ролями
- Федерация между серверами (ed25519)
- REST API + WebSocket endpoints

Клиентская часть (Flutter):
- Material Design 3 тёмная тема (Discord-like)
- WebSocket соединение с сервером
- Экраны: сплэш, логин, домашний, гильдии, чат
- Модели: пользователи, гильдии, каналы, сообщения, роли
- Сервисы: соединение, API, криптография, тема
- Виджеты: иконки гильдий, сообщения, ввод чата
- Web сборка (PWA)

Документация:
- AGENTS.md — контекст для ИИ ассистентов
- docs/protocol.md — спецификация протокола
2026-06-06 22:39:14 +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.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: ThemeService.danger.withValues(alpha: 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)),
),
),
],
),
),
),
);
}
}