fix: 修复 register_page.dart 语法错误

This commit is contained in:
2026-04-08 11:14:27 +08:00
parent 97725cb768
commit baf2d87e47

View File

@@ -17,8 +17,11 @@ class RegisterPage extends StatefulWidget {
const RegisterPage({super.key});
@override
State<RegisterPage> createState() => _RegisterPageState>();
int _currentStep = 0; // 0: 賬號信息, 2: 身份證上傳
State<RegisterPage> createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage> {
int _currentStep = 0; // 0: 賬號信息, 1: 身份證上傳
// 第一步
final _usernameController = TextEditingController();
@@ -96,7 +99,7 @@ class RegisterPage extends StatefulWidget {
children: [
// 步驟指示器
_buildStepIndicator(colorScheme),
SizedBox(height: AppSpacing.xl),
const SizedBox(height: AppSpacing.xl),
// 內容區
_currentStep == 0 ? _buildStep1(colorScheme) : _buildStep2(colorScheme),
@@ -178,7 +181,7 @@ class RegisterPage extends StatefulWidget {
),
),
),
SizedBox(height: AppSpacing.xs),
const SizedBox(height: AppSpacing.xs),
Text(
label,
style: AppTextStyles.bodySmall(context).copyWith(
@@ -206,7 +209,7 @@ class RegisterPage extends StatefulWidget {
),
),
),
SizedBox(height: AppSpacing.xxl),
const SizedBox(height: AppSpacing.xxl),
// 用戶名
MaterialInput(
@@ -221,7 +224,7 @@ class RegisterPage extends StatefulWidget {
return null;
},
),
SizedBox(height: AppSpacing.md),
const SizedBox(height: AppSpacing.md),
// 密碼
MaterialPasswordInput(
@@ -235,7 +238,7 @@ class RegisterPage extends StatefulWidget {
return null;
},
),
SizedBox(height: AppSpacing.md),
const SizedBox(height: AppSpacing.md),
// 確認密碼
MaterialPasswordInput(
@@ -249,7 +252,7 @@ class RegisterPage extends StatefulWidget {
return null;
},
),
SizedBox(height: AppSpacing.md),
const SizedBox(height: AppSpacing.md),
// 推廣碼(可選)
MaterialInput(
@@ -258,7 +261,7 @@ class RegisterPage extends StatefulWidget {
hintText: '推廣碼(選填)',
prefixIcon: Icons.card_giftcard,
),
SizedBox(height: AppSpacing.xl),
const SizedBox(height: AppSpacing.xl),
// 下一步按鈕
SizedBox(
@@ -275,7 +278,7 @@ class RegisterPage extends StatefulWidget {
showGlow: true,
),
),
SizedBox(height: AppSpacing.md),
const SizedBox(height: AppSpacing.md),
// 登錄鏈接
Center(
@@ -283,9 +286,10 @@ class RegisterPage extends StatefulWidget {
onPressed: () => Navigator.pop(context),
child: Text(
'已有賬號?立即登錄',
style: AppTextStyles.headlineMedium(context)),
style: AppTextStyles.headlineMedium(context),
),
),
),
],
),
);
@@ -298,17 +302,17 @@ class RegisterPage extends StatefulWidget {
children: [
// 標題區
GlassPanel(
padding: EdgeInsets.all(AppSpacing.lg),
padding: const EdgeInsets.all(AppSpacing.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: EdgeInsets.all(AppSpacing.sm),
padding: const EdgeInsets.all(AppSpacing.sm),
decoration: BoxDecoration(
color: colorScheme.primary.withValues(alpha: 0.1),
borderRadius: AppRadius.radiusLg,
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Icon(
Icons.shield,
@@ -316,7 +320,7 @@ class RegisterPage extends StatefulWidget {
size: 22,
),
),
SizedBox(width: AppSpacing.md),
const SizedBox(width: AppSpacing.md),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -327,7 +331,7 @@ class RegisterPage extends StatefulWidget {
color: colorScheme.onSurface,
),
),
SizedBox(height: AppSpacing.xs),
const SizedBox(height: AppSpacing.xs),
Text(
'上傳身份證正反面完成註冊',
style: AppTextStyles.bodyMedium(context).copyWith(
@@ -336,73 +340,102 @@ class RegisterPage extends StatefulWidget {
),
],
),
SizedBox(height: AppSpacing.xl),
],
),
const SizedBox(height: AppSpacing.xl),
// 身份證正面
Text(
'身份證正面(人像面)',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onSurface,
),
),
SizedBox(height: AppSpacing.sm),
_buildUploadZone(
imageFile: _frontFile,
imageBytes: _frontBytes,
label: '人像面',
onTap: () => _pickImage(true),
colorScheme: colorScheme,
),
// 身份證正面
Text(
'身份證正面(人像面)',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onSurface,
),
SizedBox(height: AppSpacing.lg),
),
const SizedBox(height: AppSpacing.sm),
_buildUploadZone(
imageFile: _frontFile,
imageBytes: _frontBytes,
label: '人像面',
onTap: () => _pickImage(true),
colorScheme: colorScheme,
),
const SizedBox(height: AppSpacing.lg),
// 身份證反面
Text(
'身份證反面(國徽面)',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onSurface
)
),
SizedBox(height: AppSpacing.sm),
_buildUploadZone(
imageFile: _backFile,
imageBytes: _backBytes,
label: '國徽面',
onTap: () => _pickImage(false),
colorScheme: colorScheme
)
'身份證反面(國徽面)',
style: AppTextStyles.bodyLarge(context).copyWith(
fontWeight: FontWeight.w600,
color: colorScheme.onSurface,
),
SizedBox(height: AppSpacing.lg),
),
const SizedBox(height: AppSpacing.sm),
_buildUploadZone(
imageFile: _backFile,
imageBytes: _backBytes,
label: '國徽面',
onTap: () => _pickImage(false),
colorScheme: colorScheme,
),
const SizedBox(height: AppSpacing.xl),
// 註冊按鈕
Consumer<AuthProvider>(
builder: (context, auth, _) {
return SizedBox(
width: double.infinity,
child: NeonButton(
text: _isLoading ? '註冊中...' : '完成註冊',
type: NeonButtonType.primary,
onPressed: _canSubmit && !auth.isLoading ? _handleRegister : null,
height: 48,
showGlow: _canSubmit,
)
return SizedBox(
width: double.infinity,
child: NeonButton(
text: _isLoading ? '註冊中...' : '完成註冊',
type: NeonButtonType.primary,
onPressed: _canSubmit && !auth.isLoading
? _handleRegister
: null,
height: 48,
showGlow: _canSubmit,
),
);
},
),
],
),
),
const SizedBox(height: AppSpacing.lg),
// 安全提示
Container(
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: AppColorScheme.up.withValues(alpha: 0.06),
borderRadius: AppRadius.radiusLg,
border: Border.all(
color: AppColorScheme.up.withValues(alpha: 0.12),
),
),
child: Row(
children: [
Icon(Icons.lock, size: 16, color: AppColorScheme.up),
const SizedBox(width: AppSpacing.sm),
Expanded(
child: Text(
'您的身份信息將被加密存儲,僅用於身份驗證',
style: AppTextStyles.bodySmall(context).copyWith(
color: AppColorScheme.up.withValues(alpha: 0.8),
),
),
),
],
),
),
),
],
);
}
Widget _buildUploadZone({
required XFile? imageFile;
required XFile? imageFile,
required Uint8List? imageBytes,
required String label;
required String label,
required VoidCallback onTap,
required ColorScheme colorScheme,
}) {
final hasImage = imageFile != null && imageBytes != null;
@@ -419,7 +452,9 @@ class RegisterPage extends StatefulWidget {
: colorScheme.surfaceContainerHigh.withValues(alpha: 0.3),
borderRadius: AppRadius.radiusXl,
border: Border.all(
color: hasImage ? AppColorScheme.up.withValues(alpha: 0.3) : AppColorScheme.darkBackground.withValues(alpha: 0),
color: hasImage
? AppColorScheme.up.withValues(alpha: 0.3)
: Colors.transparent,
),
),
child: hasImage
@@ -434,7 +469,7 @@ class RegisterPage extends StatefulWidget {
right: 0,
bottom: 0,
child: Container(
padding: EdgeInsets.symmetric(
padding: const EdgeInsets.symmetric(
vertical: AppSpacing.sm,
horizontal: AppSpacing.md,
),
@@ -444,9 +479,11 @@ class RegisterPage extends StatefulWidget {
end: Alignment.bottomCenter,
colors: [
AppColorScheme.darkBackground.withValues(alpha: 0),
AppColorScheme.darkSurfaceLowest.withValues(alpha: 0.6),
AppColorScheme.darkSurfaceLowest
.withValues(alpha: 0.6),
],
borderRadius: BorderRadius.only(
),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(AppRadius.xl),
bottomRight: Radius.circular(AppRadius.xl),
),
@@ -474,82 +511,56 @@ class RegisterPage extends StatefulWidget {
});
},
child: Container(
padding: EdgeInsets.all(AppSpacing.xs),
padding: const EdgeInsets.all(AppSpacing.xs),
decoration: BoxDecoration(
color: AppColorScheme.darkOnPrimary.withValues(alpha: 0.15),
color: AppColorScheme.darkOnPrimary
.withValues(alpha: 0.15),
shape: BoxShape.circle,
),
child: Icon(Icons.close, size: 14, color: AppColorScheme.darkOnPrimary),
),
),
],
),
: CustomPaint(
painter: _DashedBorderPainter(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.2),
borderRadius: AppRadius.xl,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.camera_alt,
size: 28,
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
SizedBox(height: AppSpacing.sm),
Text(
'點擊上傳$label',
style: AppTextStyles.bodyLarge(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
),
),
SizedBox(height: AppSpacing.xs),
Text(
'支持 JPG、PNG 格式',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.4),
child: Icon(
Icons.close,
size: 14,
color: AppColorScheme.darkOnPrimary,
),
),
),
],
),
),
);
),
],
);
),
)
: CustomPaint(
painter: _DashedBorderPainter(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.2),
borderRadius: AppRadius.xl,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.camera_alt,
size: 28,
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
SizedBox(height: AppSpacing.sm),
Text(
'点击上传$label',
style: AppTextStyles.bodyLarge(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
painter: _DashedBorderPainter(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.2),
borderRadius: AppRadius.xl,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.camera_alt,
size: 28,
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.5),
),
),
SizedBox(height: AppSpacing.xs),
Text(
'支持 JPG、PNG 格式',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.4),
const SizedBox(height: AppSpacing.sm),
Text(
'點擊上傳$label',
style: AppTextStyles.bodyLarge(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.6),
),
),
),
],
const SizedBox(height: AppSpacing.xs),
Text(
'支持 JPG、PNG 格式',
style: AppTextStyles.bodySmall(context).copyWith(
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.4),
),
),
],
),
),
),
),
),
),
);
}
@@ -563,15 +574,12 @@ class RegisterPage extends StatefulWidget {
final response = await auth.register(
_usernameController.text.trim(),
_passwordController.text,
referralCode: _referralCodeController.text.trim().isEmpty ? null
referralCode: _referralCodeController.text.trim().isEmpty
? null
: _referralCodeController.text.trim(),
: referralCode,
},
frontBytes: _frontBytes!,
backBytes: _backBytes!,
referralCode: _referralCodeController.text,
);
}
if (!mounted) return;
@@ -634,8 +642,8 @@ class _DashedBorderPainter extends CustomPainter {
..strokeWidth = 1.5
..style = PaintingStyle.stroke;
final dashWidth = 6.0;
final dashSpace = 4.0;
const dashWidth = 6.0;
const dashSpace = 4.0;
final path = Path()
..addRRect(RRect.fromRectAndRadius(