BUG: Add card refresh list

This commit is contained in:
2025-11-03 10:18:29 +02:00
parent bcff545dd7
commit 52f9eb7ba6
7 changed files with 166 additions and 131 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -33,11 +33,6 @@ class MzansiWalletProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
void addLoyaltyCard({required MIHLoyaltyCard newCard}) {
loyaltyCards.add(newCard);
notifyListeners();
}
void deleteLoyaltyCard({required int cardId}) { void deleteLoyaltyCard({required int cardId}) {
loyaltyCards.removeWhere((card) => card.idloyalty_cards == cardId); loyaltyCards.removeWhere((card) => card.idloyalty_cards == cardId);
notifyListeners(); notifyListeners();

View File

@@ -58,8 +58,12 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
); );
} }
void editCardWindow(MzansiProfileProvider mzansiProfileProvider, void editCardWindow(
BuildContext ctxt, int index, double width) { MzansiProfileProvider mzansiProfileProvider,
MzansiWalletProvider walletProvider,
BuildContext ctxt,
int index,
double width) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@@ -144,6 +148,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
if (_formKey.currentState!.validate()) { if (_formKey.currentState!.validate()) {
int statusCode = await MIHMzansiWalletApis int statusCode = await MIHMzansiWalletApis
.updateLoyaltyCardAPICall( .updateLoyaltyCardAPICall(
walletProvider,
mzansiProfileProvider.user!, mzansiProfileProvider.user!,
widget.cardList[index].idloyalty_cards, widget.cardList[index].idloyalty_cards,
widget.cardList[index].shop_name, widget.cardList[index].shop_name,
@@ -211,7 +216,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
} }
void deleteCardWindow(MzansiProfileProvider mzansiProfileProvider, void deleteCardWindow(MzansiProfileProvider mzansiProfileProvider,
BuildContext ctxt, int index) { MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@@ -221,6 +226,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
onTap: () async { onTap: () async {
int statusCode = int statusCode =
await MIHMzansiWalletApis.deleteLoyaltyCardAPICall( await MIHMzansiWalletApis.deleteLoyaltyCardAPICall(
walletProvider,
mzansiProfileProvider.user!, mzansiProfileProvider.user!,
widget.cardList[index].idloyalty_cards, widget.cardList[index].idloyalty_cards,
context, context,
@@ -238,7 +244,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
} }
void addToFavCardWindow(MzansiProfileProvider mzansiProfileProvider, void addToFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
BuildContext ctxt, int index) { MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@@ -270,6 +276,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
onPressed: () async { onPressed: () async {
int statusCode = int statusCode =
await MIHMzansiWalletApis.updateLoyaltyCardAPICall( await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
walletProvider,
mzansiProfileProvider.user!, mzansiProfileProvider.user!,
widget.cardList[index].idloyalty_cards, widget.cardList[index].idloyalty_cards,
widget.cardList[index].shop_name, widget.cardList[index].shop_name,
@@ -283,6 +290,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
context.pop(); context.pop();
context.pop(); context.pop();
await MIHMzansiWalletApis.getFavouriteLoyaltyCards( await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
walletProvider,
mzansiProfileProvider.user!.app_id, mzansiProfileProvider.user!.app_id,
context, context,
); );
@@ -323,7 +331,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
} }
void removeFromFavCardWindow(MzansiProfileProvider mzansiProfileProvider, void removeFromFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
BuildContext ctxt, int index) { MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@@ -355,6 +363,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
onPressed: () async { onPressed: () async {
int statusCode = int statusCode =
await MIHMzansiWalletApis.updateLoyaltyCardAPICall( await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
walletProvider,
mzansiProfileProvider.user!, mzansiProfileProvider.user!,
widget.cardList[index].idloyalty_cards, widget.cardList[index].idloyalty_cards,
widget.cardList[index].shop_name, widget.cardList[index].shop_name,
@@ -368,6 +377,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
context.pop(); context.pop();
context.pop(); context.pop();
await MIHMzansiWalletApis.getFavouriteLoyaltyCards( await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
walletProvider,
mzansiProfileProvider.user!.app_id, mzansiProfileProvider.user!.app_id,
context, context,
); );
@@ -396,8 +406,8 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
); );
} }
void viewCardWindow( void viewCardWindow(MzansiProfileProvider mzansiProfileProvider,
MzansiProfileProvider mzansiProfileProvider, int index, double width) { MzansiWalletProvider walletProvider, int index, double width) {
//print(widget.cardList[index].card_number); //print(widget.cardList[index].card_number);
String formattedCardNumber = ""; String formattedCardNumber = "";
for (int i = 0; i <= widget.cardList[index].card_number.length - 1; i++) { for (int i = 0; i <= widget.cardList[index].card_number.length - 1; i++) {
@@ -441,12 +451,14 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
if (widget.cardList[index].favourite == "") { if (widget.cardList[index].favourite == "") {
addToFavCardWindow( addToFavCardWindow(
mzansiProfileProvider, mzansiProfileProvider,
walletProvider,
context, context,
index, index,
); );
} else { } else {
removeFromFavCardWindow( removeFromFavCardWindow(
mzansiProfileProvider, mzansiProfileProvider,
walletProvider,
context, context,
index, index,
); );
@@ -476,6 +488,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
}); });
editCardWindow( editCardWindow(
mzansiProfileProvider, mzansiProfileProvider,
walletProvider,
context, context,
index, index,
width, width,
@@ -501,6 +514,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
onTap: () { onTap: () {
deleteCardWindow( deleteCardWindow(
mzansiProfileProvider, mzansiProfileProvider,
walletProvider,
context, context,
index, index,
); );
@@ -705,9 +719,11 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
// final double width = size.width; // final double width = size.width;
//final double height = size.height; //final double height = size.height;
if (widget.cardList.isNotEmpty) { if (widget.cardList.isNotEmpty) {
return Consumer<MzansiProfileProvider>( return Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
builder: (BuildContext context, builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) { MzansiProfileProvider mzansiProfileProvider,
MzansiWalletProvider walletProvider,
Widget? child) {
return GridView.builder( return GridView.builder(
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true, shrinkWrap: true,
@@ -732,6 +748,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
setScreenBrightness(1.0); setScreenBrightness(1.0);
viewCardWindow( viewCardWindow(
mzansiProfileProvider, mzansiProfileProvider,
walletProvider,
index, index,
size.width, size.width,
); );

View File

@@ -10,6 +10,7 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_wallet_provider.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart'; import 'package:mzansi_innovation_hub/mih_config/mih_colors.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_display.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart'; import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
@@ -72,9 +73,6 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
child: MihButton( child: MihButton(
onPressed: () { onPressed: () {
context.pop(); context.pop();
context.goNamed(
'mzansiWallet',
);
}, },
buttonColor: MihColors.getGreenColor( buttonColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
@@ -141,9 +139,11 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
padding: MzansiInnovationHub.of(context)!.theme.screenType == "desktop" padding: MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
? EdgeInsets.symmetric(horizontal: width * 0.05) ? EdgeInsets.symmetric(horizontal: width * 0.05)
: EdgeInsets.symmetric(horizontal: width * 0), : EdgeInsets.symmetric(horizontal: width * 0),
child: Consumer<MzansiProfileProvider>( child: Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
builder: (BuildContext context, builder: (BuildContext context,
MzansiProfileProvider mzansiProfileProvider, Widget? child) { MzansiProfileProvider mzansiProfileProvider,
MzansiWalletProvider walletProvider,
Widget? child) {
return Column( return Column(
children: [ children: [
MihForm( MihForm(
@@ -158,9 +158,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
return MihValidationServices().isEmpty(value); return MihValidationServices().isEmpty(value);
}, },
requiredText: true, requiredText: true,
dropdownOptions: const [ dropdownOptions: const <String>[
"+More",
"Apple Tree",
"+More", "+More",
"Apple Tree", "Apple Tree",
"Auchan", "Auchan",
@@ -206,7 +204,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
"Total Energies", "Total Energies",
"Toys R Us", "Toys R Us",
"Woermann Brock", "Woermann Brock",
"Woolworths" "Woolworths",
], ],
), ),
ValueListenableBuilder( ValueListenableBuilder(
@@ -306,6 +304,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
} else { } else {
int statusCode = await MIHMzansiWalletApis int statusCode = await MIHMzansiWalletApis
.addLoyaltyCardAPICall( .addLoyaltyCardAPICall(
walletProvider,
mzansiProfileProvider.user!, mzansiProfileProvider.user!,
mzansiProfileProvider.user!.app_id, mzansiProfileProvider.user!.app_id,
_shopController.text, _shopController.text,
@@ -317,7 +316,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
); );
if (statusCode == 201) { if (statusCode == 201) {
context.pop(); context.pop();
KenLogger.error("Card Added Successfully"); KenLogger.success("Card Added Successfully");
successPopUp( successPopUp(
"Successfully Added Card", "Successfully Added Card",
"The loyalty card has been added to your favourites.", "The loyalty card has been added to your favourites.",

View File

@@ -25,24 +25,31 @@ class _MihWalletState extends State<MihWallet> {
bool isLoading = true; bool isLoading = true;
Future<void> setLoyaltyCards( Future<void> setLoyaltyCards(
MzansiProfileProvider mzansiProfileProvider) async { MzansiProfileProvider mzansiProfileProvider,
MzansiWalletProvider walletProvider,
) async {
await MIHMzansiWalletApis.getLoyaltyCards( await MIHMzansiWalletApis.getLoyaltyCards(
mzansiProfileProvider.user!.app_id, context); walletProvider, mzansiProfileProvider.user!.app_id, context);
} }
Future<void> setFavouritesCards( Future<void> setFavouritesCards(
MzansiProfileProvider mzansiProfileProvider) async { MzansiProfileProvider mzansiProfileProvider,
MzansiWalletProvider walletProvider,
) async {
await MIHMzansiWalletApis.getFavouriteLoyaltyCards( await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
mzansiProfileProvider.user!.app_id, context); walletProvider, mzansiProfileProvider.user!.app_id, context);
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async { WidgetsBinding.instance.addPostFrameCallback((_) async {
var mzansiProfileProvider = context.read<MzansiProfileProvider>(); MzansiProfileProvider mzansiProfileProvider =
await setLoyaltyCards(mzansiProfileProvider); context.read<MzansiProfileProvider>();
await setFavouritesCards(mzansiProfileProvider); MzansiWalletProvider walletProvider =
context.read<MzansiWalletProvider>();
await setLoyaltyCards(mzansiProfileProvider, walletProvider);
await setFavouritesCards(mzansiProfileProvider, walletProvider);
context.read<MihBannerAdProvider>().loadBannerAd(); context.read<MihBannerAdProvider>().loadBannerAd();
setState(() { setState(() {
isLoading = false; isLoading = false;

View File

@@ -29,19 +29,18 @@ class MihCards extends StatefulWidget {
class _MihCardsState extends State<MihCards> { class _MihCardsState extends State<MihCards> {
final TextEditingController cardSearchController = TextEditingController(); final TextEditingController cardSearchController = TextEditingController();
final FocusNode searchFocusNode = FocusNode(); final FocusNode searchFocusNode = FocusNode();
List<MIHLoyaltyCard> listOfCards = [];
final ValueNotifier<List<MIHLoyaltyCard>> searchShopName = ValueNotifier([]); final ValueNotifier<List<MIHLoyaltyCard>> searchShopName = ValueNotifier([]);
final MobileScannerController scannerController = MobileScannerController( final MobileScannerController scannerController = MobileScannerController(
detectionSpeed: DetectionSpeed.unrestricted, detectionSpeed: DetectionSpeed.unrestricted,
); );
final boxFit = BoxFit.contain; final boxFit = BoxFit.contain;
void searchShop() { void searchShop(List<MIHLoyaltyCard> allCards) {
if (cardSearchController.text.isEmpty) { if (cardSearchController.text.isEmpty) {
searchShopName.value = listOfCards; searchShopName.value = allCards;
} else { } else {
List<MIHLoyaltyCard> temp = []; List<MIHLoyaltyCard> temp = [];
for (var item in listOfCards) { for (var item in allCards) {
if (item.shop_name if (item.shop_name
.toLowerCase() .toLowerCase()
.contains(cardSearchController.text.toLowerCase()) || .contains(cardSearchController.text.toLowerCase()) ||
@@ -130,24 +129,23 @@ class _MihCardsState extends State<MihCards> {
@override @override
void dispose() { void dispose() {
cardSearchController.removeListener(searchShop); final walletProvider = context.read<MzansiWalletProvider>();
cardSearchController.removeListener(() {
searchShop(walletProvider.loyaltyCards);
});
cardSearchController.dispose(); cardSearchController.dispose();
searchShopName.dispose(); searchShopName.dispose();
searchFocusNode.dispose(); searchFocusNode.dispose();
super.dispose(); super.dispose();
} }
void getLoyaltyCards(BuildContext context) async {
setState(() {
listOfCards = context.read<MzansiWalletProvider>().loyaltyCards;
});
searchShop();
}
@override @override
void initState() { void initState() {
getLoyaltyCards(context); final walletProvider = context.read<MzansiWalletProvider>();
cardSearchController.addListener(searchShop); searchShopName.value = walletProvider.loyaltyCards;
cardSearchController.addListener(() {
searchShop(walletProvider.loyaltyCards);
});
super.initState(); super.initState();
} }
@@ -162,6 +160,15 @@ class _MihCardsState extends State<MihCards> {
} }
Widget getBody(double width) { Widget getBody(double width) {
return Consumer<MzansiWalletProvider>(
builder: (BuildContext context, MzansiWalletProvider walletProvider,
Widget? child) {
if (cardSearchController.text.isEmpty) {
searchShopName.value = walletProvider.loyaltyCards;
} else {
// Re-run search with updated card list
searchShop(walletProvider.loyaltyCards);
}
return Stack( return Stack(
children: [ children: [
MihSingleChildScroll( MihSingleChildScroll(
@@ -175,9 +182,11 @@ class _MihCardsState extends State<MihCards> {
// prefixIcon: Icons.search, // prefixIcon: Icons.search,
prefixIcon: Icons.search, prefixIcon: Icons.search,
fillColor: MihColors.getSecondaryColor( fillColor: MihColors.getSecondaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
hintColor: MihColors.getPrimaryColor( hintColor: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onPrefixIconTap: () { onPrefixIconTap: () {
// print("Search Icon Pressed: ${cardSearchController.text}"); // print("Search Icon Pressed: ${cardSearchController.text}");
}, },
@@ -185,10 +194,7 @@ class _MihCardsState extends State<MihCards> {
), ),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
Consumer<MzansiWalletProvider>( ValueListenableBuilder<List<MIHLoyaltyCard>>(
builder: (context, mzansiWalletProvider, child) {
listOfCards = mzansiWalletProvider.loyaltyCards;
return ValueListenableBuilder<List<MIHLoyaltyCard>>(
valueListenable: searchShopName, valueListenable: searchShopName,
builder: (context, filteredCards, child) { builder: (context, filteredCards, child) {
return BuildLoyaltyCardList( return BuildLoyaltyCardList(
@@ -197,7 +203,6 @@ class _MihCardsState extends State<MihCards> {
favouritesMode: false, favouritesMode: false,
searchText: cardSearchController, searchText: cardSearchController,
); );
});
}, },
), ),
], ],
@@ -213,18 +218,22 @@ class _MihCardsState extends State<MihCards> {
child: Icon( child: Icon(
Icons.add, Icons.add,
color: MihColors.getPrimaryColor( color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
), ),
label: "Add Loyalty Card", label: "Add Loyalty Card",
labelBackgroundColor: MihColors.getGreenColor( labelBackgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
labelStyle: TextStyle( labelStyle: TextStyle(
color: MihColors.getPrimaryColor( color: MihColors.getPrimaryColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
backgroundColor: MihColors.getGreenColor( backgroundColor: MihColors.getGreenColor(
MzansiInnovationHub.of(context)!.theme.mode == "Dark"), MzansiInnovationHub.of(context)!.theme.mode ==
"Dark"),
onTap: () { onTap: () {
addCardWindow(context, width); addCardWindow(context, width);
}, },
@@ -233,5 +242,7 @@ class _MihCardsState extends State<MihCards> {
) )
], ],
); );
},
);
} }
} }

View File

@@ -1,14 +1,13 @@
import 'dart:convert'; import 'dart:convert';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_objects/loyalty_card.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_objects/loyalty_card.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_wallet_provider.dart'; import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_wallet_provider.dart';
import 'package:provider/provider.dart';
import 'package:supertokens_flutter/http.dart' as http; import 'package:supertokens_flutter/http.dart' as http;
import '../mih_components/mih_pop_up_messages/mih_error_message.dart'; import '../mih_components/mih_pop_up_messages/mih_error_message.dart';
import '../mih_components/mih_pop_up_messages/mih_success_message.dart'; import '../mih_components/mih_pop_up_messages/mih_success_message.dart';
import '../mih_config/mih_env.dart'; import '../mih_config/mih_env.dart';
@@ -17,6 +16,7 @@ class MIHMzansiWalletApis {
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
static Future<void> getLoyaltyCards( static Future<void> getLoyaltyCards(
MzansiWalletProvider walletProvider,
String app_id, String app_id,
BuildContext context, BuildContext context,
) async { ) async {
@@ -26,7 +26,7 @@ class MIHMzansiWalletApis {
Iterable l = jsonDecode(response.body); Iterable l = jsonDecode(response.body);
List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from( List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from(
l.map((model) => MIHLoyaltyCard.fromJson(model))); l.map((model) => MIHLoyaltyCard.fromJson(model)));
context.read<MzansiWalletProvider>().setLoyaltyCards(cards: myCards); walletProvider.setLoyaltyCards(cards: myCards);
// return myCards; // return myCards;
} else { } else {
throw Exception('failed to fatch loyalty cards'); throw Exception('failed to fatch loyalty cards');
@@ -34,6 +34,7 @@ class MIHMzansiWalletApis {
} }
static Future<void> getFavouriteLoyaltyCards( static Future<void> getFavouriteLoyaltyCards(
MzansiWalletProvider walletProvider,
String app_id, String app_id,
BuildContext context, BuildContext context,
) async { ) async {
@@ -44,7 +45,7 @@ class MIHMzansiWalletApis {
Iterable l = jsonDecode(response.body); Iterable l = jsonDecode(response.body);
List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from( List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from(
l.map((model) => MIHLoyaltyCard.fromJson(model))); l.map((model) => MIHLoyaltyCard.fromJson(model)));
context.read<MzansiWalletProvider>().setFavouriteCards(cards: myCards); walletProvider.setFavouriteCards(cards: myCards);
} }
// else { // else {
// throw Exception('failed to fatch loyalty cards'); // throw Exception('failed to fatch loyalty cards');
@@ -60,6 +61,7 @@ class MIHMzansiWalletApis {
/// ///
/// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS) /// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS)
static Future<int> deleteLoyaltyCardAPICall( static Future<int> deleteLoyaltyCardAPICall(
MzansiWalletProvider walletProvider,
AppUser signedInUser, AppUser signedInUser,
int idloyalty_cards, int idloyalty_cards,
BuildContext context, BuildContext context,
@@ -77,9 +79,7 @@ class MIHMzansiWalletApis {
//print(response.statusCode); //print(response.statusCode);
context.pop(); context.pop();
if (response.statusCode == 200) { if (response.statusCode == 200) {
context walletProvider.deleteLoyaltyCard(cardId: idloyalty_cards);
.read<MzansiWalletProvider>()
.deleteLoyaltyCard(cardId: idloyalty_cards);
} }
return response.statusCode; return response.statusCode;
// if (response.statusCode == 200) { // if (response.statusCode == 200) {
@@ -111,6 +111,7 @@ class MIHMzansiWalletApis {
/// ///
/// Returns VOID (TRIGGERS SUCCESS pop up) /// Returns VOID (TRIGGERS SUCCESS pop up)
static Future<int> addLoyaltyCardAPICall( static Future<int> addLoyaltyCardAPICall(
MzansiWalletProvider walletProvider,
AppUser signedInUser, AppUser signedInUser,
String app_id, String app_id,
String shop_name, String shop_name,
@@ -137,6 +138,10 @@ class MIHMzansiWalletApis {
}), }),
); );
context.pop(); context.pop();
KenLogger.success("Response: $response");
if (response.statusCode == 201) {
await getLoyaltyCards(walletProvider, app_id, context);
}
return response.statusCode; return response.statusCode;
// if (response.statusCode == 201) { // if (response.statusCode == 201) {
// // Navigator.pop(context); // // Navigator.pop(context);
@@ -164,6 +169,7 @@ class MIHMzansiWalletApis {
/// ///
/// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS) /// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS)
static Future<int> updateLoyaltyCardAPICall( static Future<int> updateLoyaltyCardAPICall(
MzansiWalletProvider walletProvider,
AppUser signedInUser, AppUser signedInUser,
int idloyalty_cards, int idloyalty_cards,
String shopName, String shopName,
@@ -190,7 +196,7 @@ class MIHMzansiWalletApis {
); );
context.pop(); context.pop();
if (response.statusCode == 200) { if (response.statusCode == 200) {
context.read<MzansiWalletProvider>().editLoyaltyCard( walletProvider.editLoyaltyCard(
updatedCard: MIHLoyaltyCard( updatedCard: MIHLoyaltyCard(
idloyalty_cards: idloyalty_cards, idloyalty_cards: idloyalty_cards,
app_id: signedInUser.app_id, app_id: signedInUser.app_id,