Files
rog_app/lib/pages/drawer/drawer_page.dart

258 lines
13 KiB
Dart
Raw Normal View History

2022-03-14 12:28:57 +05:30
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2023-09-12 22:08:03 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
2022-05-12 02:17:08 +05:30
import 'package:rogapp/routes/app_pages.dart';
2023-01-06 16:48:47 +05:30
import 'package:rogapp/services/auth_service.dart';
2022-09-22 20:36:56 +05:30
import 'package:url_launcher/url_launcher.dart';
2022-03-14 12:28:57 +05:30
// SafeAreaウィジェットを使用して、画面の安全領域内にメニューを表示しています。
// Columnウィジェットを使用して、メニューアイテムを縦に並べています。
//
2022-03-14 12:28:57 +05:30
class DrawerPage extends StatelessWidget {
2023-09-12 22:08:03 +05:30
DrawerPage({Key? key}) : super(key: key);
2022-03-14 12:28:57 +05:30
final IndexController indexController = Get.find<IndexController>();
2022-03-14 12:28:57 +05:30
// 要検討URLの起動に失敗した場合のエラーハンドリングが不十分です。適切なエラーメッセージを表示するなどの処理を追加してください。
//
/*
2022-09-22 20:36:56 +05:30
void _launchURL(url) async {
2023-10-06 16:25:21 +05:30
if (!await launchUrl(url)) throw 'Could not launch $url';
2022-09-22 20:36:56 +05:30
}
*/
void _launchURL(String urlString) async {
Uri url = Uri.parse(urlString);
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
}
2022-09-22 20:36:56 +05:30
2022-03-14 12:28:57 +05:30
@override
Widget build(BuildContext context) {
2022-03-15 18:19:34 +05:30
return SafeArea(
child: Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
2022-04-17 11:45:21 +05:30
child: Column(
children: [
// 最初のアイテムは、ユーザーのログイン状態に応じて表示が変わります。
// ユーザーがログインしていない場合は、"drawer_title".trというテキストを表示します。
// ユーザーがログインしている場合は、ユーザーのメールアドレスを表示します。
2022-04-17 11:45:21 +05:30
Container(
height: 100,
color: Colors.amber,
2023-09-12 22:08:03 +05:30
child: Obx(() => Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: indexController.currentUser.isEmpty
? Flexible(
child: Text(
"drawer_title".tr,
style: const TextStyle(
color: Colors.black, fontSize: 20),
))
: Text(
indexController.currentUser[0]['user']['email'],
style: const TextStyle(
color: Colors.black, fontSize: 20),
),
),
)),
2022-04-17 11:45:21 +05:30
),
// 次に、IndexControllerのcurrentUserリストが空かどうかに応じて、ログインまたはログアウトのアイテムを表示します。
// currentUserリストが空の場合は、"login".trというテキストのログインアイテムを表示し、タップするとAppPages.LOGINにナビゲートします。
// currentUserリストが空でない場合は、"logout".trというテキストのログアウトアイテムを表示し、タップするとindexController.logout()を呼び出してログアウトし、AppPages.LOGINにナビゲートします。
2023-09-12 22:08:03 +05:30
Obx(() => indexController.currentUser.isEmpty
? ListTile(
leading: const Icon(Icons.login),
title: Text("login".tr),
onTap: () {
Get.toNamed(AppPages.LOGIN);
},
)
: ListTile(
leading: const Icon(Icons.login),
title: Text("logout".tr),
onTap: () {
indexController.logout();
Get.toNamed(AppPages.LOGIN);
},
)),
// パスワード変更のアイテムは、ユーザーがログインしている場合にのみ表示されます。
// "change_password".trというテキストを表示し、タップするとAppPages.CHANGE_PASSWORDにナビゲートします。
2023-09-12 22:08:03 +05:30
indexController.currentUser.isNotEmpty
? ListTile(
leading: const Icon(Icons.password),
title: Text("change_password".tr),
onTap: () {
Get.toNamed(AppPages.CHANGE_PASSWORD);
},
)
: const SizedBox(
width: 0,
height: 0,
),
// サインアップのアイテムは、ユーザーがログインしていない場合にのみ表示されます。
// "sign_up".trというテキストを表示し、タップするとAppPages.REGISTERにナビゲートします。
2023-09-12 22:08:03 +05:30
indexController.currentUser.isEmpty
? ListTile(
leading: const Icon(Icons.person),
title: Text("sign_up".tr),
onTap: () {
Get.toNamed(AppPages.REGISTER);
},
)
: const SizedBox(
width: 0,
height: 0,
),
// リセットのアイテムは、ユーザーがログインしている場合にのみ表示されます。
// タップすると、確認ダイアログを表示し、ユーザーがリセットを確認するとDestinationControllerのresetRogaining()メソッドを呼び出してゲームデータをリセットします。
2023-09-12 22:08:03 +05:30
indexController.currentUser.isNotEmpty
? ListTile(
leading: const Icon(Icons.password),
title: const Text("リセット"),
onTap: () {
// 要検討:リセット操作の確認メッセージをローカライズすることを検討してください。
//
2023-09-12 22:08:03 +05:30
Get.defaultDialog(
title: "リセットしますがよろしいですか?",
2023-09-12 22:08:03 +05:30
middleText: "これにより、すべてのゲーム データが削除され、すべての状態が削除されます",
textConfirm: "確認する",
textCancel: "キャンセルする",
onCancel: () => Get.back(),
onConfirm: () {
DestinationController destinationController =
Get.find<DestinationController>();
destinationController.resetRogaining();
destinationController.deleteDBDestinations();
Get.back();
},
);
},
)
: const SizedBox(
width: 0,
height: 0,
),
// アカウント削除のアイテムは、ユーザーがログインしている場合にのみ表示されます。
// "delete_account".trというテキストを表示し、タップするとAuthService.deleteUser()を呼び出してアカウントを削除し、AppPages.TRAVELにナビゲートします。
2023-09-12 22:08:03 +05:30
indexController.currentUser.isNotEmpty
? ListTile(
leading: const Icon(Icons.delete_forever),
title: Text("delete_account".tr),
onTap: () {
Get.defaultDialog(
title: "アカウントを削除しますがよろしいですか?",
middleText: "これにより、アカウント情報とすべてのゲーム データが削除され、すべての状態が削除されます",
textConfirm: "確認する",
textCancel: "キャンセルする",
onCancel: () => Get.back(),
onConfirm: () {
String token = indexController.currentUser[0]['token'];
AuthService.deleteUser(token).then((value) {
if (value.isNotEmpty) {
indexController.logout();
Get.toNamed(AppPages.TRAVEL);
Get.snackbar("accounted_deleted".tr,
"account_deleted_message".tr);
}
});
},
);
2023-09-12 22:08:03 +05:30
},
)
: const SizedBox(
width: 0,
height: 0,
),
// ユーザーデータ削除のアイテムは、ユーザーがログインしている場合にのみ表示されます。
// タップすると、AuthService.deleteUser()を呼び出してユーザーデータを削除します。
2023-11-24 11:58:17 +05:30
indexController.currentUser.isNotEmpty
? ListTile(
// 要検討:アカウント削除のリクエストが失敗した場合のエラーハンドリングを追加することをお勧めします。
//
2023-11-24 11:58:17 +05:30
leading: const Icon(Icons.delete_forever),
title: Text("ユーザーデータを削除する".tr),
onTap: () {
Get.defaultDialog(
title: "アカウントを削除しますがよろしいですか?",
middleText: "これにより、アカウント情報とすべてのゲーム データが削除され、すべての状態が削除されます",
textConfirm: "確認する",
textCancel: "キャンセルする",
onCancel: () => Get.back(),
onConfirm: () {
String token = indexController.currentUser[0]['token'];
AuthService.deleteUser(token).then((value) {
Get.snackbar("ユーザーデータを削除する",
2023-11-24 12:08:02 +05:30
"データを削除するためにユーザーの同意が設定されています アプリとサーバーでユーザーデータが削除されました");
});
});
},
)
2023-11-24 11:58:17 +05:30
: const SizedBox(
width: 0,
height: 0,
),
// ListTile(
// leading: const Icon(Icons.person),
// title: Text("profile".tr),
// onTap: (){},
// ),
// ListTile(
// leading: const Icon(Icons.route),
// title: Text("recommended_route".tr),
// onTap: (){},
// ),
// ListTile(
// leading: const Icon(Icons.favorite_rounded),
// title: Text("point_rank".tr),
// onTap: (){},
// ),
// "rog_web".trというテキストのアイテムは、ユーザーがログインしている場合にのみ表示されます。
// タップすると、_launchURL()メソッドを呼び出して外部のウェブサイトを開きます。
2023-09-12 22:08:03 +05:30
indexController.currentUser.isNotEmpty
? ListTile(
leading: const Icon(Icons.featured_video),
title: Text("rog_web".tr),
onTap: () {
_launchURL("https://www.gifuai.net/?page_id=60043");
2023-09-12 22:08:03 +05:30
},
)
: const SizedBox(
width: 0,
height: 0,
),
// "privacy".trというテキストのアイテムは、常に表示されます。
// タップすると、_launchURL()メソッドを呼び出してプライバシーポリシーのURLを開きます。
2023-01-12 12:32:08 +05:30
ListTile(
leading: const Icon(Icons.privacy_tip),
title: Text("privacy".tr),
2023-09-12 22:08:03 +05:30
onTap: () {
2023-01-12 12:32:08 +05:30
_launchURL("https://rogaining.sumasen.net/api/privacy/");
},
)
// ListTile(
// leading: const Icon(Icons.router),
// title: Text("my_route".tr),
// onTap: (){},
// ),
// ListTile(
// leading: const Icon(Icons.history_sharp),
// title: Text("visit_history".tr),
// onTap: (){},
// ),
2022-04-17 11:45:21 +05:30
],
),
2022-03-15 18:19:34 +05:30
),
2022-03-14 12:28:57 +05:30
);
}
2023-09-12 22:08:03 +05:30
}