update packages, replace barcode_widget with, qr_bar_code & update for new code package
This commit is contained in:
parent
d7e4ac134d
commit
e3766c827e
12 changed files with 925 additions and 823 deletions
|
|
@ -1,21 +1,19 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_banner_ad.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_display_slanted.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_display_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_edit_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_wallet_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_display.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:screen_brightness/screen_brightness.dart';
|
||||
|
||||
|
|
@ -38,556 +36,18 @@ class BuildLoyaltyCardList extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
final TextEditingController _nicknameController = TextEditingController();
|
||||
final TextEditingController _cardNumberController = TextEditingController();
|
||||
late int _noFavourites;
|
||||
double? _originalBrightness;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
void openscanner() async {
|
||||
context.pushNamed(
|
||||
"barcodeScanner",
|
||||
extra: _cardNumberController,
|
||||
);
|
||||
}
|
||||
|
||||
void editCardWindow(
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
BuildContext ctxt,
|
||||
int index,
|
||||
double width) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: "Edit Loyalty Card",
|
||||
onWindowTapClose: () {
|
||||
_cardNumberController.clear();
|
||||
_nicknameController.clear();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
windowBody: Padding(
|
||||
padding:
|
||||
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||
? EdgeInsets.symmetric(horizontal: width * 0.05)
|
||||
: EdgeInsets.symmetric(horizontal: width * 0),
|
||||
child: Column(
|
||||
children: [
|
||||
MihForm(
|
||||
formKey: _formKey,
|
||||
formFields: [
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.secondary(),
|
||||
inputColor: MihColors.primary(),
|
||||
controller: _nicknameController,
|
||||
multiLineInput: false,
|
||||
requiredText: false,
|
||||
hintText: "Card Title",
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.secondary(),
|
||||
inputColor: MihColors.primary(),
|
||||
controller: _cardNumberController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: "Card Number",
|
||||
numberMode: true,
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
openscanner();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 100,
|
||||
child: Text(
|
||||
"Scan",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
walletProvider.updateLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
MIHLoyaltyCard(
|
||||
idloyalty_cards:
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
app_id: widget.cardList[index].app_id,
|
||||
shop_name: widget.cardList[index].shop_name,
|
||||
card_number: _cardNumberController.text,
|
||||
favourite: widget.cardList[index].favourite,
|
||||
priority_index:
|
||||
widget.cardList[index].priority_index,
|
||||
nickname: _nicknameController.text,
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully updated the loyalty card details.",
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Update",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void deleteCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
MihAlertServices().deleteConfirmationAlert(
|
||||
"This Card will be deleted permanently from your Mzansi Wallet. Are you certain you want to delete it?",
|
||||
() async {
|
||||
walletProvider.deleteLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
widget.cardList[index],
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully deleted the loyalty card from your Mzansi Wallet.",
|
||||
context,
|
||||
);
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
void addToFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
MihAlertServices().warningAdvancedAlert(
|
||||
// "Card Added to Favourites",
|
||||
"Add Card to Favourites?",
|
||||
"Would you like to add this card to your favourites for quick access?",
|
||||
// "You have successfully added the loyalty card to your favourites.",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
},
|
||||
buttonColor: MihColors.red(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
await walletProvider.updateLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
MIHLoyaltyCard(
|
||||
idloyalty_cards: widget.cardList[index].idloyalty_cards,
|
||||
app_id: widget.cardList[index].app_id,
|
||||
shop_name: widget.cardList[index].shop_name,
|
||||
card_number: widget.cardList[index].card_number,
|
||||
favourite: "Yes",
|
||||
priority_index: _noFavourites,
|
||||
nickname: widget.cardList[index].nickname,
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.read<MzansiWalletProvider>().setToolIndex(1);
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully added the loyalty card to your favourites.",
|
||||
context,
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Add",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
void removeFromFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
MihAlertServices().warningAdvancedAlert(
|
||||
"Remove From Favourites?",
|
||||
"Are you sure you want to remove this card from your favourites?",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
await walletProvider.updateLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
MIHLoyaltyCard(
|
||||
idloyalty_cards: widget.cardList[index].idloyalty_cards,
|
||||
app_id: widget.cardList[index].app_id,
|
||||
shop_name: widget.cardList[index].shop_name,
|
||||
card_number: widget.cardList[index].card_number,
|
||||
favourite: "",
|
||||
priority_index: 0,
|
||||
nickname: widget.cardList[index].nickname,
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.read<MzansiWalletProvider>().setToolIndex(0);
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully removed the loyalty card to your favourites.",
|
||||
context,
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.red(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Remove",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
ctxt,
|
||||
);
|
||||
}
|
||||
|
||||
Color getCardColor(String shopName) {
|
||||
switch (shopName.toLowerCase()) {
|
||||
case "apple tree":
|
||||
return const Color(0xFFffffff);
|
||||
case "best before":
|
||||
return const Color(0xFF000000);
|
||||
case "checkers":
|
||||
return const Color(0xFF00a6a3);
|
||||
case "clicks":
|
||||
return const Color(0xFF005baa);
|
||||
case "cotton:on":
|
||||
return const Color(0xFFffffff);
|
||||
case "dis-chem":
|
||||
return const Color(0xFF00a950);
|
||||
case "pick n pay":
|
||||
return const Color(0xFFffffff);
|
||||
case "shoprite":
|
||||
return const Color(0xFFc12514);
|
||||
case "spar":
|
||||
return const Color(0xFFffffff);
|
||||
case "woolworths":
|
||||
return const Color(0xFF000000);
|
||||
case "makro":
|
||||
return const Color(0xFFffffff);
|
||||
case "fresh stop":
|
||||
return const Color(0xFF50b849);
|
||||
case "panarottis":
|
||||
return const Color(0xFF3c3c3b);
|
||||
case "shell":
|
||||
return const Color(0xFF1d232a);
|
||||
case "edgars":
|
||||
return const Color(0xFFffffff);
|
||||
case "jet":
|
||||
return const Color(0xFFffffff);
|
||||
case "spur":
|
||||
return const Color(0xFF0a0157);
|
||||
case "infinity":
|
||||
return const Color(0xFFffffff);
|
||||
case "eskom":
|
||||
return const Color(0xFF003897);
|
||||
case "+more":
|
||||
return const Color(0xFFffffff);
|
||||
case "bp":
|
||||
return const Color(0xFF9dc600);
|
||||
case "builders warehouse":
|
||||
return const Color(0xFFffcb26);
|
||||
case "exclusive books":
|
||||
return const Color(0xFF2abdc5);
|
||||
case "pna":
|
||||
return const Color(0xFFcf3339);
|
||||
case "pq clothing":
|
||||
return const Color(0xFFed2223);
|
||||
case "rage":
|
||||
return const Color(0xFFffffff);
|
||||
case "sasol":
|
||||
return const Color(0xFFffffff);
|
||||
case "tfg group":
|
||||
return const Color(0xFF622775);
|
||||
case "toys r us":
|
||||
return const Color(0xFF0962ad);
|
||||
case "leroy merlin":
|
||||
return const Color(0xFFffffff);
|
||||
case "signature cosmetics & fragrances":
|
||||
return const Color(0xFFec028b);
|
||||
case "ok foods":
|
||||
return const Color(0xFFffffff);
|
||||
case "choppies":
|
||||
return const Color(0xFFffffff);
|
||||
case "boxer":
|
||||
return const Color(0xFFffffff);
|
||||
case "carrefour":
|
||||
return const Color(0xFFffffff);
|
||||
case "sefalana":
|
||||
return const Color(0xFFffffff);
|
||||
case "big save":
|
||||
return const Color(0xFF333333);
|
||||
case "justrite":
|
||||
return const Color(0xFF50b849);
|
||||
case "naivas":
|
||||
return const Color(0xFFf26535);
|
||||
case "kero":
|
||||
return const Color(0xFF004986);
|
||||
case "auchan":
|
||||
return const Color(0xFFffffff);
|
||||
case "woermann brock":
|
||||
return const Color(0xFFe31e2d);
|
||||
case "continente":
|
||||
return const Color(0xFFffffff);
|
||||
case "fresmart":
|
||||
return const Color(0xFF72ba2e);
|
||||
case "total energies":
|
||||
return const Color(0xFFffffff);
|
||||
case "engen":
|
||||
return const Color(0xFF002b8f);
|
||||
default:
|
||||
return const Color(0xFFffffff);
|
||||
}
|
||||
}
|
||||
|
||||
void viewCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, int index, double width) {
|
||||
//print(widget.cardList[index].card_number);
|
||||
String formattedCardNumber = "";
|
||||
for (int i = 0; i <= widget.cardList[index].card_number.length - 1; i++) {
|
||||
formattedCardNumber += widget.cardList[index].card_number[i];
|
||||
if ((i + 1) % 4 == 0) {
|
||||
formattedCardNumber += "\t";
|
||||
}
|
||||
}
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => MihPackageWindow(
|
||||
backgroundColor: getCardColor(widget.cardList[index].shop_name),
|
||||
fullscreen: false,
|
||||
windowTitle: null,
|
||||
menuOptions: [
|
||||
SpeedDialChild(
|
||||
child: widget.cardList[index].favourite == ""
|
||||
? Icon(
|
||||
Icons.favorite,
|
||||
color: MihColors.primary(),
|
||||
)
|
||||
: Icon(
|
||||
Icons.favorite_border,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: widget.cardList[index].favourite == ""
|
||||
? "Add to Favourite"
|
||||
: "Remove from Favourite",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
if (widget.cardList[index].favourite == "") {
|
||||
addToFavCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
);
|
||||
} else {
|
||||
removeFromFavCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: "Edit Card Details",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_cardNumberController.text = widget.cardList[index].card_number;
|
||||
_nicknameController.text = widget.cardList[index].nickname;
|
||||
});
|
||||
editCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
width,
|
||||
);
|
||||
},
|
||||
),
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.delete,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: "Delete Card",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
deleteCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
onWindowTapClose: () {
|
||||
resetScreenBrightness();
|
||||
context.pop();
|
||||
},
|
||||
windowBody: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
SizedBox(
|
||||
width: 500,
|
||||
child: MihCardDisplay(
|
||||
shopName: widget.cardList[index].shop_name,
|
||||
nickname: widget.cardList[index].nickname,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
width: 500,
|
||||
//color: Colors.white,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// const SizedBox(height: 10),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
// width: 300,
|
||||
child: BarcodeWidget(
|
||||
//color: MihColors.secondary(),
|
||||
barcode: Barcode.code128(),
|
||||
backgroundColor: Colors.white,
|
||||
data: widget.cardList[index].card_number,
|
||||
drawText: false,
|
||||
),
|
||||
// SfBarcodeGenerator(
|
||||
// backgroundColor: Colors.white,
|
||||
// barColor: Colors.black,
|
||||
// value: widget.cardList[index].card_number,
|
||||
// symbology: Code128(),
|
||||
// //showValue: true,
|
||||
// ),
|
||||
),
|
||||
),
|
||||
// const SizedBox(height: 10),
|
||||
Text(
|
||||
formattedCardNumber,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold
|
||||
//MihColors.secondary(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) MihBannerAd()
|
||||
// MihBannerAd(),
|
||||
],
|
||||
),
|
||||
builder: (context) => MihCardDisplayWindow(
|
||||
displayCard: widget.cardList[index],
|
||||
listIndex: index,
|
||||
noFavourites: _noFavourites,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -657,22 +117,6 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
|||
} else {
|
||||
KenLogger.warning(
|
||||
"Screen brightness adjustment is not supported on Web.");
|
||||
// _originalBrightness = 1.0; // Default brightness for web
|
||||
// await ScreenBrightness.instance.setSystemScreenBrightness(1.0);
|
||||
// KenLogger.success("Brightness set to default value: 1.0");
|
||||
}
|
||||
}
|
||||
|
||||
void resetScreenBrightness() async {
|
||||
if (!kIsWeb) {
|
||||
KenLogger.success(
|
||||
"Resetting screen brightness to original value: $_originalBrightness");
|
||||
if (_originalBrightness != null) {
|
||||
await ScreenBrightness.instance
|
||||
.setSystemScreenBrightness(_originalBrightness!);
|
||||
}
|
||||
} else {
|
||||
KenLogger.warning("Screen brightness reset is not supported on Web.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -687,8 +131,6 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Size size = MediaQuery.sizeOf(context);
|
||||
// final double width = size.width;
|
||||
//final double height = size.height;
|
||||
if (widget.cardList.isNotEmpty) {
|
||||
return Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
|
||||
builder: (BuildContext context,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,469 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_package_components/mih_banner_ad.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_display.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_card_edit_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_wallet_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qr_bar_code/code/src/code_generate.dart';
|
||||
import 'package:qr_bar_code/code/src/code_type.dart';
|
||||
import 'package:screen_brightness/screen_brightness.dart';
|
||||
|
||||
class MihCardDisplayWindow extends StatefulWidget {
|
||||
final MIHLoyaltyCard displayCard;
|
||||
final int listIndex;
|
||||
final int noFavourites;
|
||||
const MihCardDisplayWindow({
|
||||
super.key,
|
||||
required this.displayCard,
|
||||
required this.listIndex,
|
||||
required this.noFavourites,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihCardDisplayWindow> createState() => _MihCardDisplayWindowState();
|
||||
}
|
||||
|
||||
class _MihCardDisplayWindowState extends State<MihCardDisplayWindow> {
|
||||
double? _originalBrightness;
|
||||
|
||||
void resetScreenBrightness() async {
|
||||
if (!kIsWeb) {
|
||||
KenLogger.success(
|
||||
"Resetting screen brightness to original value: $_originalBrightness");
|
||||
if (_originalBrightness != null) {
|
||||
await ScreenBrightness.instance
|
||||
.setSystemScreenBrightness(_originalBrightness!);
|
||||
}
|
||||
} else {
|
||||
KenLogger.warning("Screen brightness reset is not supported on Web.");
|
||||
}
|
||||
}
|
||||
|
||||
String getFormattedCardNumber() {
|
||||
String formattedCardNumber = "";
|
||||
for (int i = 0; i <= widget.displayCard.card_number.length - 1; i++) {
|
||||
formattedCardNumber += widget.displayCard.card_number[i];
|
||||
if ((i + 1) % 4 == 0) {
|
||||
formattedCardNumber += "\t";
|
||||
}
|
||||
}
|
||||
return formattedCardNumber;
|
||||
}
|
||||
|
||||
void deleteCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
MihAlertServices().deleteConfirmationAlert(
|
||||
"This Card will be deleted permanently from your Mzansi Wallet. Are you certain you want to delete it?",
|
||||
() async {
|
||||
walletProvider.deleteLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
widget.displayCard,
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully deleted the loyalty card from your Mzansi Wallet.",
|
||||
context,
|
||||
);
|
||||
},
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
void addToFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
MihAlertServices().warningAdvancedAlert(
|
||||
// "Card Added to Favourites",
|
||||
"Add Card to Favourites?",
|
||||
"Would you like to add this card to your favourites for quick access?",
|
||||
// "You have successfully added the loyalty card to your favourites.",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
},
|
||||
buttonColor: MihColors.red(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
await walletProvider.updateLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
MIHLoyaltyCard(
|
||||
idloyalty_cards: widget.displayCard.idloyalty_cards,
|
||||
app_id: widget.displayCard.app_id,
|
||||
shop_name: widget.displayCard.shop_name,
|
||||
card_number: widget.displayCard.card_number,
|
||||
favourite: "Yes",
|
||||
priority_index: widget.noFavourites,
|
||||
nickname: widget.displayCard.nickname,
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.read<MzansiWalletProvider>().setToolIndex(1);
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully added the loyalty card to your favourites.",
|
||||
context,
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Add",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
context,
|
||||
);
|
||||
}
|
||||
|
||||
void removeFromFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
MihAlertServices().warningAdvancedAlert(
|
||||
"Remove From Favourites?",
|
||||
"Are you sure you want to remove this card from your favourites?",
|
||||
[
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
await walletProvider.updateLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
MIHLoyaltyCard(
|
||||
idloyalty_cards: widget.displayCard.idloyalty_cards,
|
||||
app_id: widget.displayCard.app_id,
|
||||
shop_name: widget.displayCard.shop_name,
|
||||
card_number: widget.displayCard.card_number,
|
||||
favourite: "",
|
||||
priority_index: 0,
|
||||
nickname: widget.displayCard.nickname,
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.read<MzansiWalletProvider>().setToolIndex(0);
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully removed the loyalty card to your favourites.",
|
||||
context,
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.red(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Remove",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
ctxt,
|
||||
);
|
||||
}
|
||||
|
||||
void editCardWindow(
|
||||
int index,
|
||||
) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => MihCardEditWindow(
|
||||
editCard: widget.displayCard,
|
||||
listIndex: widget.listIndex,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
|
||||
builder: (
|
||||
BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
Widget? child,
|
||||
) {
|
||||
return MihPackageWindow(
|
||||
backgroundColor: getCardColor(widget.displayCard.shop_name),
|
||||
fullscreen: false,
|
||||
windowTitle: null,
|
||||
menuOptions: [
|
||||
SpeedDialChild(
|
||||
child: widget.displayCard.favourite == ""
|
||||
? Icon(
|
||||
Icons.favorite,
|
||||
color: MihColors.primary(),
|
||||
)
|
||||
: Icon(
|
||||
Icons.favorite_border,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: widget.displayCard.favourite == ""
|
||||
? "Add to Favourite"
|
||||
: "Remove from Favourite",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
if (widget.displayCard.favourite == "") {
|
||||
addToFavCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
widget.listIndex,
|
||||
);
|
||||
} else {
|
||||
removeFromFavCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
widget.listIndex,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.edit,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: "Edit Card Details",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
editCardWindow(
|
||||
widget.listIndex,
|
||||
);
|
||||
},
|
||||
),
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.delete,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: "Delete Card",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () {
|
||||
deleteCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
widget.listIndex,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
onWindowTapClose: () {
|
||||
resetScreenBrightness();
|
||||
context.pop();
|
||||
},
|
||||
windowBody: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
SizedBox(
|
||||
width: 500,
|
||||
child: MihCardDisplay(
|
||||
shopName: widget.displayCard.shop_name,
|
||||
nickname: widget.displayCard.nickname,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
// width: 500,
|
||||
//color: Colors.white,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Code(
|
||||
data: widget.displayCard.card_number,
|
||||
codeType: CodeType.code128(),
|
||||
drawText: false,
|
||||
height: 250,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
getFormattedCardNumber(),
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold
|
||||
//MihColors.secondary(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
if (!kIsWeb && (Platform.isAndroid || Platform.isIOS))
|
||||
MihBannerAd()
|
||||
// MihBannerAd(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Color getCardColor(String shopName) {
|
||||
switch (shopName.toLowerCase()) {
|
||||
case "apple tree":
|
||||
return const Color(0xFFffffff);
|
||||
case "best before":
|
||||
return const Color(0xFF000000);
|
||||
case "checkers":
|
||||
return const Color(0xFF00a6a3);
|
||||
case "clicks":
|
||||
return const Color(0xFF005baa);
|
||||
case "cotton:on":
|
||||
return const Color(0xFFffffff);
|
||||
case "dis-chem":
|
||||
return const Color(0xFF00a950);
|
||||
case "pick n pay":
|
||||
return const Color(0xFFffffff);
|
||||
case "shoprite":
|
||||
return const Color(0xFFc12514);
|
||||
case "spar":
|
||||
return const Color(0xFFffffff);
|
||||
case "woolworths":
|
||||
return const Color(0xFF000000);
|
||||
case "makro":
|
||||
return const Color(0xFFffffff);
|
||||
case "fresh stop":
|
||||
return const Color(0xFF50b849);
|
||||
case "panarottis":
|
||||
return const Color(0xFF3c3c3b);
|
||||
case "shell":
|
||||
return const Color(0xFF1d232a);
|
||||
case "edgars":
|
||||
return const Color(0xFFffffff);
|
||||
case "jet":
|
||||
return const Color(0xFFffffff);
|
||||
case "spur":
|
||||
return const Color(0xFF0a0157);
|
||||
case "infinity":
|
||||
return const Color(0xFFffffff);
|
||||
case "eskom":
|
||||
return const Color(0xFF003897);
|
||||
case "+more":
|
||||
return const Color(0xFFffffff);
|
||||
case "bp":
|
||||
return const Color(0xFF9dc600);
|
||||
case "builders warehouse":
|
||||
return const Color(0xFFffcb26);
|
||||
case "exclusive books":
|
||||
return const Color(0xFF2abdc5);
|
||||
case "pna":
|
||||
return const Color(0xFFcf3339);
|
||||
case "pq clothing":
|
||||
return const Color(0xFFed2223);
|
||||
case "rage":
|
||||
return const Color(0xFFffffff);
|
||||
case "sasol":
|
||||
return const Color(0xFFffffff);
|
||||
case "tfg group":
|
||||
return const Color(0xFF622775);
|
||||
case "toys r us":
|
||||
return const Color(0xFF0962ad);
|
||||
case "leroy merlin":
|
||||
return const Color(0xFFffffff);
|
||||
case "signature cosmetics & fragrances":
|
||||
return const Color(0xFFec028b);
|
||||
case "ok foods":
|
||||
return const Color(0xFFffffff);
|
||||
case "choppies":
|
||||
return const Color(0xFFffffff);
|
||||
case "boxer":
|
||||
return const Color(0xFFffffff);
|
||||
case "carrefour":
|
||||
return const Color(0xFFffffff);
|
||||
case "sefalana":
|
||||
return const Color(0xFFffffff);
|
||||
case "big save":
|
||||
return const Color(0xFF333333);
|
||||
case "justrite":
|
||||
return const Color(0xFF50b849);
|
||||
case "naivas":
|
||||
return const Color(0xFFf26535);
|
||||
case "kero":
|
||||
return const Color(0xFF004986);
|
||||
case "auchan":
|
||||
return const Color(0xFFffffff);
|
||||
case "woermann brock":
|
||||
return const Color(0xFFe31e2d);
|
||||
case "continente":
|
||||
return const Color(0xFFffffff);
|
||||
case "fresmart":
|
||||
return const Color(0xFF72ba2e);
|
||||
case "total energies":
|
||||
return const Color(0xFFffffff);
|
||||
case "engen":
|
||||
return const Color(0xFF002b8f);
|
||||
default:
|
||||
return const Color(0xFFffffff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_providers/mzansi_wallet_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../mih_services/mih_alert_services.dart';
|
||||
|
||||
class MihCardEditWindow extends StatefulWidget {
|
||||
final MIHLoyaltyCard editCard;
|
||||
final int listIndex;
|
||||
const MihCardEditWindow({
|
||||
super.key,
|
||||
required this.editCard,
|
||||
required this.listIndex,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MihCardEditWindow> createState() => _MihCardEditWindowState();
|
||||
}
|
||||
|
||||
class _MihCardEditWindowState extends State<MihCardEditWindow> {
|
||||
final TextEditingController _nicknameController = TextEditingController();
|
||||
final TextEditingController _cardNumberController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
void openscanner() async {
|
||||
context.pushNamed(
|
||||
"barcodeScanner",
|
||||
extra: _cardNumberController,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nicknameController.text = widget.editCard.nickname;
|
||||
_cardNumberController.text = widget.editCard.card_number;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Size size = MediaQuery.sizeOf(context);
|
||||
return Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
|
||||
builder: (
|
||||
BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
Widget? child,
|
||||
) {
|
||||
return MihPackageWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: "Edit Loyalty Card",
|
||||
onWindowTapClose: () {
|
||||
_cardNumberController.clear();
|
||||
_nicknameController.clear();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
windowBody: Padding(
|
||||
padding:
|
||||
MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||
? EdgeInsets.symmetric(horizontal: size.width * 0.05)
|
||||
: EdgeInsets.symmetric(horizontal: size.width * 0),
|
||||
child: Column(
|
||||
children: [
|
||||
MihForm(
|
||||
formKey: _formKey,
|
||||
formFields: [
|
||||
MihTextFormField(
|
||||
fillColor: MihColors.secondary(),
|
||||
inputColor: MihColors.primary(),
|
||||
controller: _nicknameController,
|
||||
multiLineInput: false,
|
||||
requiredText: false,
|
||||
hintText: "Card Title",
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Flexible(
|
||||
child: MihTextFormField(
|
||||
fillColor: MihColors.secondary(),
|
||||
inputColor: MihColors.primary(),
|
||||
controller: _cardNumberController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
hintText: "Card Number",
|
||||
numberMode: true,
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
MihButton(
|
||||
onPressed: () {
|
||||
openscanner();
|
||||
},
|
||||
buttonColor: MihColors.secondary(),
|
||||
width: 100,
|
||||
child: Text(
|
||||
"Scan",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
walletProvider.updateLocalLoyaltyCard(
|
||||
mzansiProfileProvider,
|
||||
MIHLoyaltyCard(
|
||||
idloyalty_cards:
|
||||
widget.editCard.idloyalty_cards,
|
||||
app_id: widget.editCard.app_id,
|
||||
shop_name: widget.editCard.shop_name,
|
||||
card_number: _cardNumberController.text,
|
||||
favourite: widget.editCard.favourite,
|
||||
priority_index: widget.editCard.priority_index,
|
||||
nickname: _nicknameController.text,
|
||||
),
|
||||
);
|
||||
context.pop();
|
||||
context.pop();
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully updated the loyalty card details.",
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Update",
|
||||
style: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue