This commit is contained in:
Manasit.K
2024-12-12 10:12:19 +07:00
parent 43c32ef6cf
commit ed510b00d1
52 changed files with 1256 additions and 1027 deletions

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:cathaypay_mobile/GetPaid/GetPaid.dart';
@@ -9,9 +10,11 @@ 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:device_info_plus/device_info_plus.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:permission_handler/permission_handler.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';
@@ -19,6 +22,7 @@ import 'package:url_launcher/url_launcher.dart';
import '../api/api.dart';
import '../model/promotion_model.dart';
import '../model/token_model.dart';
import '../utils/color_custom.dart';
import '../utils/utils.dart';
Profile? profile;
@@ -40,9 +44,38 @@ class _HomePageState extends State<HomePage> {
getTokenAdmin();
getBanner();
getPromotion();
checkAndRequestPermissions(skipIfExists: true);
super.initState();
}
Future<bool> checkAndRequestPermissions({required bool skipIfExists}) async {
if (!Platform.isAndroid && !Platform.isIOS) {
return false; // Only Android and iOS platforms are supported
}
if (Platform.isAndroid) {
final deviceInfo = await DeviceInfoPlugin().androidInfo;
final sdkInt = deviceInfo.version.sdkInt;
if (skipIfExists) {
// Read permission is required to check if the file already exists
return sdkInt >= 33
? await Permission.photos.request().isGranted
: await Permission.storage.request().isGranted;
} else {
// No read permission required for Android SDK 29 and above
return sdkInt >= 29 ? true : await Permission.storage.request().isGranted;
}
} else if (Platform.isIOS) {
// iOS permission for saving images to the gallery
return skipIfExists
? await Permission.photos.request().isGranted
: await Permission.photosAddOnly.request().isGranted;
}
return false; // Unsupported platforms
}
Future<void> getProfile() async {
Api.get(context, Api.profile).then((value) => {
if (value != null) {initProfile(value)} else {clearProfile()}
@@ -206,13 +239,13 @@ class _HomePageState extends State<HomePage> {
children: [
context.locale.toString() == "th"
? Image.asset(
"images/home/lang_20.png",
width: 20,
)
"images/home/lang_20.png",
width: 20,
)
: Image.asset(
"images/home/lang_21.png",
width: 20,
),
"images/home/lang_21.png",
width: 20,
),
SizedBox(
width: 5,
),
@@ -391,7 +424,7 @@ class _HomePageState extends State<HomePage> {
],
),
),
/* Container(
/* Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
@@ -485,7 +518,7 @@ class _HomePageState extends State<HomePage> {
],
),
)*/
HomeBottomMenuWidget()
HomeBottomMenuWidget()
],
),
),
@@ -609,44 +642,39 @@ class _CardHomePageState extends State<CardHomePage> {
return SafeArea(child: TopUpMenuPage());
});
},
child: Container(
child: SizedBox(
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,
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
),
child: Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 30,
child: Text(
"Wallet Topup".tr(),
style: GoogleFonts.kanit(
color: ColorCustom.red,
fontSize: 18,
),
),
),
),
Spacer(),
Image(
image: AssetImage('images/home/icon_plus.png'),
fit: BoxFit.cover,
color: ColorCustom.red,
)
],
),
Spacer(),
Image(
image: AssetImage('images/home/icon_plus.png'),
fit: BoxFit.cover,
)
],
),
),
),
),
@@ -749,48 +777,43 @@ class _CardHomePageState extends State<CardHomePage> {
return SafeArea(child: PayPage());
});
},
child: Container(
child: SizedBox(
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,
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
),
child: Container(
padding: EdgeInsets.all(10),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 30,
child: Text(
"Pay".tr(),
style: GoogleFonts.kanit(
color: ColorCustom.red,
fontSize: 18,
),
),
),
),
Spacer(),
Container(
width: 21,
height: 21,
child: Image(
image: AssetImage('images/home/icon_qr.png'),
fit: BoxFit.cover,
color: ColorCustom.red,
),
)
],
),
Spacer(),
Container(
width: 21,
height: 21,
child: Image(
image: AssetImage('images/home/icon_qr.png'),
fit: BoxFit.cover,
),
)
],
),
),
),
),
@@ -819,43 +842,25 @@ class _MenuHomePageState extends State<MenuHomePage> {
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,
),
),
],
Expanded(
child: InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return GetPaidPage();
});
},
child: Image(
width: 80,
height: 80,
image: context.locale.toString() == "th" ? AssetImage('images/menu/27.png') : AssetImage('images/menu/22.png'),
fit: BoxFit.fitHeight,
),
),
),
),),
/* InkWell(
onTap: () {
showModalBottomSheet<void>(
@@ -898,83 +903,47 @@ class _MenuHomePageState extends State<MenuHomePage> {
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,
),
),
],
),
),
),),
Expanded(
child: InkWell(
onTap: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return TransferMoneyMenuPage();
});
},
child: Image(
width: 80,
height: 80,
image: context.locale.toString() == "th" ? AssetImage('images/menu/26.png') : AssetImage('images/menu/23.png'),
fit: BoxFit.fitHeight,
),
),
),
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,
),
),
],
),
),
),),
Expanded(
child: InkWell(
onTap: () {
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return PayPage();
});
},
child: Image(
width: 80,
height: 80,
image: context.locale.toString() == "th" ? AssetImage('images/menu/25.png') : AssetImage('images/menu/24.png'),
fit: BoxFit.fitHeight,
),
),
),
/* InkWell(
onTap: () {
showModalBottomSheet<void>(