382 lines
11 KiB
Dart
382 lines
11 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:airhub_app/theme/design_tokens.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'dart:io';
|
|
|
|
class ProfileInfoPage extends StatefulWidget {
|
|
const ProfileInfoPage({super.key});
|
|
|
|
@override
|
|
State<ProfileInfoPage> createState() => _ProfileInfoPageState();
|
|
}
|
|
|
|
class _ProfileInfoPageState extends State<ProfileInfoPage> {
|
|
String _gender = '男';
|
|
String _birthday = '1994-12-09';
|
|
File? _avatarImage;
|
|
final TextEditingController _nicknameController = TextEditingController(
|
|
text: '土豆',
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.background,
|
|
body: Stack(
|
|
children: [
|
|
// Background - Simplified gradient for consistency
|
|
Container(
|
|
decoration: const BoxDecoration(color: Color(0xFFFEFEFE)),
|
|
// We can reuse the same gradient background widget or implement a similar one
|
|
// For now, simple background to focus on content
|
|
),
|
|
|
|
Column(
|
|
children: [
|
|
_buildHeader(context),
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
padding: EdgeInsets.only(
|
|
top: 20,
|
|
left: AppSpacing.lg,
|
|
right: AppSpacing.lg,
|
|
bottom: 40 + MediaQuery.of(context).padding.bottom,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(height: 20),
|
|
_buildAvatarSection(),
|
|
const SizedBox(height: 32),
|
|
_buildFormCard(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(BuildContext context) {
|
|
return Container(
|
|
padding: EdgeInsets.only(
|
|
top: MediaQuery.of(context).padding.top + 20,
|
|
left: AppSpacing.lg,
|
|
right: AppSpacing.lg,
|
|
bottom: AppSpacing.md,
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
_buildBackButton(context),
|
|
const Text('个人信息', style: AppTextStyles.title),
|
|
_buildSaveButton(),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildBackButton(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () => Navigator.pop(context),
|
|
child: Container(
|
|
width: 44,
|
|
height: 44,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.iconBtnBg,
|
|
borderRadius: BorderRadius.circular(AppRadius.button),
|
|
border: Border.all(color: AppColors.iconBtnBorder),
|
|
),
|
|
child: const Icon(
|
|
Icons.arrow_back,
|
|
color: AppColors.textPrimary,
|
|
size: 20,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSaveButton() {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
colors: AppColors.saveBtnGradient,
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: const Text(
|
|
'保存',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAvatarSection() {
|
|
return Stack(
|
|
children: [
|
|
Container(
|
|
width: 100,
|
|
height: 100,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
gradient: LinearGradient(
|
|
colors: AppColors.avatarGradient,
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Color(0x338B5E3C), // rgba(139, 94, 60, 0.2)
|
|
blurRadius: 24,
|
|
offset: Offset(0, 8),
|
|
),
|
|
],
|
|
),
|
|
child: ClipOval(
|
|
child: _avatarImage != null
|
|
? Image.file(_avatarImage!, fit: BoxFit.cover)
|
|
: Image.asset(
|
|
'assets/www/Capybara.png',
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (ctx, err, stack) =>
|
|
const Icon(Icons.person, color: Colors.white, size: 40),
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
bottom: 0,
|
|
right: 0,
|
|
child: GestureDetector(
|
|
onTap: _pickImage,
|
|
child: Container(
|
|
width: 32,
|
|
height: 32,
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
colors: AppColors.saveBtnGradient,
|
|
),
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: Colors.white, width: 3),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.15),
|
|
offset: const Offset(0, 2),
|
|
blurRadius: 8,
|
|
),
|
|
],
|
|
),
|
|
child: const Icon(
|
|
Icons.camera_alt,
|
|
color: Colors.white,
|
|
size: 14,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<void> _pickImage() async {
|
|
try {
|
|
final ImagePicker picker = ImagePicker();
|
|
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
|
|
|
if (image != null) {
|
|
setState(() {
|
|
_avatarImage = File(image.path);
|
|
});
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text('选择图片失败: $e')));
|
|
}
|
|
}
|
|
}
|
|
|
|
Widget _buildFormCard() {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardSurface,
|
|
borderRadius: BorderRadius.circular(AppRadius.card),
|
|
boxShadow: const [AppShadows.card],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildInputItem('昵称', _nicknameController),
|
|
_buildSelectionItem('性别', _gender, onTap: _showGenderModal),
|
|
_buildSelectionItem(
|
|
'生日',
|
|
_birthday,
|
|
showDivider: false,
|
|
onTap: _showBirthdayInput,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInputItem(String label, TextEditingController controller) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.lg,
|
|
vertical: 18,
|
|
),
|
|
decoration: const BoxDecoration(
|
|
border: Border(bottom: BorderSide(color: AppColors.divider)),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 80,
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(color: AppColors.formLabel, fontSize: 15),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TextField(
|
|
controller: controller,
|
|
textAlign: TextAlign.right,
|
|
decoration: const InputDecoration.collapsed(
|
|
hintText: '请输入',
|
|
hintStyle: TextStyle(color: AppColors.textHint),
|
|
),
|
|
style: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontSize: 15,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSelectionItem(
|
|
String label,
|
|
String value, {
|
|
bool showDivider = true,
|
|
VoidCallback? onTap,
|
|
}) {
|
|
return InkWell(
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.lg,
|
|
vertical: 18,
|
|
),
|
|
decoration: showDivider
|
|
? const BoxDecoration(
|
|
border: Border(bottom: BorderSide(color: AppColors.divider)),
|
|
)
|
|
: null,
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 80,
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(
|
|
color: AppColors.formLabel,
|
|
fontSize: 15,
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Text(
|
|
value,
|
|
textAlign: TextAlign.right,
|
|
style: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontSize: 15,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
const Icon(
|
|
Icons.chevron_right,
|
|
color: AppColors.textHint,
|
|
size: 18,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showGenderModal() {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (context) => Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Text('选择性别', style: AppTextStyles.title),
|
|
const SizedBox(height: 20),
|
|
ListTile(
|
|
title: const Text('男', textAlign: TextAlign.center),
|
|
onTap: () {
|
|
setState(() => _gender = '男');
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
const Divider(),
|
|
ListTile(
|
|
title: const Text('女', textAlign: TextAlign.center),
|
|
onTap: () {
|
|
setState(() => _gender = '女');
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
const SizedBox(height: 10),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text(
|
|
'取消',
|
|
style: TextStyle(color: AppColors.textSecondary),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Simplified for MVP - using text input dialog for birthday as per PRD implication (custom input modal)
|
|
void _showBirthdayInput() {
|
|
// ... Implementation omitted for brevity in this step, can be added if requested or use standard date picker
|
|
// Using standard DatePicker for better UX in Flutter
|
|
showDatePicker(
|
|
context: context,
|
|
initialDate: DateTime.tryParse(_birthday) ?? DateTime(1994, 12, 9),
|
|
firstDate: DateTime(1900),
|
|
lastDate: DateTime.now(),
|
|
).then((picked) {
|
|
if (picked != null) {
|
|
setState(() {
|
|
_birthday =
|
|
"${picked.year}-${picked.month.toString().padLeft(2, '0')}-${picked.day.toString().padLeft(2, '0')}";
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|