Files
rog_app/lib/pages/login/login_page.dart

283 lines
13 KiB
Dart
Raw Normal View History

2022-05-12 02:17:08 +05:30
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';
// 要検討:ログインボタンとサインアップボタンの配色を見直すことを検討してください。現在の配色では、ボタンの役割がわかりにくい可能性があります。
// エラーメッセージをローカライズすることを検討してください。
// ログイン処理中にエラーが発生した場合のエラーハンドリングを追加することをお勧めします。
//
2022-05-12 02:17:08 +05:30
class LoginPage extends StatelessWidget {
final IndexController indexController = Get.find<IndexController>();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
2023-08-16 14:53:32 +05:30
LoginPage({Key? key}) : super(key: key);
2022-05-12 02:17:08 +05:30
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
2023-10-06 16:25:21 +05:30
backgroundColor: Colors.white,
2024-04-03 20:44:30 +09:00
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.white,
automaticallyImplyLeading: false,
),
2023-10-06 16:25:21 +05:30
body: indexController.currentUser.isEmpty
? SizedBox(
width: double.infinity,
2023-10-06 16:25:21 +05:30
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
2022-05-12 02:17:08 +05:30
children: [
Column(
children: [
2023-10-06 16:25:21 +05:30
Container(
height: MediaQuery.of(context).size.height / 6,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/login_image.jpg'))),
),
const SizedBox(
height: 5,
),
],
),
2023-10-06 16:25:21 +05:30
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Column(
children: [
makeInput(
label: "email".tr, controller: emailController),
makeInput(
label: "password".tr,
controller: passwordController,
obsureText: true),
],
),
2022-12-27 18:52:37 +05:30
),
2023-10-06 16:25:21 +05:30
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)),
child: const CircularProgressIndicator(),
)
: Column(
children: [
MaterialButton(
minWidth: double.infinity,
height: 40,
2024-04-03 20:44:30 +09:00
onPressed: () async {
2023-10-06 16:25:21 +05:30
if (emailController.text.isEmpty ||
passwordController
.text.isEmpty) {
Get.snackbar(
"no_values".tr,
"email_and_password_required"
.tr,
backgroundColor: Colors.red,
colorText: Colors.white,
icon: const Icon(
2023-10-06 16:25:21 +05:30
Icons
.assistant_photo_outlined,
size: 40.0,
color: Colors.blue),
snackPosition:
SnackPosition.TOP,
duration: const Duration(
2024-04-03 21:39:12 +09:00
seconds: 3),
// backgroundColor: Colors.yellow,
2023-10-06 16:25:21 +05:30
//icon:Image(image:AssetImage("assets/images/dora.png"))
);
return;
}
indexController.isLoading.value =
true;
indexController.login(
emailController.text,
passwordController.text,
context);
},
color: Colors.indigoAccent[400],
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(40)),
child: Text(
"login".tr,
2024-07-15 06:54:02 +09:00
style: const TextStyle(
2023-10-06 16:25:21 +05:30
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white70),
),
),
const SizedBox(
height: 5.0,
),
MaterialButton(
minWidth: double.infinity,
height: 36,
2023-10-06 16:25:21 +05:30
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: 2.0,
),
MaterialButton(
minWidth: double.infinity,
height: 36,
2023-10-06 16:25:21 +05:30
onPressed: () {
Get.back();
},
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(40)),
child: Text(
"cancel".tr,
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16,
color: Colors.white70),
),
),
],
)),
),
)),
const SizedBox(
height: 3,
2022-12-27 18:52:37 +05:30
),
2023-10-06 16:25:21 +05:30
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"rogaining_user_need_tosign_up".tr,
style: const TextStyle(
overflow: TextOverflow.ellipsis,
fontSize: 10.0
2023-10-06 16:25:21 +05:30
),
),
),
),
],
2022-12-27 18:52:37 +05:30
),
2023-10-06 16:25:21 +05:30
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"app_developed_by_gifu_dx".tr,
style: const TextStyle(
overflow: TextOverflow.ellipsis,
fontSize: 10.0),
),
),
),
],
),
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"※第8回と第9回は、岐阜県の令和年度「清流の国ぎふ」SDGs推進ネットワーク連携促進補助金を受けています",
style: TextStyle(
//overflow: TextOverflow.ellipsis,
fontSize:
10.0, // Consider adjusting the font size if the text is too small.
// Removed overflow: TextOverflow.ellipsis to allow text wrapping.
),
),
),
),
],
),
2023-10-06 16:25:21 +05:30
],
2022-05-12 02:17:08 +05:30
),
2023-10-06 16:25:21 +05:30
],
),
2023-10-06 16:25:21 +05:30
)
: TextButton(
onPressed: () {
indexController.currentUser.clear();
},
child: const Text("Already Logged in, Click to logout"),
2022-05-12 02:17:08 +05:30
),
);
}
}
2023-10-06 16:25:21 +05:30
Widget makeInput(
{label, required TextEditingController controller, obsureText = false}) {
2022-05-12 02:17:08 +05:30
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2023-10-06 16:25:21 +05:30
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(
2023-10-06 16:25:21 +05:30
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(
2023-10-06 16:25:21 +05:30
borderSide: BorderSide(color: (Colors.grey[400])!),
2022-05-12 02:17:08 +05:30
),
),
),
2023-10-06 16:25:21 +05:30
const SizedBox(
height: 30.0,
)
2022-05-12 02:17:08 +05:30
],
);
}