From cbc755b68f0946265cb8dbd1fb20dc6f5b5567df Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Fri, 9 May 2025 14:31:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E9=A0=81-=E4=BD=8F=E6=88=B6-=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=80=8B=E4=BA=BA=E8=B3=87=E6=96=99=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BB=8B=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/edit_profile.dart | 209 +++++++++++++++++++++++++++++++++++++++++ lib/personal_page.dart | 26 +++-- 2 files changed, 226 insertions(+), 9 deletions(-) create mode 100644 lib/edit_profile.dart diff --git a/lib/edit_profile.dart b/lib/edit_profile.dart new file mode 100644 index 0000000..a9653c7 --- /dev/null +++ b/lib/edit_profile.dart @@ -0,0 +1,209 @@ +import 'package:flutter/material.dart'; + +class EditProfilePage extends StatefulWidget { + const EditProfilePage({super.key}); + + @override + State createState() => _EditProfilePageState(); +} + +class _EditProfilePageState extends State { + 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), + ), + ), + ], + ), + ], + ), + ], + ), + ), + bottomNavigationBar: BottomNavigationBar( + type: BottomNavigationBarType.fixed, + items: const [ + BottomNavigationBarItem(icon: Icon(Icons.home), label: '首頁'), + BottomNavigationBarItem( + icon: Icon(Icons.door_front_door), + label: '出入', + ), + BottomNavigationBarItem(icon: Icon(Icons.message), label: '訊息'), + BottomNavigationBarItem(icon: Icon(Icons.person), label: '住戶'), + ], + currentIndex: 3, + onTap: (index) { + // Add navigation logic here if needed + }, + ), + ); + } + + Widget _buildSection({required List 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( + value: gender, + isExpanded: true, + items: + ['男', '女', '其他'].map((value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + onChanged: (newValue) { + setState(() { + gender = newValue!; + }); + }, + ), + ), + ), + ); + } +} diff --git a/lib/personal_page.dart b/lib/personal_page.dart index f31fcff..2bbaf22 100644 --- a/lib/personal_page.dart +++ b/lib/personal_page.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'login_page.dart'; +import 'edit_profile.dart'; class PersonalPage extends StatelessWidget { const PersonalPage({super.key}); @@ -50,7 +52,7 @@ class PersonalPage extends StatelessWidget { const SizedBox(height: 10), _buildNotificationsSection(), const SizedBox(height: 30), - _buildLogoutButton(), + _buildLogoutButton(context), const SizedBox(height: 60), ], ), @@ -98,7 +100,12 @@ class PersonalPage extends StatelessWidget { ), TextButton( onPressed: () { - // TODO: 修改個人資料按鈕 + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const EditProfilePage(), + ), + ); }, style: TextButton.styleFrom( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), @@ -250,11 +257,14 @@ class PersonalPage extends StatelessWidget { ); } - Widget _buildLogoutButton() { + Widget _buildLogoutButton(BuildContext context) { return Center( child: ElevatedButton.icon( onPressed: () { - // TODO: 登出按鈕 + Navigator.pushReplacement( + context, + MaterialPageRoute(builder: (context) => const LoginPage()), + ); }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFF08080), @@ -265,12 +275,10 @@ class PersonalPage extends StatelessWidget { shadowColor: Colors.black, elevation: 6, ), - icon: GestureDetector( - onTap: () { - // TODO: 登出icon單獨點擊(如果需要的話) - }, + /*icon: GestureDetector( + onTap: () {}, child: Image.asset('assets/icons/logout.png', width: 18, height: 18), - ), + ),*/ label: const Text('登出', style: TextStyle(fontSize: 16)), ), );