2022-05-12 02:17:08 +05:30
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
2024-08-22 14:35:09 +09:00
|
|
|
|
import 'package:gifunavi/pages/index/index_controller.dart';
|
|
|
|
|
|
import 'package:gifunavi/routes/app_pages.dart';
|
|
|
|
|
|
import 'package:gifunavi/widgets/helper_dialog.dart';
|
|
|
|
|
|
import 'package:gifunavi/services/api_service.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
|
|
|
|
|
|
|
|
|
|
// 要検討:ログインボタンとサインアップボタンの配色を見直すことを検討してください。現在の配色では、ボタンの役割がわかりにくい可能性があります。
|
|
|
|
|
|
// エラーメッセージをローカライズすることを検討してください。
|
|
|
|
|
|
// ログイン処理中にエラーが発生した場合のエラーハンドリングを追加することをお勧めします。
|
|
|
|
|
|
//
|
|
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
|
|
|
|
const LoginPage({super.key});
|
2022-05-12 02:17:08 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
@override
|
|
|
|
|
|
_LoginPageState createState() => _LoginPageState();
|
|
|
|
|
|
}
|
2022-05-12 02:17:08 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
|
|
|
|
//class LoginPage extends StatelessWidget {
|
2022-05-12 02:17:08 +05:30
|
|
|
|
final IndexController indexController = Get.find<IndexController>();
|
2024-08-22 14:35:09 +09:00
|
|
|
|
final ApiService apiService = Get.find<ApiService>();
|
2022-05-12 02:17:08 +05:30
|
|
|
|
|
|
|
|
|
|
TextEditingController emailController = TextEditingController();
|
|
|
|
|
|
TextEditingController passwordController = TextEditingController();
|
2024-08-22 14:35:09 +09:00
|
|
|
|
bool _obscureText = true;
|
|
|
|
|
|
String _version = ''; // バージョン情報を保持する変数
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
|
showHelperDialog(
|
|
|
|
|
|
'参加するにはユーザー登録が必要です。サインアップからユーザー登録してください。',
|
|
|
|
|
|
'login_page'
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
_getVersionInfo(); // バージョン情報を取得
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// バージョン情報を取得するメソッド
|
|
|
|
|
|
Future<void> _getVersionInfo() async {
|
|
|
|
|
|
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
_version = packageInfo.version;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _showResetPasswordDialog() {
|
|
|
|
|
|
TextEditingController resetEmailController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
|
|
Get.dialog(
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
|
title: const Text('パスワードのリセット'),
|
|
|
|
|
|
content: Column(
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
const Text('パスワードをリセットするメールアドレスを入力してください。'),
|
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
|
TextField(
|
|
|
|
|
|
controller: resetEmailController,
|
|
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
|
|
labelText: 'メールアドレス',
|
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
child: const Text('キャンセル'),
|
|
|
|
|
|
onPressed: () => Get.back(),
|
|
|
|
|
|
),
|
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
|
child: const Text('リセット'),
|
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
|
if (resetEmailController.text.isNotEmpty) {
|
|
|
|
|
|
bool success = await apiService.resetPassword(resetEmailController.text);
|
|
|
|
|
|
Get.back();
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
Get.dialog(
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
|
title: const Text('パスワードリセット'),
|
|
|
|
|
|
content: const Text('パスワードリセットメールを送信しました。メールのリンクからパスワードを設定してください。'),
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
child: const Text('OK'),
|
|
|
|
|
|
onPressed: () => Get.back(),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Get.snackbar('エラー', 'パスワードリセットに失敗しました。もう一度お試しください。',
|
|
|
|
|
|
snackPosition: SnackPosition.BOTTOM);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2022-05-12 02:17:08 +05:30
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
//LoginPage({Key? key}) : super(key: key);
|
2023-09-03 23:37:41 +05:30
|
|
|
|
|
2022-05-12 02:17:08 +05:30
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
|
resizeToAvoidBottomInset: false,
|
2024-08-22 14:35:09 +09:00
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
|
elevation: 0,
|
2022-05-12 02:17:08 +05:30
|
|
|
|
backgroundColor: Colors.white,
|
2024-08-22 14:35:09 +09:00
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
|
|
),
|
|
|
|
|
|
body: GestureDetector(
|
|
|
|
|
|
onTap: () => FocusScope.of(context).unfocus(),
|
|
|
|
|
|
child: indexController.currentUser.isEmpty
|
2024-09-02 21:25:19 +09:00
|
|
|
|
? SingleChildScrollView(
|
2024-08-22 14:35:09 +09:00
|
|
|
|
child: Column(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Column(
|
2022-05-12 02:17:08 +05:30
|
|
|
|
children: [
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Container(
|
|
|
|
|
|
height: MediaQuery.of(context).size.height / 6,
|
|
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
|
|
image: DecorationImage(
|
|
|
|
|
|
image: AssetImage(
|
|
|
|
|
|
'assets/images/login_image.jpg'))),
|
2022-05-12 02:17:08 +05:30
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
const SizedBox(
|
|
|
|
|
|
height: 5,
|
2022-09-14 19:51:50 +05:30
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
// バージョン情報を表示
|
|
|
|
|
|
Text(
|
|
|
|
|
|
'Version: $_version',
|
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
|
color: Colors.grey[600],
|
|
|
|
|
|
),
|
2022-09-14 19:51:50 +05:30
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 40),
|
|
|
|
|
|
child: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
makeInput(
|
|
|
|
|
|
label: "email".tr, controller: emailController),
|
|
|
|
|
|
makePasswordInput(
|
|
|
|
|
|
label: "password".tr,
|
|
|
|
|
|
controller: passwordController,
|
|
|
|
|
|
obscureText: _obscureText,
|
|
|
|
|
|
onToggleVisibility: () {
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
_obscureText = !_obscureText;
|
|
|
|
|
|
});
|
|
|
|
|
|
}),
|
|
|
|
|
|
],
|
2022-12-27 18:52:37 +05:30
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
),
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 40),
|
|
|
|
|
|
child: Container(
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 3, left: 3),
|
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
|
borderRadius: BorderRadius.circular(40),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: Obx(
|
|
|
|
|
|
(() => indexController.isLoading.value == true
|
|
|
|
|
|
? MaterialButton(
|
|
|
|
|
|
minWidth: double.infinity,
|
|
|
|
|
|
height: 60,
|
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
|
color: Colors.grey[400],
|
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
|
borderRadius:
|
|
|
|
|
|
BorderRadius.circular(40)),
|
2024-09-08 18:16:51 +09:00
|
|
|
|
child: const CircularProgressIndicator(), // Login page
|
2024-08-22 14:35:09 +09:00
|
|
|
|
)
|
|
|
|
|
|
: Column(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
MaterialButton(
|
|
|
|
|
|
minWidth: double.infinity,
|
|
|
|
|
|
height: 40,
|
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
|
if (emailController.text.isEmpty ||
|
|
|
|
|
|
passwordController
|
|
|
|
|
|
.text.isEmpty) {
|
|
|
|
|
|
Get.snackbar(
|
|
|
|
|
|
"no_values".tr,
|
|
|
|
|
|
"email_and_password_required"
|
|
|
|
|
|
.tr,
|
|
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
|
|
colorText: Colors.white,
|
2024-09-08 18:16:51 +09:00
|
|
|
|
icon: const Icon(Icons.assistant_photo_outlined, size: 40.0, color: Colors.blue),
|
|
|
|
|
|
snackPosition: SnackPosition.TOP,
|
|
|
|
|
|
duration: const Duration(seconds: 3),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-09-08 18:16:51 +09:00
|
|
|
|
try {
|
|
|
|
|
|
//indexController.isLoading.value = true;
|
|
|
|
|
|
indexController.login(emailController.text, passwordController.text);
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
print('Error during login: $e');
|
|
|
|
|
|
// エラーハンドリングは IndexController 内で行われるため、ここでは何もしない
|
|
|
|
|
|
}
|
2024-08-22 14:35:09 +09:00
|
|
|
|
},
|
|
|
|
|
|
color: Colors.indigoAccent[400],
|
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
|
borderRadius:
|
|
|
|
|
|
BorderRadius.circular(40)),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
"login".tr,
|
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
|
color: Colors.white70),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(
|
|
|
|
|
|
height: 5.0,
|
|
|
|
|
|
),
|
|
|
|
|
|
MaterialButton(
|
|
|
|
|
|
minWidth: double.infinity,
|
|
|
|
|
|
height: 36,
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
Get.toNamed(AppPages.REGISTER);
|
|
|
|
|
|
},
|
|
|
|
|
|
color: Colors.redAccent,
|
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
|
borderRadius:
|
|
|
|
|
|
BorderRadius.circular(40)),
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
"sign_up".tr,
|
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
|
color: Colors.white70),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
)),
|
|
|
|
|
|
),
|
|
|
|
|
|
)),
|
|
|
|
|
|
const SizedBox(
|
|
|
|
|
|
height: 3,
|
|
|
|
|
|
),
|
|
|
|
|
|
Row(
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
onPressed: _showResetPasswordDialog,
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
"forgot_password".tr,
|
|
|
|
|
|
style: const TextStyle(color: Colors.blue),
|
|
|
|
|
|
),
|
2022-12-27 18:52:37 +05:30
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
],
|
2022-05-12 02:17:08 +05:30
|
|
|
|
),
|
2024-09-02 21:25:19 +09:00
|
|
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Expanded(
|
2024-08-22 14:35:09 +09:00
|
|
|
|
child: Text(
|
|
|
|
|
|
"app_developed_by_gifu_dx".tr,
|
2024-09-02 21:25:19 +09:00
|
|
|
|
style: const TextStyle(fontSize: 10.0),
|
|
|
|
|
|
textAlign: TextAlign.center,
|
2024-08-22 14:35:09 +09:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-09-02 21:25:19 +09:00
|
|
|
|
],
|
|
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
),
|
2024-09-02 21:25:19 +09:00
|
|
|
|
Padding(
|
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Expanded(
|
2024-08-22 14:35:09 +09:00
|
|
|
|
child: Text(
|
|
|
|
|
|
"※第8回と第9回は、岐阜県の令和5年度「清流の国ぎふ」SDGs推進ネットワーク連携促進補助金を受けています",
|
2024-09-02 21:25:19 +09:00
|
|
|
|
style: const TextStyle(fontSize: 10.0),
|
|
|
|
|
|
textAlign: TextAlign.center,
|
2024-08-22 14:35:09 +09:00
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-09-02 21:25:19 +09:00
|
|
|
|
],
|
|
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
: TextButton(
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
indexController.logout();
|
|
|
|
|
|
Get.offAllNamed(AppPages.LOGIN);
|
2022-09-01 19:14:18 +05:30
|
|
|
|
},
|
2023-09-03 23:37:41 +05:30
|
|
|
|
child: const Text("Already Logged in, Click to logout"),
|
2022-09-01 19:14:18 +05:30
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
),
|
2022-05-12 02:17:08 +05:30
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Widget makePasswordInput({
|
|
|
|
|
|
required String label,
|
|
|
|
|
|
required TextEditingController controller,
|
|
|
|
|
|
required bool obscureText,
|
|
|
|
|
|
required VoidCallback onToggleVisibility,
|
|
|
|
|
|
}) {
|
|
|
|
|
|
return Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Text(
|
|
|
|
|
|
label,
|
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
|
fontSize: 15, fontWeight: FontWeight.w400, color: Colors.black87),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
|
|
TextField(
|
|
|
|
|
|
controller: controller,
|
|
|
|
|
|
obscureText: obscureText,
|
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
|
contentPadding:
|
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 0, horizontal: 10),
|
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey[400]!),
|
|
|
|
|
|
),
|
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey[400]!),
|
|
|
|
|
|
),
|
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
|
icon: Icon(
|
|
|
|
|
|
obscureText ? Icons.visibility : Icons.visibility_off,
|
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
|
),
|
|
|
|
|
|
onPressed: onToggleVisibility,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(height: 30.0)
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Widget makeInput(
|
|
|
|
|
|
{label, required TextEditingController controller, obsureText = false}) {
|
2022-05-12 02:17:08 +05:30
|
|
|
|
return Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
2024-08-22 14:35:09 +09:00
|
|
|
|
Text(
|
|
|
|
|
|
label,
|
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
|
fontSize: 15, fontWeight: FontWeight.w400, color: Colors.black87),
|
|
|
|
|
|
),
|
|
|
|
|
|
const SizedBox(
|
|
|
|
|
|
height: 5,
|
|
|
|
|
|
),
|
2022-05-12 02:17:08 +05:30
|
|
|
|
TextField(
|
|
|
|
|
|
controller: controller,
|
|
|
|
|
|
obscureText: obsureText,
|
|
|
|
|
|
decoration: InputDecoration(
|
2024-08-22 14:35:09 +09:00
|
|
|
|
contentPadding:
|
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 0, horizontal: 10),
|
2022-05-12 02:17:08 +05:30
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
|
borderSide: BorderSide(
|
|
|
|
|
|
color: (Colors.grey[400])!,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
border: OutlineInputBorder(
|
2024-08-22 14:35:09 +09:00
|
|
|
|
borderSide: BorderSide(color: (Colors.grey[400])!),
|
2022-05-12 02:17:08 +05:30
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2024-08-22 14:35:09 +09:00
|
|
|
|
const SizedBox(
|
|
|
|
|
|
height: 30.0,
|
|
|
|
|
|
)
|
2022-05-12 02:17:08 +05:30
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|