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

62
lib/pages/home_page.dart Normal file
View File

@@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
import 'package:liquid_glass_widgets/widgets/shared/glass_page.dart';
import 'package:liquid_glass_widgets/widgets/surfaces/glass_bottom_bar.dart';
import 'package:liquid_glass_widgets/widgets/surfaces/glass_scaffold.dart';
import 'package:sweet_chat_app/pages/contacts_page.dart';
import 'package:sweet_chat_app/pages/explore_page.dart';
import 'package:sweet_chat_app/pages/messages_page.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _index = 0;
final _pages = [
const MessagePage(),
const ContactsPage(),
const ExplorePage(),
const Center(child: Text('⚙ 我的', style: TextStyle(fontSize: 26))),
];
@override
Widget build(BuildContext context) {
return GlassScaffold(
statusBarStyle: GlassStatusBarStyle.auto,
bottomBar: GlassBottomBar(
selectedIndex: _index,
onTabSelected: (i) => setState(() => _index = i),
selectedIconColor: Colors.purple.shade200,
unselectedIconColor: Colors.white,
tabs: const [
GlassBottomBarTab(
icon: Icon(Icons.chat_bubble_outline),
activeIcon: Icon(Icons.chat_bubble),
label: '消息',
),
GlassBottomBarTab(
icon: Icon(Icons.contacts_outlined),
activeIcon: Icon(Icons.contacts),
label: '通讯录',
),
GlassBottomBarTab(
icon: Icon(Icons.explore_outlined),
activeIcon: Icon(Icons.explore),
label: '发现',
),
GlassBottomBarTab(
icon: Icon(Icons.person_outline),
activeIcon: Icon(Icons.person),
label: '我的',
),
],
),
body: _pages[_index],
);
}
}

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)),
),
],
),
),
),
],
),
);
}
}