Files
Neo_wallet/neowallet_mobile/lib/Login/Login.dart
nutchayut b9ec3e6104 bug fixed
2025-01-09 23:50:38 +07:00

255 lines
9.1 KiB
Dart

import 'dart:convert';
import 'package:cathaypay_mobile/Register/pre_register.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../PinCodeVadidate.dart';
import '../api/api.dart';
import '../model/token_model.dart';
import '../utils/color_custom.dart';
import 'LoginValidate.dart';
class LoginPage extends StatefulWidget {
const LoginPage({Key? key}) : super(key: key);
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override
void initState() {
checkLogin();
getVersion();
super.initState();
}
checkLogin() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var value = await prefs.getString('access_token');
print(value);
tokenModel = TokenModel.fromJson(json.decode(value ?? ""));
if (tokenModel != null) {
print(tokenModel!.email!);
getProfile();
}
}
Future<void> getProfile() async {
Api.get(context, Api.profile).then((value) => {
if (value != null) {initProfile()} else {clearProfile()}
});
}
initProfile() async {
var result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PinCodeValidatePage(),
),
);
if (result) {
Navigator.pushNamed(context, '/HomePage');
}
}
clearProfile() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("access_token", "");
Navigator.popUntil(context, ModalRoute.withName('/'));
}
refresh() {
setState(() {});
}
String version = "";
getVersion() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String v = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
setState(() {
version = "$v ($buildNumber)";
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Container(
color: Colors.white,
),
),
Column(
children: [
Container(
margin: EdgeInsets.symmetric(vertical: 60, horizontal: 60),
child: Image(
image: AssetImage('images/neopay_logo.png'),
),
),
Expanded(
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
bottomLeft: Radius.circular(0),
bottomRight: Radius.circular(0),
),
boxShadow: [BoxShadow(color: Color.fromRGBO(0, 0, 0, 0.10000000149011612), offset: Offset(0, -4), blurRadius: 4)],
color: ColorCustom.primaryColor,
),
child: Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
child: Text(
"Welcome".tr(),
style: GoogleFonts.kanit(
color: Color(0xff9d001b),
fontSize: 45,
fontWeight: FontWeight.w500,
),
),
),
SizedBox(height: 1.68),
SizedBox(
child: Text(
"to NEO TRAVEL".tr(),
style: GoogleFonts.kanit(
color: Color(0xff565656),
fontSize: 20,
fontWeight: FontWeight.w300,
),
),
),
],
),
),
InkWell(
onTap: () {
if (context.locale.toString() == "th") {
context.setLocale(Locale('en', ''));
} else {
context.setLocale(Locale('th', ''));
}
refresh();
},
child: context.locale.toString() == "th"
? Image.asset(
"images/home/lang_1.png",
width: 80,
)
: Image.asset(
"images/home/lang_2.png",
width: 80,
))
],
)),
Spacer(),
InkWell(
onTap: () {
Navigator.pushNamed(context, '/LoginValidate');
},
child: SizedBox(
width: double.infinity,
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
// side: BorderSide(color: ColorCustom.red, width: 1)
),
child: Container(
padding: EdgeInsets.all(10),
child: Text(
"Log In".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: ColorCustom.red,
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
),
),
),
SizedBox(height: 10),
InkWell(
onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => RegisterData(),
// ),
// );
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PreRegisterPage(),
),
);
},
child: SizedBox(
width: double.infinity,
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
),
child: Container(
padding: EdgeInsets.all(10),
child: Text(
"Register".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: ColorCustom.red,
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
),
),
),
SizedBox(height: 20),
Text(
version,
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Colors.black,
fontSize: 14,
),
),
SizedBox(height: 20),
],
),
),
)
],
),
]),
);
}
}