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>(

View File

@@ -0,0 +1,169 @@
import 'package:cathaypay_mobile/Home/HomePage.dart';
import 'package:cathaypay_mobile/Home/home_bottom_menu_widget.dart';
import 'package:cathaypay_mobile/model/menu_icon_model.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:url_launcher/url_launcher.dart';
import '../GetPaid/GetPaid.dart';
import '../Pay/PayPage.dart';
import '../TopUp/TopUpMenuPage.dart';
import '../TransferMoney/TransferMoneyMenu.dart';
import '../api/api.dart';
class AllMenuPage extends StatefulWidget {
const AllMenuPage({Key? key}) : super(key: key);
@override
State<AllMenuPage> createState() => _PolicyPageState();
}
class _PolicyPageState extends State<AllMenuPage> {
var controller;
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (context.locale.toString() == "th") {
listMenu.add(MenuIconModel(fileUrl: "images/menu/27.png", localID: 0));
listMenu.add(MenuIconModel(fileUrl: "images/menu/26.png", localID: 1));
listMenu.add(MenuIconModel(fileUrl: "images/menu/25.png", localID: 2));
listMenu.add(MenuIconModel(fileUrl: "images/menu/31.png", localID: 3));
} else {
listMenu.add(MenuIconModel(fileUrl: "images/menu/22.png", localID: 0));
listMenu.add(MenuIconModel(fileUrl: "images/menu/23.png", localID: 1));
listMenu.add(MenuIconModel(fileUrl: "images/menu/24.png", localID: 2));
listMenu.add(MenuIconModel(fileUrl: "images/menu/32.png", localID: 3));
}
getMenu();
});
super.initState();
}
List<MenuIconModel> listMenu = [];
getMenu() {
Api.get(context, Api.menuIcons).then((value) => {
if (value != null)
{
setState(() {
value.forEach((v) {
listMenu.add(MenuIconModel.fromJson(v));
});
})
}
else
{}
});
}
Future<void> _launchUrl(String url) async {
if (!await launchUrl(Uri.parse(url))) {
throw Exception('Could not launch $url');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
// extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
leading: CupertinoButton(
onPressed: () {
Navigator.pop(context);
},
child: const Icon(
Icons.arrow_back,
color: Colors.black54,
),
),
elevation: 0,
centerTitle: true,
title: Text(
"แอปพลิเคชันทั้งหมด".tr(),
textAlign: TextAlign.center,
style: GoogleFonts.kanit(
color: Colors.black,
fontSize: 20,
),
),
),
body: SafeArea(
child: Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: GridView.count(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 4,
childAspectRatio: 1 / 1,
mainAxisSpacing: 5.0,
crossAxisSpacing: 5.0,
children: listMenu.map((MenuIconModel promo) {
return InkWell(
onTap: () {
switch (promo.localID) {
case 0:
showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return GetPaidPage();
});
break;
case 1:
showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return TransferMoneyMenuPage();
});
break;
case 2:
showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return PayPage();
});
break;
case 3:
showModalBottomSheet(
context: context,
isScrollControlled: true,
useSafeArea: true,
builder: (BuildContext context) {
return SafeArea(child: TopUpMenuPage());
});
break;
}
String url = "${promo.link}?token=${promo.token}&id=${profile?.id}&mobile=${profile?.phoneNumber}&email=${profile?.email}";
print(url);
_launchUrl( url);
},
child: promo.fileUrl != null
? promo.fileUrl!.startsWith("http")
? Image.network(promo.fileUrl ?? "")
: Image.asset(promo.fileUrl ?? "")
: Container(),
);
}).toList()),
),
),
HomeBottomMenuWidget()
],
)),
);
}
}

View File

@@ -1,3 +1,4 @@
import 'package:cathaypay_mobile/Home/all_menu.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
@@ -27,7 +28,7 @@ class _HomePageState extends State<HomeBottomMenuWidget> {
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(20),
padding: EdgeInsets.all(10),
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),
@@ -42,10 +43,10 @@ class _HomePageState extends State<HomeBottomMenuWidget> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
height: 45,
width: 45,
child: Image(
image: AssetImage('images/home/1.home.png'),
image: AssetImage('images/home/15.png'),
fit: BoxFit.cover,
),
),
@@ -70,10 +71,10 @@ class _HomePageState extends State<HomeBottomMenuWidget> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
height: 45,
width: 45,
child: Image(
image: AssetImage('images/home/2.scan.png'),
image: AssetImage('images/home/17.png'),
fit: BoxFit.cover,
),
),
@@ -101,17 +102,24 @@ class _HomePageState extends State<HomeBottomMenuWidget> {
),
InkWell(
onTap: () {
// clearProfile();
Navigator.popUntil(context, ModalRoute.withName('/'));
Navigator.pushNamed(context, '/HomePage');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AllMenuPage(),
),
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 35,
width: 35,
height: 45,
width: 45,
child: Image(
image: AssetImage('images/home/3.all.png'),
image: AssetImage('images/home/19.png'),
fit: BoxFit.cover,
),
),