feat: 重构认证页面使用 AuthPageScaffold 组件
This commit is contained in:
@@ -7,6 +7,7 @@ import '../../../../core/di/injection.dart';
|
||||
import '../../../../shared/widgets/app_button.dart';
|
||||
import '../../../../shared/widgets/banner/app_banner.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../widgets/auth_page_scaffold.dart';
|
||||
import '../../presentation/cubits/login_cubit.dart';
|
||||
import '../../presentation/bloc/auth_bloc.dart';
|
||||
import '../../presentation/bloc/auth_event.dart';
|
||||
@@ -59,36 +60,21 @@ class _LoginViewState extends State<LoginView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
key: const Key('login_main_content'),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildAppIcon(),
|
||||
const SizedBox(height: 24),
|
||||
_buildAppTitle(),
|
||||
const SizedBox(height: 32),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(key: const Key('login_footer'), child: _buildFooter()),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
return AuthPageScaffold(
|
||||
mainContentKey: const Key('login_main_content'),
|
||||
footerKey: const Key('login_footer'),
|
||||
mainContent: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildAppIcon(),
|
||||
const SizedBox(height: 24),
|
||||
_buildAppTitle(),
|
||||
const SizedBox(height: 32),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
footer: _buildFooter(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../presentation/cubits/register_cubit.dart';
|
||||
import '../../data/auth_repository.dart';
|
||||
import '../widgets/auth_page_scaffold.dart';
|
||||
|
||||
class RegisterScreen extends StatelessWidget {
|
||||
const RegisterScreen({super.key});
|
||||
@@ -79,35 +80,19 @@ class _RegisterViewState extends State<RegisterView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildAppIcon(),
|
||||
const SizedBox(height: 24),
|
||||
_buildAppTitle(),
|
||||
const SizedBox(height: 24),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildFooter(),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
return AuthPageScaffold(
|
||||
mainContent: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildAppIcon(),
|
||||
const SizedBox(height: 24),
|
||||
_buildAppTitle(),
|
||||
const SizedBox(height: 24),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
footer: _buildFooter(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -202,7 +187,7 @@ class _RegisterViewState extends State<RegisterView> {
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF475569),
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
@@ -223,7 +208,7 @@ class _RegisterViewState extends State<RegisterView> {
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF475569),
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../presentation/cubits/register_cubit.dart';
|
||||
import '../../presentation/bloc/auth_bloc.dart';
|
||||
import '../../presentation/bloc/auth_event.dart';
|
||||
import '../widgets/auth_page_scaffold.dart';
|
||||
|
||||
class RegisterVerificationScreen extends StatelessWidget {
|
||||
final RegisterCubit? cubit;
|
||||
@@ -125,35 +126,19 @@ class _RegisterVerificationViewState extends State<RegisterVerificationView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildAppIcon(),
|
||||
const SizedBox(height: 24),
|
||||
_buildAppTitle(),
|
||||
const SizedBox(height: 24),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildFooter(),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
return AuthPageScaffold(
|
||||
mainContent: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildAppIcon(),
|
||||
const SizedBox(height: 24),
|
||||
_buildAppTitle(),
|
||||
const SizedBox(height: 24),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
footer: _buildFooter(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -250,7 +235,7 @@ class _RegisterVerificationViewState extends State<RegisterVerificationView> {
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Color(0xFF475569),
|
||||
color: AppColors.slate600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../../../shared/widgets/toast/toast.dart';
|
||||
import '../../../../shared/widgets/toast/toast_type.dart';
|
||||
import '../../presentation/cubits/reset_password_cubit.dart';
|
||||
import '../../data/auth_repository.dart';
|
||||
import '../widgets/auth_page_scaffold.dart';
|
||||
|
||||
class ResetPasswordScreen extends StatelessWidget {
|
||||
const ResetPasswordScreen({super.key});
|
||||
@@ -78,30 +79,15 @@ class _ResetPasswordViewState extends State<ResetPasswordView> {
|
||||
Toast.show(context, state.errorMessage!, type: ToastType.error);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildTitle(),
|
||||
const SizedBox(height: 32),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: AuthPageScaffold(
|
||||
mainContent: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_buildTitle(),
|
||||
const SizedBox(height: 32),
|
||||
_buildFormContainer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/theme/design_tokens.dart';
|
||||
|
||||
class AuthPageScaffold extends StatelessWidget {
|
||||
const AuthPageScaffold({
|
||||
super.key,
|
||||
required this.mainContent,
|
||||
this.footer,
|
||||
this.mainContentKey,
|
||||
this.footerKey,
|
||||
});
|
||||
|
||||
final Widget mainContent;
|
||||
final Widget? footer;
|
||||
final Key? mainContentKey;
|
||||
final Key? footerKey;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final keyboardInset = MediaQuery.viewInsetsOf(context).bottom;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final viewportHeight = math.max(
|
||||
constraints.maxHeight - keyboardInset,
|
||||
AppSpacing.none,
|
||||
);
|
||||
|
||||
return SingleChildScrollView(
|
||||
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
AppSpacing.xxl,
|
||||
AppSpacing.none,
|
||||
AppSpacing.xxl,
|
||||
keyboardInset + AppSpacing.xxl,
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: viewportHeight),
|
||||
child: IntrinsicHeight(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
key: mainContentKey,
|
||||
child: Center(child: mainContent),
|
||||
),
|
||||
if (footer != null)
|
||||
Container(key: footerKey, child: footer),
|
||||
SizedBox(height: AppSpacing.xxl),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user