大幅変更&環境バージョンアップ
This commit is contained in:
@ -1,128 +1,274 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.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:gifunavi/pages/destination/destination_controller.dart';
|
||||
import 'package:gifunavi/pages/index/index_controller.dart';
|
||||
import 'package:gifunavi/routes/app_pages.dart';
|
||||
import 'package:gifunavi/services/auth_service.dart';
|
||||
import 'package:gifunavi/utils/database_helper.dart';
|
||||
import 'package:gifunavi/widgets/debug_widget.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:gifunavi/pages/WebView/WebView_page.dart';
|
||||
|
||||
// SafeAreaウィジェットを使用して、画面の安全領域内にメニューを表示しています。
|
||||
// Columnウィジェットを使用して、メニューアイテムを縦に並べています。
|
||||
//
|
||||
class DrawerPage extends StatelessWidget {
|
||||
DrawerPage({ Key? key }) : super(key: key);
|
||||
DrawerPage({super.key});
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
LogManager logManager = LogManager();
|
||||
|
||||
// 要検討:URLの起動に失敗した場合のエラーハンドリングが不十分です。適切なエラーメッセージを表示するなどの処理を追加してください。
|
||||
//
|
||||
/*
|
||||
void _launchURL(url) async {
|
||||
if (!await launch(url)) throw 'Could not launch $url';
|
||||
if (!await launchUrl(url)) throw 'Could not launch $url';
|
||||
}
|
||||
*/
|
||||
|
||||
void _launchURL(BuildContext context,String urlString) async {
|
||||
try {
|
||||
logManager.addOperationLog('User clicked $urlString on the drawer');
|
||||
Uri url = Uri.parse(urlString);
|
||||
if (await canLaunchUrl(url)) {
|
||||
await launchUrl(url);
|
||||
} else {
|
||||
// URLを開けない場合のフォールバック動作
|
||||
// 例えば、WebViewを使用してアプリ内でURLを開く
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => WebViewPage(url: urlString),
|
||||
),
|
||||
);
|
||||
}
|
||||
}catch(e){
|
||||
// エラーメッセージを表示する
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('URLを開けませんでした: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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),),
|
||||
),
|
||||
)
|
||||
),
|
||||
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.TRAVEL);
|
||||
},
|
||||
)
|
||||
),
|
||||
indexController.currentUser.isNotEmpty ?
|
||||
|
||||
ListTile(
|
||||
leading: const Icon(Icons.password),
|
||||
title: Text("change_password".tr),
|
||||
onTap: (){
|
||||
Get.toNamed(AppPages.CHANGE_PASSWORD);
|
||||
leading: const Icon(Icons.group),
|
||||
title: const Text('チーム管理'),
|
||||
onTap: () async{
|
||||
//Get.back();
|
||||
// スナックバーを安全に閉じる
|
||||
await _safelyCloseSnackbar();
|
||||
Get.toNamed(AppPages.TEAM_LIST);
|
||||
},
|
||||
) :
|
||||
const SizedBox(width: 0, height: 0,),
|
||||
indexController.currentUser.isEmpty ?
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.event),
|
||||
title: const Text('エントリー管理'),
|
||||
onTap: () {
|
||||
Get.back();
|
||||
Get.toNamed(AppPages.ENTRY_LIST);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.event),
|
||||
title: const Text('イベント参加'),
|
||||
onTap: () {
|
||||
Get.back(); // ドロワーを閉じる
|
||||
Get.toNamed(AppPages.EVENT_ENTRY);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.person),
|
||||
title: Text("sign_up".tr),
|
||||
onTap: (){
|
||||
Get.toNamed(AppPages.REGISTER);
|
||||
title: const Text("個人情報の修正"),
|
||||
onTap: () {
|
||||
Get.back(); // Close the drawer
|
||||
Get.toNamed(AppPages.USER_DETAILS_EDIT);
|
||||
},
|
||||
) :
|
||||
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,),
|
||||
// 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,),
|
||||
),
|
||||
|
||||
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: Text('reset_button'.tr),
|
||||
onTap: () {
|
||||
logManager.addOperationLog('User clicked RESET button on the drawer');
|
||||
// 要検討:リセット操作の確認メッセージをローカライズすることを検討してください。
|
||||
//
|
||||
Get.defaultDialog(
|
||||
title: "reset_title".tr,
|
||||
middleText: "reset_message".tr,
|
||||
textConfirm: "confirm".tr,
|
||||
textCancel: "cancel".tr,
|
||||
onCancel: () => Get.back(),
|
||||
onConfirm: () async {
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
DatabaseHelper databaseHelper = DatabaseHelper.instance;
|
||||
|
||||
// ゲーム中のデータを削除
|
||||
await databaseHelper.deleteAllRogaining();
|
||||
await databaseHelper.deleteAllDestinations();
|
||||
destinationController.resetRogaining();
|
||||
|
||||
//destinationController.resetRogaining();
|
||||
//destinationController.deleteDBDestinations();
|
||||
Get.back();
|
||||
Get.snackbar(
|
||||
"reset_done".tr,
|
||||
"reset_explain".tr,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white,
|
||||
duration: const Duration(seconds: 3),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
: const SizedBox(
|
||||
width: 0,
|
||||
height: 0,
|
||||
),
|
||||
indexController.currentUser.isNotEmpty
|
||||
? ListTile(
|
||||
leading: const Icon(Icons.delete_forever),
|
||||
title: Text("delete_account".tr),
|
||||
onTap: () {
|
||||
Get.defaultDialog(
|
||||
title: "delete_account_title".tr,
|
||||
middleText: "delete_account_middle".tr,
|
||||
textConfirm: "confirm".tr,
|
||||
textCancel: "cancel".tr,
|
||||
onCancel: () => Get.back(),
|
||||
onConfirm: () {
|
||||
logManager.addOperationLog('User clicked Confirm button on the account delete dialog');
|
||||
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,
|
||||
backgroundColor: Colors.green,
|
||||
colorText: Colors.white
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
: const SizedBox(
|
||||
width: 0,
|
||||
height: 0,
|
||||
),
|
||||
indexController.currentUser.isNotEmpty
|
||||
? ListTile(
|
||||
leading: const Icon(Icons.featured_video),
|
||||
title: Text("rog_web".tr),
|
||||
onTap: () {
|
||||
_launchURL(context, "https://www.gifuai.net/?page_id=60043");
|
||||
},
|
||||
)
|
||||
: 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/");
|
||||
onTap: () {
|
||||
_launchURL(context, "https://rogaining.sumasen.net/api/privacy/");
|
||||
},
|
||||
)
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.settings),
|
||||
title: Text('open_settings'.tr),
|
||||
onTap: () {
|
||||
Get.back(); // ドロワーを閉じる
|
||||
Get.toNamed(Routes.SETTINGS);
|
||||
},
|
||||
),
|
||||
|
||||
//ListTile(
|
||||
// leading: const Icon(Icons.developer_mode),
|
||||
// title: const Text('open_settings'),
|
||||
// onTap: () {
|
||||
// Get.back(); // ドロワーを閉じる
|
||||
// Get.toNamed('/debug'); // デバッグ画面に遷移
|
||||
// },
|
||||
//),
|
||||
|
||||
|
||||
// ListTile(
|
||||
// leading: const Icon(Icons.router),
|
||||
// title: Text("my_route".tr),
|
||||
@ -138,4 +284,14 @@ class DrawerPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _safelyCloseSnackbar() async {
|
||||
if (Get.isSnackbarOpen) {
|
||||
try {
|
||||
await Get.closeCurrentSnackbar();
|
||||
} catch (e) {
|
||||
print('Error closing snackbar: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user