修改
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||||
|
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||||
|
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||||
|
|
||||||
import '../../domain/usecases/login_usecase.dart';
|
import '../../domain/usecases/login_usecase.dart';
|
||||||
import 'auth_cubit.dart';
|
import 'auth_cubit.dart';
|
||||||
@@ -17,9 +20,12 @@ class LoginCubit extends Cubit<LoginState> {
|
|||||||
Future<void> login(String username, String password, sourceType) async {
|
Future<void> login(String username, String password, sourceType) async {
|
||||||
emit(LoginLoading());
|
emit(LoginLoading());
|
||||||
try {
|
try {
|
||||||
final result = await loginUseCase.call(
|
final result = await loginUseCase.call(LoginParams(username, password, sourceType));
|
||||||
LoginParams(username, password, sourceType),
|
final user = sl<AppUserCubit>().state.user;
|
||||||
);
|
final devicesCubit = sl<DevicesCubit>();
|
||||||
|
if (user != null) {
|
||||||
|
devicesCubit.fetchAllDevices(user.username);
|
||||||
|
}
|
||||||
result.fold((failure) => emit(LoginFailure(failure.message)), (user) {
|
result.fold((failure) => emit(LoginFailure(failure.message)), (user) {
|
||||||
emit(LoginSuccess(user));
|
emit(LoginSuccess(user));
|
||||||
authCubit.loginSuccess(user);
|
authCubit.loginSuccess(user);
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import 'package:cc_ui_kit/cc_ui_kit.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||||
|
import 'package:maibu_satabot_v2/core/di/injection.dart';
|
||||||
|
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||||
|
|
||||||
import '../../../../core/router/route_paths.dart';
|
import '../../../../core/router/route_paths.dart';
|
||||||
import '../bloc/login_cubit.dart';
|
import '../bloc/login_cubit.dart';
|
||||||
@@ -39,9 +42,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
context.go(RoutePaths.home);
|
context.go(RoutePaths.home);
|
||||||
} else if (state is LoginFailure) {
|
} else if (state is LoginFailure) {
|
||||||
// 可以在这里弹出简洁的黑白提示框
|
// 可以在这里弹出简洁的黑白提示框
|
||||||
ScaffoldMessenger.of(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('登录失败,${state.message}')));
|
||||||
context,
|
|
||||||
).showSnackBar(SnackBar(content: Text('登录失败,${state.message}')));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
@@ -52,17 +53,10 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
const Text(
|
const Text(
|
||||||
"账号登录",
|
"账号登录",
|
||||||
style: TextStyle(
|
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: Colors.black),
|
||||||
fontSize: 28,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
const Text(
|
const Text("请填写以下信息以验证身份", style: TextStyle(fontSize: 15, color: Colors.grey)),
|
||||||
"请填写以下信息以验证身份",
|
|
||||||
style: TextStyle(fontSize: 15, color: Colors.grey),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
|
|
||||||
// 账号输入框
|
// 账号输入框
|
||||||
@@ -84,13 +78,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
decoration: _inputDecoration(
|
decoration: _inputDecoration(
|
||||||
hint: "请输入密码",
|
hint: "请输入密码",
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(_obscurePwd ? Icons.visibility_off_outlined : Icons.visibility_outlined, color: Colors.grey, size: 20),
|
||||||
_obscurePwd
|
|
||||||
? Icons.visibility_off_outlined
|
|
||||||
: Icons.visibility_outlined,
|
|
||||||
color: Colors.grey,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
onPressed: () => setState(() => _obscurePwd = !_obscurePwd),
|
onPressed: () => setState(() => _obscurePwd = !_obscurePwd),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -114,9 +102,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (!_isAgreed) {
|
if (!_isAgreed) {
|
||||||
// 如果没有勾选协议,弹出提示
|
// 如果没有勾选协议,弹出提示
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('请先阅读并同意用户协议')));
|
||||||
const SnackBar(content: Text('请先阅读并同意用户协议')),
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state is! LoginLoading) {
|
if (state is! LoginLoading) {
|
||||||
@@ -138,16 +124,18 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
// 执行登录逻辑
|
// 执行登录逻辑
|
||||||
void _handleLogin() {
|
void _handleLogin() {
|
||||||
context.read<LoginCubit>().login(_userCtrl.text, _pwdCtrl.text, 2);
|
context.read<LoginCubit>().login(_userCtrl.text, _pwdCtrl.text, 2);
|
||||||
|
//final user = sl<AppUserCubit>().state.user;
|
||||||
|
//final devicesCubit = sl<DevicesCubit>();
|
||||||
|
//if (user != null) {
|
||||||
|
// devicesCubit.fetchAllDevices(user.username);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 辅助组件:输入框标签
|
// 辅助组件:输入框标签
|
||||||
Widget _buildInputLabel(String label) {
|
Widget _buildInputLabel(String label) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 8.0),
|
padding: const EdgeInsets.only(bottom: 8.0),
|
||||||
child: Text(
|
child: Text(label, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||||
label,
|
|
||||||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,24 +171,16 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
value: _isAgreed,
|
value: _isAgreed,
|
||||||
activeColor: Colors.black,
|
activeColor: Colors.black,
|
||||||
onChanged: (val) => setState(() => _isAgreed = val!),
|
onChanged: (val) => setState(() => _isAgreed = val!),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
|
||||||
borderRadius: BorderRadius.circular(4),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text("我已阅读并同意 ", style: TextStyle(fontSize: 13, color: Colors.grey)),
|
||||||
"我已阅读并同意 ",
|
|
||||||
style: TextStyle(fontSize: 13, color: Colors.grey),
|
|
||||||
),
|
|
||||||
_protocolText("《用户协议》", () => _showProtocolDetail("用户协议")),
|
_protocolText("《用户协议》", () => _showProtocolDetail("用户协议")),
|
||||||
const Text(
|
const Text(" 和 ", style: TextStyle(fontSize: 13, color: Colors.grey)),
|
||||||
" 和 ",
|
|
||||||
style: TextStyle(fontSize: 13, color: Colors.grey),
|
|
||||||
),
|
|
||||||
_protocolText("《隐私政策》", () => _showProtocolDetail("隐私政策")),
|
_protocolText("《隐私政策》", () => _showProtocolDetail("隐私政策")),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -214,11 +194,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: Text(
|
child: Text(
|
||||||
text,
|
text,
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 13, color: Colors.black, fontWeight: FontWeight.bold),
|
||||||
fontSize: 13,
|
|
||||||
color: Colors.black,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -228,25 +204,17 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
||||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
|
||||||
),
|
|
||||||
builder: (context) => Container(
|
builder: (context) => Container(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
height: MediaQuery.of(context).size.height * 0.7,
|
height: MediaQuery.of(context).size.height * 0.7,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(title, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
title,
|
|
||||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const Divider(height: 32),
|
const Divider(height: 32),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Text(
|
child: Text("此处放置您的${title}详细内容...\n" * 20, style: const TextStyle(color: Colors.black87, height: 1.5)),
|
||||||
"此处放置您的${title}详细内容...\n" * 20,
|
|
||||||
style: const TextStyle(color: Colors.black87, height: 1.5),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
@@ -254,10 +222,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: BlocBuilder<LoginCubit, LoginState>(
|
child: BlocBuilder<LoginCubit, LoginState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return CCPrimaryButton(
|
return CCPrimaryButton(onPressed: () => Navigator.pop(context), text: "我已了解");
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
text: "我已了解",
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user