194 lines
6.2 KiB
Dart
194 lines
6.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class EditProfilePage extends StatefulWidget {
|
|
const EditProfilePage({super.key});
|
|
|
|
@override
|
|
State<EditProfilePage> createState() => _EditProfilePageState();
|
|
}
|
|
|
|
class _EditProfilePageState extends State<EditProfilePage> {
|
|
final TextEditingController fullNameController = TextEditingController(
|
|
text: '林小安',
|
|
);
|
|
final TextEditingController birthdayController = TextEditingController(
|
|
text: '1995-05-01',
|
|
);
|
|
final TextEditingController phoneController = TextEditingController(
|
|
text: '0912-345-678',
|
|
);
|
|
final TextEditingController emailController = TextEditingController(
|
|
text: 'linxiaoan@gmail.com',
|
|
);
|
|
final TextEditingController carPlateController = TextEditingController(
|
|
text: 'ABC-1234',
|
|
);
|
|
|
|
String gender = '男';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF7F8FA),
|
|
appBar: AppBar(
|
|
backgroundColor: const Color(0xFF9EAFAF),
|
|
title: const Text('編輯個人資料'),
|
|
centerTitle: true,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
_buildSection(
|
|
children: [
|
|
_buildTextField(label: '姓名', controller: fullNameController),
|
|
_buildDropdownField(label: '性別'),
|
|
_buildTextField(
|
|
label: '生日',
|
|
controller: birthdayController,
|
|
isDate: true,
|
|
),
|
|
_buildTextField(
|
|
label: '手機號碼',
|
|
controller: phoneController,
|
|
keyboardType: TextInputType.phone,
|
|
),
|
|
_buildTextField(
|
|
label: '電子郵件',
|
|
controller: emailController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
),
|
|
_buildTextField(label: '車牌號碼', controller: carPlateController),
|
|
const SizedBox(height: 24),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.green,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24),
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 24,
|
|
vertical: 10,
|
|
),
|
|
),
|
|
child: const Text(
|
|
'儲存',
|
|
style: TextStyle(fontSize: 16, color: Colors.white),
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.grey[400],
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(24),
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 24,
|
|
vertical: 10,
|
|
),
|
|
),
|
|
child: const Text(
|
|
'取消',
|
|
style: TextStyle(fontSize: 16, color: Colors.black87),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSection({required List<Widget> children}) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(20),
|
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: children,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTextField({
|
|
required String label,
|
|
required TextEditingController controller,
|
|
TextInputType? keyboardType,
|
|
bool isDate = false,
|
|
}) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: TextField(
|
|
controller: controller,
|
|
keyboardType: keyboardType,
|
|
readOnly: isDate,
|
|
onTap:
|
|
isDate
|
|
? () async {
|
|
DateTime? picked = await showDatePicker(
|
|
context: context,
|
|
initialDate:
|
|
DateTime.tryParse(controller.text) ?? DateTime.now(),
|
|
firstDate: DateTime(1900),
|
|
lastDate: DateTime.now(),
|
|
);
|
|
if (picked != null) {
|
|
controller.text = picked.toIso8601String().split('T').first;
|
|
}
|
|
}
|
|
: null,
|
|
decoration: InputDecoration(
|
|
labelText: label,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDropdownField({required String label}) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: InputDecorator(
|
|
decoration: InputDecoration(
|
|
labelText: label,
|
|
border: const OutlineInputBorder(),
|
|
),
|
|
child: DropdownButtonHideUnderline(
|
|
child: DropdownButton<String>(
|
|
value: gender,
|
|
isExpanded: true,
|
|
items:
|
|
['男', '女', '其他'].map((value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(value),
|
|
);
|
|
}).toList(),
|
|
onChanged: (newValue) {
|
|
setState(() {
|
|
gender = newValue!;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|