feat:增加登录页

This commit is contained in:
2026-06-17 19:58:39 +08:00
parent 02084ada96
commit ddd1c1960e
6 changed files with 269 additions and 59 deletions

118
lib/pages/login.dart Normal file
View File

@@ -0,0 +1,118 @@
import 'package:flutter/material.dart';
import 'package:liquid_glass_widgets/liquid_glass_widgets.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import '../services/webSocket_service.dart';
import 'home_page.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
void _login() {
print('username: ${_usernameController.text}');
print('password: ${_passwordController.text}');
WebSocketService().connect('ws://127.0.0.1:5050?userId=123');
WebSocketService().messages.listen((msg) {
print('收到消息: $msg');
});
// Navigator.of(context).push(
// MaterialPageRoute(
// builder: (_) => const HomePage(),
// ),
// );
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: [
Center(
child: GlassCard(
width: 340,
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Sweet Chat',
style: TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(height: 24),
// 邮箱
TextField(
controller: _usernameController,
style: const TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: '请输入用户名',
hintStyle: TextStyle(color: Colors.white70),
filled: true,
fillColor: Colors.white.withAlpha(50),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide.none,
),
),
),
const SizedBox(height: 16),
// 密码
TextField(
controller: _passwordController,
obscureText: true,
style: const TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: '请输入密码',
hintStyle: TextStyle(color: Colors.white70),
filled: true,
fillColor: Colors.white.withAlpha(50),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide.none,
),
),
),
const SizedBox(height: 28),
// 登录按钮
ElevatedButton(
onPressed: _login,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white.withAlpha(50),
foregroundColor: Colors.white,
minimumSize: const Size.fromHeight(50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
elevation: 0,
),
child: const Text('登录', style: TextStyle(fontSize: 18)),
),
],
),
),
),
],
),
);
}
}