205 lines
8.4 KiB
Dart
205 lines
8.4 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||
import 'package:rogapp/pages/index/index_controller.dart';
|
||
import 'package:rogapp/routes/app_pages.dart';
|
||
import 'package:rogapp/services/auth_service.dart';
|
||
import 'package:url_launcher/url_launcher.dart';
|
||
|
||
class DrawerPage extends StatelessWidget {
|
||
DrawerPage({Key? key}) : super(key: key);
|
||
|
||
final IndexController indexController = Get.find<IndexController>();
|
||
|
||
// 要検討:URLの起動に失敗した場合のエラーハンドリングが不十分です。適切なエラーメッセージを表示するなどの処理を追加してください。
|
||
//
|
||
void _launchURL(url) async {
|
||
if (!await launchUrl(url)) throw 'Could not launch $url';
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
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.
|
||
child: Column(
|
||
children: [
|
||
Container(
|
||
height: 100,
|
||
color: Colors.amber,
|
||
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),
|
||
),
|
||
),
|
||
)),
|
||
),
|
||
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);
|
||
},
|
||
)),
|
||
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,
|
||
),
|
||
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,
|
||
),
|
||
indexController.currentUser.isNotEmpty
|
||
? ListTile(
|
||
leading: const Icon(Icons.password),
|
||
title: const Text("リセット"),
|
||
onTap: () {
|
||
// 要検討:リセット操作の確認メッセージをローカライズすることを検討してください。
|
||
//
|
||
Get.defaultDialog(
|
||
title: "よろしいですか、リセットしますか?",
|
||
middleText: "これにより、すべてのゲーム データが削除され、すべての状態が削除されます",
|
||
textConfirm: "確認する",
|
||
textCancel: "キャンセルする",
|
||
onCancel: () => Get.back(),
|
||
onConfirm: () {
|
||
DestinationController destinationController =
|
||
Get.find<DestinationController>();
|
||
destinationController.resetRogaining();
|
||
destinationController.deleteDBDestinations();
|
||
Get.back();
|
||
},
|
||
);
|
||
},
|
||
)
|
||
: const SizedBox(
|
||
width: 0,
|
||
height: 0,
|
||
),
|
||
indexController.currentUser.isNotEmpty
|
||
? ListTile(
|
||
leading: const Icon(Icons.delete_forever),
|
||
title: Text("delete_account".tr),
|
||
onTap: () {
|
||
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);
|
||
}
|
||
});
|
||
},
|
||
)
|
||
: const SizedBox(
|
||
width: 0,
|
||
height: 0,
|
||
),
|
||
indexController.currentUser.isNotEmpty
|
||
? ListTile(
|
||
// 要検討:アカウント削除のリクエストが失敗した場合のエラーハンドリングを追加することをお勧めします。
|
||
//
|
||
leading: const Icon(Icons.delete_forever),
|
||
title: Text("ユーザーデータを削除する".tr),
|
||
onTap: () {
|
||
String token = indexController.currentUser[0]['token'];
|
||
AuthService.deleteUser(token).then((value) {
|
||
Get.snackbar("ユーザーデータを削除する",
|
||
"データを削除するためにユーザーの同意が設定されています アプリとサーバーでユーザーデータが削除されました");
|
||
});
|
||
},
|
||
)
|
||
: 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: (){},
|
||
// ),
|
||
indexController.currentUser.isNotEmpty
|
||
? ListTile(
|
||
leading: const Icon(Icons.featured_video),
|
||
title: Text("rog_web".tr),
|
||
onTap: () {
|
||
_launchURL("https://www.gifuai.net/?page_id=17397");
|
||
},
|
||
)
|
||
: const SizedBox(
|
||
width: 0,
|
||
height: 0,
|
||
),
|
||
ListTile(
|
||
leading: const Icon(Icons.privacy_tip),
|
||
title: Text("privacy".tr),
|
||
onTap: () {
|
||
_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: (){},
|
||
// ),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|