-暂提交-bug未处理

This commit is contained in:
2026-05-13 10:34:07 +08:00
parent 4b3ad72627
commit fb529b2485
10 changed files with 501 additions and 121 deletions

View File

@@ -68,25 +68,12 @@ class AuthCubit extends Cubit<AuthState> {
/// 当 HTTP 登录/注册成功后调用
Future<void> loginSuccess(UserEntity user) async {
// 🔥 关键修复:先立即更新状态,触发 GoRouter redirect
await storage.saveUser(user);
await tcp.connect(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT);
// await _authTcpDatasource.sendAuthPacket(); //包括发送认证包和获取列表和切换函数
//tcp.startHeartbeat(interval: const Duration(seconds: 4)); //启动心跳
appCubit.setAuth(user);
emit(AuthAuthenticated(user));
// 然后异步执行其他操作(不阻塞主流程)
_performPostLoginTasks(user);
}
/// 登录后后台任务(不阻塞主流程)
Future<void> _performPostLoginTasks(UserEntity user) async {
try {
await storage.saveUser(user);
await tcp.connect(host: TCPConsts.TCP_IP, port: TCPConsts.TCP_PORT);
// await _authTcpDatasource.sendAuthPacket();
// tcp.startHeartbeat(interval: const Duration(seconds: 4));
} catch (e) {
_logger.logWithLevel('[AUTH] 登录后任务失败: $e', level: 'ERROR');
// 不影响已登录状态,只是记录错误
}
}
/// 退出登录 (主动或被动)

View File

@@ -39,9 +39,7 @@ class _LoginPageState extends State<LoginPage> {
body: BlocListener<LoginCubit, LoginState>(
listener: (context, state) {
if (state is LoginSuccess) {
// 登录成功后,AuthCubit 状态已更新
// GoRouter 的 redirect 会自动检测到已登录状态并跳转到首页
// 不需要手动调用 context.go
context.go(RoutePaths.home);
} else if (state is LoginFailure) {
// 可以在这里弹出简洁的黑白提示框
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('登录失败,${state.message}')));
@@ -122,6 +120,39 @@ class _LoginPageState extends State<LoginPage> {
},
),
),
const SizedBox(height: 24),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"没有账号吗?",
style: TextStyle(fontSize: 14, color: Colors.grey),
),
GestureDetector(
onTap: () {
print('点击了立即注册');
print('跳转路径: ${RoutePaths.register}');
context.go(RoutePaths.register);
},
child: const Text(
"立即注册",
style: TextStyle(
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
const SizedBox(height: 20),
],
),
),

View File

@@ -1,13 +1,300 @@
import 'package:cc_ui_kit/cc_ui_kit.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
class RegisterPage extends StatelessWidget {
class RegisterPage extends StatefulWidget {
const RegisterPage({super.key});
@override
State<RegisterPage> createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage> {
final _userCtrl = TextEditingController();
final _pwdCtrl = TextEditingController();
final _confirmPwdCtrl = TextEditingController();
bool _isAgreed = false;
bool _obscurePwd = true;
bool _obscureConfirmPwd = true;
@override
void dispose() {
_userCtrl.dispose();
_pwdCtrl.dispose();
_confirmPwdCtrl.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Register')),
body: Center(child: Text('Welcome Register page')),
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => context.go(RoutePaths.login),
),
),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 30.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 40),
const Text(
"账号注册",
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
const SizedBox(height: 12),
const Text(
"请填写以下信息完成注册",
style: TextStyle(fontSize: 15, color: Colors.grey),
),
const SizedBox(height: 40),
_buildInputLabel("用户名"),
TextField(
controller: _userCtrl,
cursorColor: Colors.black,
decoration: _inputDecoration(hint: "请设置用户名"),
),
const SizedBox(height: 24),
_buildInputLabel("密码"),
TextField(
controller: _pwdCtrl,
obscureText: _obscurePwd,
cursorColor: Colors.black,
decoration: _inputDecoration(
hint: "请设置密码",
suffixIcon: IconButton(
icon: Icon(
_obscurePwd
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: Colors.grey,
size: 20,
),
onPressed: () => setState(() => _obscurePwd = !_obscurePwd),
),
),
),
const SizedBox(height: 24),
_buildInputLabel("确认密码"),
TextField(
controller: _confirmPwdCtrl,
obscureText: _obscureConfirmPwd,
cursorColor: Colors.black,
decoration: _inputDecoration(
hint: "请再次输入密码",
suffixIcon: IconButton(
icon: Icon(
_obscureConfirmPwd
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: Colors.grey,
size: 20,
),
onPressed: () => setState(
() => _obscureConfirmPwd = !_obscureConfirmPwd,
),
),
),
),
const SizedBox(height: 20),
_buildProtocolSection(),
const SizedBox(height: 40),
SizedBox(
width: double.infinity,
child: CCPrimaryButton(
onPressed: _isAgreed ? _handleRegister : null,
text: '注 册',
),
),
const SizedBox(height: 24),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"已有账号?",
style: TextStyle(fontSize: 14, color: Colors.grey),
),
GestureDetector(
onTap: () => context.go(RoutePaths.login),
child: const Text(
"立即登录",
style: TextStyle(
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
const SizedBox(height: 20),
],
),
),
);
}
void _handleRegister() {
if (_userCtrl.text.isEmpty || _pwdCtrl.text.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('请填写完整信息')),
);
return;
}
if (_pwdCtrl.text != _confirmPwdCtrl.text) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('两次输入的密码不一致')),
);
return;
}
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('注册功能开发中...')),
);
}
Widget _buildInputLabel(String label) {
return Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Text(
label,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
);
}
InputDecoration _inputDecoration({required String hint, Widget? suffixIcon}) {
return InputDecoration(
hintText: hint,
hintStyle: TextStyle(color: Colors.grey.shade400, fontSize: 14),
filled: true,
fillColor: Colors.grey.shade50,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: Colors.grey.shade200),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(color: Colors.black, width: 1),
),
suffixIcon: suffixIcon,
);
}
Widget _buildProtocolSection() {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 24,
width: 24,
child: Checkbox(
value: _isAgreed,
activeColor: Colors.black,
onChanged: (val) => setState(() => _isAgreed = val!),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
),
),
),
const SizedBox(width: 8),
Expanded(
child: Wrap(
children: [
const Text(
"我已阅读并同意 ",
style: TextStyle(fontSize: 13, color: Colors.grey),
),
_protocolText("《用户协议》", () => _showProtocolDetail("用户协议")),
const Text(" 和 ", style: TextStyle(fontSize: 13, color: Colors.grey)),
_protocolText("《隐私政策》", () => _showProtocolDetail("隐私政策")),
],
),
),
],
);
}
Widget _protocolText(String text, VoidCallback onTap) {
return GestureDetector(
onTap: onTap,
child: Text(
text,
style: const TextStyle(
fontSize: 13,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
);
}
void _showProtocolDetail(String title) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (context) => Container(
padding: const EdgeInsets.all(24),
height: MediaQuery.of(context).size.height * 0.7,
child: Column(
children: [
Text(
title,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const Divider(height: 32),
Expanded(
child: SingleChildScrollView(
child: Text(
"此处放置您的${title}详细内容...\n" * 20,
style: const TextStyle(color: Colors.black87, height: 1.5),
),
),
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: CCPrimaryButton(
onPressed: () => Navigator.pop(context),
text: "我已了解",
),
),
],
),
),
);
}
}