ほぼ完成:QRcodeトライ

This commit is contained in:
2024-08-01 20:08:12 +09:00
parent 3d7a5ae0c1
commit ee007795b9
25 changed files with 3214 additions and 1121 deletions

View File

@ -85,121 +85,153 @@ class _MemberDetailPageState extends State<MemberDetailPage> {
home:Scaffold(
*/
return Scaffold(
appBar: AppBar(
title: Text(mode == 'new' ? 'メンバー追加' : 'メンバー詳細'),
actions: [
IconButton(
icon: Icon(Icons.save),
onPressed: () async {
await controller.saveMember();
Get.back(result: true);
},
),
],
),
body: Obx(() {
if (controller.isLoading.value) {
return Center(child: CircularProgressIndicator());
}
return SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (mode == 'new')
TextField(
decoration: InputDecoration(labelText: 'メールアドレス'),
onChanged: (value) => controller.email.value = value,
controller: TextEditingController(text: controller.email.value),
)
else if (controller.isDummyEmail)
Text('メールアドレス: (メアド無し)')
else
Text('メールアドレス: ${controller.email.value}'),
if (controller.email.value.isEmpty || mode == 'edit') ...[
TextField(
decoration: InputDecoration(labelText: ''),
onChanged: (value) => controller.lastname.value = value,
controller: TextEditingController(text: controller.lastname.value),
),
TextField(
decoration: InputDecoration(labelText: ''),
onChanged: (value) => controller.firstname.value = value,
controller: TextEditingController(text: controller.firstname.value),
),
// 生年月日
if (controller.isDummyEmail || !controller.isOver18())
ListTile(
title: Text('生年月日'),
subtitle: Text(controller.dateOfBirth.value != null
? '${DateFormat('yyyy年MM月dd日').format(controller.dateOfBirth.value!)} (${controller.getAgeAndGrade()})'
: '未設定'),
onTap: () async {
final date = await showDatePicker(
context: context,
initialDate: controller.dateOfBirth.value ?? DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now(),
//locale: const Locale('ja', 'JP'),
);
if (date != null) controller.dateOfBirth.value = date;
},
)
else
Text('18歳以上'),
SwitchListTile(
title: Text('性別'),
subtitle: Text(controller.female.value ? '女性' : '男性'),
value: controller.female.value,
onChanged: (value) => controller.female.value = value,
),
],
// 招待メール再送信ボタン通常のEmailで未承認の場合のみ
if (!controller.isDummyEmail && !controller.isApproved)
ElevatedButton(
child: Text('招待メールを再送信'),
onPressed: () => controller.resendInvitation(),
),
// メンバー削除ボタン
ElevatedButton(
child: Text('メンバーから削除'),
onPressed: () async {
final confirmed = await Get.dialog<bool>(
AlertDialog(
title: Text('確認'),
content: Text('このメンバーを削除してもよろしいですか?'),
actions: [
TextButton(
child: Text('キャンセル'),
onPressed: () => Get.back(result: false),
),
TextButton(
child: Text('削除'),
onPressed: () => Get.back(result: true),
),
],
),
);
if (confirmed == true) {
await controller.deleteMember();
Get.back(result: true);
}
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
),
],
),
);
}),
appBar: AppBar(
title: Text(mode == 'new' ? 'メンバー追加' : 'メンバー詳細'),
),
body: Obx(() {
if (controller.isLoading.value) {
return Center(child: CircularProgressIndicator());
}
// TextEditingControllerをObxの中で作成
final emailController = TextEditingController(text: controller.email.value);
// カーソル位置を保持
emailController.selection = TextSelection.fromPosition(
TextPosition(offset: controller.email.value.length),
);
return Column(
children: [
Expanded(
child: SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (mode == 'new')
TextFormField(
decoration: InputDecoration(labelText: 'メールアドレス'),
//onChanged: (value) => controller.email.value = value,
onChanged: (value) {
controller.email.value = value;
// カーソル位置を更新
emailController.selection = TextSelection.fromPosition(
TextPosition(offset: value.length),
);
},
controller: emailController,
//controller: TextEditingController(text: controller.email.value),
keyboardType: TextInputType.emailAddress, // メールアドレス用のキーボードを表示
autocorrect: false, // 自動修正を無効化
enableSuggestions: false,
)
else if (controller.isDummyEmail)
Text('メールアドレス: (メアド無し)')
else
Text('メールアドレス: ${controller.email.value}'),
if (controller.email.value.isEmpty || mode == 'edit') ...[
TextFormField(
decoration: InputDecoration(labelText: ''),
onChanged: (value) => controller.lastname.value = value,
controller: TextEditingController(text: controller.lastname.value),
),
TextFormField(
decoration: InputDecoration(labelText: ''),
onChanged: (value) => controller.firstname.value = value,
controller: TextEditingController(text: controller.firstname.value),
),
// 生年月日
if (controller.isDummyEmail || !controller.isOver18())
ListTile(
title: Text('生年月日'),
subtitle: Text(controller.dateOfBirth.value != null
? '${DateFormat('yyyy年MM月dd日').format(controller.dateOfBirth.value!)} (${controller.getAgeAndGrade()})'
: '未設定'),
onTap: () async {
final date = await showDatePicker(
context: context,
initialDate: controller.dateOfBirth.value ?? DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now(),
//locale: const Locale('ja', 'JP'),
);
if (date != null) controller.dateOfBirth.value = date;
},
)
else
Text('18歳以上'),
SwitchListTile(
title: Text('性別'),
subtitle: Text(controller.female.value ? '女性' : '男性'),
value: controller.female.value,
onChanged: (value) => controller.female.value = value,
),
],
]),
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
child: Text('削除'),
onPressed: () async {
final confirmed = await Get.dialog<bool>(
AlertDialog(
title: Text('確認'),
content: Text('このメンバーを削除してもよろしいですか?'),
actions: [
TextButton(
child: Text('キャンセル'),
onPressed: () => Get.back(result: false),
),
TextButton(
child: Text('削除'),
onPressed: () => Get.back(result: true),
),
],
),
);
if (confirmed == true) {
await controller.deleteMember();
Get.back(result: true);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
),
if (!controller.isDummyEmail && !controller.isApproved)
ElevatedButton(
child: Text('招待再送信'),
onPressed: () => controller.resendInvitation(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
),
ElevatedButton(
child: Text('保存・招待'),
onPressed: () async {
await controller.saveMember();
Get.back(result: true);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
),
),
],
),
),
],
);
}),
);
}
@override