feat:增加朋友圈评论显示模块

This commit is contained in:
2025-11-20 19:55:44 +08:00
parent 4f033a4d0a
commit 515021781f
4 changed files with 176 additions and 62 deletions

View File

@@ -5,7 +5,6 @@ import 'package:food_hub_app/models/session.dart';
import 'package:food_hub_app/utils/sp_util.dart';
import 'package:food_hub_app/widgets/common/index.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@@ -20,6 +19,7 @@ class _LoginPage extends State<LoginPage> {
String _username = "Cxx0822", _password = "19940822Cxx";
bool _isRemember = false;
bool _isObscure = true;
bool _isLoading = false;
Color _eyeColor = Colors.grey;
final List _loginMethod = [
{"title": "phone", "icon": Icons.phone_android},
@@ -34,7 +34,7 @@ class _LoginPage extends State<LoginPage> {
}
Future<void> _loadRememberState() async {
bool? isRemember = await SPUtil.getBool('isRemember');
bool? isRemember = SPUtil.getBool('isRemember');
if (isRemember) {
setState(() {
_isRemember = true;
@@ -60,7 +60,11 @@ class _LoginPage extends State<LoginPage> {
SPUtil.set('token', token);
}
void loginClick(BuildContext context) async {
void loginClick() async {
setState(() {
_isLoading = true;
});
// 表单校验通过才会继续执行
if ((_formKey.currentState as FormState).validate()) {
(_formKey.currentState as FormState).save();
@@ -70,9 +74,11 @@ class _LoginPage extends State<LoginPage> {
handleRememberState();
handleTokenState(session.saToken.tokenValue);
Navigator.pushNamed(context, '/home');
} else {
showErrorToast('请先输入信息');
}
setState(() {
_isLoading = false;
});
}
@override
@@ -81,13 +87,9 @@ class _LoginPage extends State<LoginPage> {
backgroundColor: Colors.grey[100],
body: Form(
key: _formKey,
// autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
children: [
// 可滚动的主要内容区域
Expanded(child: buildLoginForm()),
// 固定在底部的其他登录选项区域
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 50),
child: Column(
@@ -123,18 +125,11 @@ class _LoginPage extends State<LoginPage> {
const SizedBox(height: 60),
buildUsernameTextField(),
const SizedBox(height: 20),
buildPasswordTextField(context),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
buildRememberPasswordCheckbox(context), // 记住密码(左对齐)
buildForgetPasswordText(context),
],
),
const SizedBox(height: 20), // 调整与登录按钮的间距
buildLoginButton(context),
buildPasswordTextField(),
const SizedBox(height: 10),
buildRememberPasswordCheckbox(),
const SizedBox(height: 20),
buildLoginButton(),
],
);
}
@@ -160,7 +155,7 @@ class _LoginPage extends State<LoginPage> {
);
}
Widget buildPasswordTextField(BuildContext context) {
Widget buildPasswordTextField() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -198,10 +193,12 @@ class _LoginPage extends State<LoginPage> {
);
}
Widget buildRememberPasswordCheckbox(BuildContext context) {
Widget buildRememberPasswordCheckbox() {
return Row(
children: [
Checkbox(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
visualDensity: VisualDensity.compact,
value: _isRemember,
onChanged: (bool? value) {
setState(() {
@@ -214,40 +211,40 @@ class _LoginPage extends State<LoginPage> {
);
}
Widget buildForgetPasswordText(BuildContext context) {
return Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
print("忘记密码");
},
child: const Text(
"忘记密码?",
style: TextStyle(fontSize: 14, color: Colors.grey),
Widget buildLoginButton() {
return SizedBox(
height: 45,
width: double.infinity,
child: ElevatedButton(
onPressed: _isLoading ? null : loginClick,
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Colors.white,
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
),
);
}
Widget buildLoginButton(BuildContext context) {
return Align(
child: SizedBox(
height: 45,
width: double.infinity,
child: TDButton(
text: '登录',
size: TDButtonSize.large,
type: TDButtonType.fill,
shape: TDButtonShape.rectangle,
theme: TDButtonTheme.primary,
onTap: () => loginClick(context),
child: const Text(
'登录',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
),
);
}
Widget buildOtherLoginText() {
return TDDivider(text: '其他方式登录', alignment: TextAlignment.center);
return Row(
children: [
Expanded(child: Divider(color: Colors.grey[300], thickness: 1)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'其他方式登录',
style: TextStyle(color: Colors.grey, fontSize: 14),
),
),
Expanded(child: Divider(color: Colors.grey[300], thickness: 1)),
],
);
}
Widget buildOtherMethod(context) {