Complete Offline Wallet Display & Edit
This commit is contained in:
parent
6ad1ea613c
commit
04f034971f
21 changed files with 973 additions and 507 deletions
|
|
@ -11,7 +11,6 @@ import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/components/mih_
|
|||
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_mzansi_wallet_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';
|
||||
|
|
@ -130,29 +129,27 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
|||
child: MihButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
int statusCode = await MIHMzansiWalletApis
|
||||
.updateLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
widget.cardList[index].favourite,
|
||||
widget.cardList[index].priority_index,
|
||||
_nicknameController.text,
|
||||
_cardNumberController.text,
|
||||
ctxt,
|
||||
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,
|
||||
);
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully updated the loyalty card details.",
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
|
|
@ -183,24 +180,17 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
|||
MihAlertServices().deleteConfirmationAlert(
|
||||
"This Card will be deleted permanently from your Mzansi Wallet. Are you certain you want to delete it?",
|
||||
() async {
|
||||
int statusCode = await MIHMzansiWalletApis.deleteLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
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,
|
||||
);
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully deleted the loyalty card from your Mzansi Wallet.",
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
context.pop();
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
},
|
||||
context,
|
||||
);
|
||||
|
|
@ -231,34 +221,26 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
|||
),
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
int statusCode = await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
"Yes",
|
||||
_noFavourites,
|
||||
widget.cardList[index].nickname,
|
||||
widget.cardList[index].card_number,
|
||||
ctxt,
|
||||
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,
|
||||
);
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
context,
|
||||
);
|
||||
context.read<MzansiWalletProvider>().setToolIndex(1);
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully added the loyalty card to your favourites.",
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
|
|
@ -284,34 +266,26 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
|||
[
|
||||
MihButton(
|
||||
onPressed: () async {
|
||||
int statusCode = await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
"",
|
||||
0,
|
||||
widget.cardList[index].nickname,
|
||||
widget.cardList[index].card_number,
|
||||
ctxt,
|
||||
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,
|
||||
);
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
context,
|
||||
);
|
||||
context.read<MzansiWalletProvider>().setToolIndex(0);
|
||||
MihAlertServices().successBasicAlert(
|
||||
"Success!",
|
||||
"You have successfully removed the loyalty card to your favourites.",
|
||||
context,
|
||||
);
|
||||
} else {
|
||||
MihAlertServices().internetConnectionAlert(context);
|
||||
}
|
||||
},
|
||||
buttonColor: MihColors.red(),
|
||||
width: 300,
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ 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_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_packages/mzansi_wallet/components/mih_card_display.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_wallet_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class MihAddCardWindow extends StatefulWidget {
|
||||
const MihAddCardWindow({
|
||||
|
|
@ -58,6 +59,38 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
|||
}
|
||||
}
|
||||
|
||||
void addLoyaltyCard(MzansiProfileProvider profileProvider,
|
||||
MzansiWalletProvider walletProvider) async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
if (_shopController.text == "") {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
} else {
|
||||
final String uniqueKey = const Uuid().v4();
|
||||
|
||||
MIHLoyaltyCard newCard = MIHLoyaltyCard(
|
||||
idloyalty_cards: 0,
|
||||
app_id: profileProvider.user!.app_id,
|
||||
shop_name: _shopController.text,
|
||||
card_number: _cardNumberController.text,
|
||||
favourite: "No",
|
||||
priority_index: 0,
|
||||
nickname: _nicknameController.text,
|
||||
offline_id: uniqueKey,
|
||||
);
|
||||
await walletProvider.addLocalLoyaltyCard(profileProvider, newCard);
|
||||
context.pop();
|
||||
KenLogger.success("Card Added Successfully");
|
||||
successPopUp(
|
||||
"Successfully Added Card",
|
||||
"The loyalty card has been added to your favourites.",
|
||||
0,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double width = MediaQuery.sizeOf(context).width;
|
||||
|
|
@ -224,38 +257,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
|||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
if (_shopController.text == "") {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
} else {
|
||||
int statusCode = await MIHMzansiWalletApis
|
||||
.addLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
_shopController.text,
|
||||
_cardNumberController.text,
|
||||
"",
|
||||
0,
|
||||
_nicknameController.text,
|
||||
context,
|
||||
);
|
||||
if (statusCode == 201) {
|
||||
context.pop();
|
||||
KenLogger.success("Card Added Successfully");
|
||||
successPopUp(
|
||||
"Successfully Added Card",
|
||||
"The loyalty card has been added to your favourites.",
|
||||
0,
|
||||
);
|
||||
} else {
|
||||
MihAlertServices()
|
||||
.internetConnectionAlert(context);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
MihAlertServices().inputErrorAlert(context);
|
||||
}
|
||||
addLoyaltyCard(mzansiProfileProvider, walletProvider);
|
||||
},
|
||||
buttonColor: MihColors.green(),
|
||||
width: 300,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ class _MihWalletState extends State<MihWallet> {
|
|||
if (mzansiProfileProvider.user == null) {
|
||||
mzansiProfileProvider.syncWithMihServerData();
|
||||
}
|
||||
if (walletProvider.loyaltyCards.isEmpty) {
|
||||
if (walletProvider.loyaltyCards.isEmpty ||
|
||||
walletProvider.isLocalModificationsPending()) {
|
||||
walletProvider.syncWithMihServerData(mzansiProfileProvider);
|
||||
}
|
||||
setState(() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue