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

1154 lines
42 KiB
Dart

import 'dart:convert';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:cathaypay_mobile/GetPaid/GetPaid.dart';
import 'package:cathaypay_mobile/Home/home_bottom_menu_widget.dart';
import 'package:cathaypay_mobile/Login/LoginValidate.dart';
import 'package:cathaypay_mobile/Pay/PayPage.dart';
import 'package:cathaypay_mobile/TopUp/TopUpMenuPage.dart';
import 'package:cathaypay_mobile/TransferMoney/TransferMoneyMenu.dart';
import 'package:cathaypay_mobile/model/banner_model.dart';
import 'package:cathaypay_mobile/model/profile_model.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import '../api/api.dart';
import '../model/promotion_model.dart';
import '../model/token_model.dart';
import '../utils/utils.dart';
Profile? profile;
String tokenAdmin = "";
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
// getProfile(context);
// getBalance(context);
// getPoint(context);
getTokenAdmin();
getBanner();
getPromotion();
super.initState();
}
Future<void> getProfile() async {
Api.get(context, Api.profile).then((value) => {
if (value != null) {initProfile(value)} else {clearProfile()}
});
}
initProfile(value) {
setState(() {
profile = Profile.fromJson(value["profile"]);
});
_refreshController.refreshCompleted();
}
clearProfile() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("access_token", "");
Navigator.popUntil(context, ModalRoute.withName('/'));
}
lockTest() {
var param = jsonEncode(<dynamic, dynamic>{"userId": profile?.id});
Api.post(context, Api.lockTest, param).then((value) => {
if (value != null)
{
value.forEach((v) {
if (v["file_url"] != null) {
listBanner.add(BannerModel.fromJson(v));
}
}),
refresh()
}
else
{}
});
}
List<BannerModel> listBanner = [];
getBanner() {
Api.get(context, Api.banner).then((value) => {
if (value != null)
{
value.forEach((v) {
if (v["file_url"] != null) {
listBanner.add(BannerModel.fromJson(v));
}
}),
refresh()
}
else
{}
});
}
List<PromotionModel> listPromotion = [];
getPromotion() {
Api.get(context, Api.promotion).then((value) => {
if (value != null)
{
value.forEach((v) {
if (v["file_url"] != null) {
listPromotion.add(PromotionModel.fromJson(v));
}
}),
refresh()
}
else
{}
});
}
getTokenAdmin() {
// Api.get(context, Api.getTokenAdmin).then((value) => {tokenAdmin = value["token"]});
var param = jsonEncode(<dynamic, dynamic>{
"UserName": Api.userAdmin,
"Password": Api.passAdmin,
"MobileDeviceId": Api.mobileAdmin,
});
Api.postLogin(context, Api.login, param).then((value) => {
if (value != null)
{
setState(() {
var tokenModel = TokenModel.fromJson(value);
tokenAdmin = tokenModel.token ?? "";
})
}
else
{}
});
}
refresh() {
setState(() {});
}
Future<void> _launchUrl(String url) async {
if (!await launchUrl(Uri.parse(url))) {
throw Exception('Could not launch $url');
}
}
RefreshController _refreshController = RefreshController(initialRefresh: false);
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SmartRefresher(
onRefresh: () {
getProfile();
},
controller: _refreshController,
child: Column(
children: [
Expanded(
child: Stack(
children: [
Container(
width: MediaQuery.of(context).size.width,
child: Image(
image: AssetImage('images/home/Head.png'),
fit: BoxFit.fitWidth,
),
),
SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: [
Container(
alignment: Alignment.centerRight,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell(
onTap: () {
clearProfile();
},
child: Icon(
Icons.logout,
size: 20,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
InkWell(
onTap: () {
if (context.locale.toString() == "th") {
context.setLocale(Locale('en', ''));
} else {
context.setLocale(Locale('th', ''));
}
refresh();
},
child: Row(
children: [
context.locale.toString() == "th"
? Image.asset(
"images/home/lang_20.png",
width: 20,
)
: Image.asset(
"images/home/lang_21.png",
width: 20,
),
SizedBox(
width: 5,
),
Text(
context.locale.toString().toUpperCase(),
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 14,
),
),
],
),
),
],
),
),
Container(
padding: EdgeInsets.only(left: 10),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image(
image: AssetImage('images/neopay_logo.png'),
fit: BoxFit.fitHeight,
height: 80,
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Your Name".tr(),
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w300,
),
),
Text(
tokenModel?.fullName ?? "",
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 18,
),
),
SizedBox(
height: 10,
),
Text(
"Member ID".tr(),
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w300,
),
),
Text(
tokenModel?.maxCardMembers?.first.maxCardID ?? "",
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 18,
),
),
],
)
],
),
),
),
SizedBox(
height: 20,
),
CardHomePage(),
SizedBox(
height: 20,
),
MenuHomePage(),
SizedBox(
height: 20,
),
CarouselSlider(
options: CarouselOptions(
height: 200.0,
aspectRatio: 16 / 9,
viewportFraction: 1.0,
initialPage: 0,
enableInfiniteScroll: true,
reverse: false,
autoPlay: true,
enlargeCenterPage: true,
),
items: listBanner.map((i) {
return Builder(
builder: (BuildContext context) {
return InkWell(
onTap: () {
_launchUrl(i.link ?? "");
},
child: Container(width: MediaQuery.of(context).size.width, child: i.fileUrl != null ? Image.network(i.fileUrl ?? "") : Container()),
);
},
);
}).toList(),
),
/* Image(
image: AssetImage('images/home/Banner.png'),
fit: BoxFit.fill,
),*/
SizedBox(
height: 20,
),
Row(
children: [
Text(
"Promotions for you".tr(),
style: GoogleFonts.kanit(
color: Color(0xff050505),
fontSize: 16,
),
),
Spacer()
],
),
SizedBox(
height: 20,
),
GridView.count(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 2,
childAspectRatio: 1 / 1,
mainAxisSpacing: 5.0,
crossAxisSpacing: 5.0,
children: listPromotion.map((PromotionModel promo) {
return InkWell(
onTap: () {
_launchUrl(promo.link ?? "");
},
child: promo.fileUrl != null
? ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.network(promo.fileUrl ?? ""),
)
: Container(),
);
}).toList()),
/*CarouselSlider(
options: CarouselOptions(
height: 200.0,
aspectRatio: 16 / 9,
viewportFraction: 1.0,
initialPage: 0,
enableInfiniteScroll: true,
reverse: false,
autoPlay: true,
enlargeCenterPage: true,
),
items: listPromotion.map((i) {
return Builder(
builder: (BuildContext context) {
return InkWell(
onTap: () {
_launchUrl(i.link ?? "");
},
child: Container(width: MediaQuery.of(context).size.width, child: i.fileUrl != null ? Image.network(i.fileUrl ?? "") : Container()),
);
},
);
}).toList(),
),*/
],
),
))
],
),
),
/* Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
boxShadow: [BoxShadow(color: Color.fromRGBO(0, 0, 0, 0.07999999821186066), offset: Offset(0, -4), blurRadius: 4)],
color: Color.fromRGBO(255, 255, 255, 1),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
child: Image(
image: AssetImage('images/home/1.home.png'),
fit: BoxFit.cover,
),
),
Text(
"หน้าหลัก".tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xff65676b),
fontSize: 12,
),
)
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
child: Image(
image: AssetImage('images/home/2.scan.png'),
fit: BoxFit.cover,
),
),
Text(
"สแกน".tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xff65676b),
fontSize: 12,
),
)
],
),
InkWell(
onTap: () {
// clearProfile();
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
child: Image(
image: AssetImage('images/home/3.all.png'),
fit: BoxFit.cover,
),
),
Text(
"ทั้งหมด".tr(),
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xff65676b),
fontSize: 12,
),
)
],
),
),
],
),
),
],
),
)*/
HomeBottomMenuWidget()
],
),
),
));
}
}
class CardHomePage extends StatefulWidget {
const CardHomePage({Key? key}) : super(key: key);
@override
State<CardHomePage> createState() => _CardHomePageState();
}
class _CardHomePageState extends State<CardHomePage> {
@override
void initState() {
getProfile(context);
super.initState();
}
clearProfile() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("access_token", "");
Navigator.popUntil(context, ModalRoute.withName('/'));
}
getProfile(BuildContext context) {
Api.get(context, Api.profile).then((value) => {
if (value != null) {profile = Profile.fromJson(value["profile"]), refresh()} else {clearProfile()}
});
}
refresh() {
setState(() {});
}
@override
Widget build(BuildContext context) {
return Container(
width: 376,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
boxShadow: [
BoxShadow(
color: Color(0x19000000),
blurRadius: 4,
offset: Offset(1, 1),
),
],
color: Colors.white,
),
padding: const EdgeInsets.all(12),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 24,
child: Text(
"Balance".tr(),
style: GoogleFonts.kanit(
color: Color(0xff050505),
fontSize: 14,
fontWeight: FontWeight.w300,
),
),
),
Row(
children: [
Text(
Utils.moneyFormat(profile?.maxCardMembers.first.balance),
style: GoogleFonts.kanit(
color: Color(0xff050505),
fontSize: 20,
),
),
Text(
" ${"Baht".tr()}",
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 16,
fontWeight: FontWeight.w300,
),
),
InkWell(
child: Icon(
Icons.refresh,
size: 20,
color: Color(0xffd0315a),
),
onTap: () {
getProfile(context);
},
),
],
),
],
),
Expanded(child: Container()),
InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return SafeArea(child: TopUpMenuPage());
});
},
child: Container(
width: 160,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
boxShadow: [
BoxShadow(
color: Color(0x19000000),
blurRadius: 4,
offset: Offset(1, 1),
),
],
color: Color(0xffd0315a),
),
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 15,
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 30,
child: Text(
"Wallet Topup".tr(),
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 18,
),
),
),
Spacer(),
Image(
image: AssetImage('images/home/icon_plus.png'),
fit: BoxFit.cover,
)
],
),
),
),
],
),
),
SizedBox(height: 10),
Container(
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 92,
height: 24,
child: Text(
"Point".tr(),
style: GoogleFonts.kanit(
color: Color(0xff050505),
fontSize: 14,
fontWeight: FontWeight.w300,
),
),
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 24,
height: 24,
child: Stack(
children: [
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0xffd0315a),
),
),
Positioned(
left: 8,
top: 2,
child: Text(
"P",
style: GoogleFonts.kanit(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
SizedBox(width: 8),
Row(
children: [
Text(
Utils.moneyFormat(profile?.maxCardMembers.first.pointBalance),
style: GoogleFonts.kanit(
color: Color(0xff050505),
fontSize: 20,
),
),
/* Text(
" ${"Point".tr()}",
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 16,
fontWeight: FontWeight.w300,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),*/
],
),
],
),
],
),
),
SizedBox(width: 20),
InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return SafeArea(child: PayPage());
});
},
child: Container(
width: 160,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
boxShadow: [
BoxShadow(
color: Color(0x19000000),
blurRadius: 4,
offset: Offset(1, 1),
),
],
color: Color(0xfff2f2f2),
),
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 15,
),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 30,
child: Text(
"Pay".tr(),
style: GoogleFonts.kanit(
color: Color(0xffd0315a),
fontSize: 18,
),
),
),
Spacer(),
Container(
width: 21,
height: 21,
child: Image(
image: AssetImage('images/home/icon_qr.png'),
fit: BoxFit.cover,
),
)
],
),
),
),
],
),
),
],
),
);
}
}
class MenuHomePage extends StatefulWidget {
const MenuHomePage({Key? key}) : super(key: key);
@override
State<MenuHomePage> createState() => _MenuHomePageState();
}
class _MenuHomePageState extends State<MenuHomePage> {
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(child: InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return GetPaidPage();
});
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/1.png'),
fit: BoxFit.cover,
),
Text(
"Receive Money".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),),
/* InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return GetPaidShopByAmount();
});
},
child: Container(
width: 85,
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/1.png'),
fit: BoxFit.cover,
),
Text(
"SHOP",
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),*/
SizedBox(
width: 10,
),
Expanded(child: InkWell(
onTap: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return TransferMoneyMenuPage();
});
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/2.png'),
fit: BoxFit.cover,
),
Text(
"Transfer Money".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),),
SizedBox(
width: 10,
),
Expanded(child: InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return PayPage();
});
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/5.png'),
fit: BoxFit.cover,
),
Text(
"Pay".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),),
/* InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return SafeArea(child: WithDrawMenuPage());
});
},
child: Container(
width: 85,
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/3.png'),
fit: BoxFit.cover,
),
Text(
"ถอนเงิน",
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),
SizedBox(
width: 10,
),
InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return EFXPage();
});
},
child: Container(
width: 85,
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/1.png'),
fit: BoxFit.cover,
),
Text(
"eFx",
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),*/
],
),
/* SizedBox(
height: 15,
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10,
),
InkWell(
// onTap: () { showModalBottomSheet<void>(
// context: context,
// isScrollControlled: true,useSafeArea: true,
// builder: (BuildContext context) {
// return PointMenuPage();
// });},
child: Container(
width: 85,
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image(
width: 50,
height: 50,
image: AssetImage('images/home/6.png'),
fit: BoxFit.cover,
),
Text(
"Point Transfer",
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Color(0xff65676b),
fontSize: 13,
),
),
],
),
),
),
InkWell(
onTap: () {},
child: Container(
width: 85,
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.transparent,
),
),
),
InkWell(
onTap: () {},
child: Container(
width: 85,
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.transparent,
),
),
),
],
),
)*/
],
),
);
}
}
class PromotionPage extends StatefulWidget {
const PromotionPage({Key? key}) : super(key: key);
@override
State<PromotionPage> createState() => _PromotionPageState();
}
class _PromotionPageState extends State<PromotionPage> {
@override
Widget build(BuildContext context) {
return Container();
}
}