Files
Neo_wallet/neowallet_mobile/lib/Login/Login.dart
Manasit.K 43c32ef6cf init
2024-10-31 15:57:57 +07:00

285 lines
10 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 '../Register/register_data.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: Container(
width: MediaQuery
.of(context)
.size
.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
border: Border.all(
color: Color(0xff9d001b),
width: 1,
),
),
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 12,
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
child: Text(
"Log In".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff9d001b),
fontSize: 20,
fontWeight: FontWeight.w300,
),
),
),
],
),
),
),
SizedBox(height: 10),
InkWell(
onTap: () {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (context) => RegisterData(),
// ),
// );
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PreRegisterPage(),
),
);
},
child: Container(
width: MediaQuery
.of(context)
.size
.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: Color(0xffd0315a),
),
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 12,
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
child: Text(
"Register".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
),
SizedBox(height: 20),
Text(
version,
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Colors.black,
fontSize: 14,
),
),
SizedBox(height: 20),
],
),
),
)
],
),
]),
);
}
}