forked from yaso_meth/mih-project
BUG: Add card refresh list
This commit is contained in:
@@ -33,11 +33,6 @@ class MzansiWalletProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addLoyaltyCard({required MIHLoyaltyCard newCard}) {
|
||||
loyaltyCards.add(newCard);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void deleteLoyaltyCard({required int cardId}) {
|
||||
loyaltyCards.removeWhere((card) => card.idloyalty_cards == cardId);
|
||||
notifyListeners();
|
||||
|
||||
@@ -58,8 +58,12 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
);
|
||||
}
|
||||
|
||||
void editCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
BuildContext ctxt, int index, double width) {
|
||||
void editCardWindow(
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
BuildContext ctxt,
|
||||
int index,
|
||||
double width) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -144,6 +148,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
int statusCode = await MIHMzansiWalletApis
|
||||
.updateLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
@@ -211,7 +216,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
}
|
||||
|
||||
void deleteCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
BuildContext ctxt, int index) {
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -221,6 +226,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
onTap: () async {
|
||||
int statusCode =
|
||||
await MIHMzansiWalletApis.deleteLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
context,
|
||||
@@ -238,7 +244,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
}
|
||||
|
||||
void addToFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
BuildContext ctxt, int index) {
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -270,6 +276,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
onPressed: () async {
|
||||
int statusCode =
|
||||
await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
@@ -283,6 +290,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
context.pop();
|
||||
context.pop();
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
context,
|
||||
);
|
||||
@@ -323,7 +331,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
}
|
||||
|
||||
void removeFromFavCardWindow(MzansiProfileProvider mzansiProfileProvider,
|
||||
BuildContext ctxt, int index) {
|
||||
MzansiWalletProvider walletProvider, BuildContext ctxt, int index) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
@@ -355,6 +363,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
onPressed: () async {
|
||||
int statusCode =
|
||||
await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
@@ -368,6 +377,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
context.pop();
|
||||
context.pop();
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
context,
|
||||
);
|
||||
@@ -396,8 +406,8 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
);
|
||||
}
|
||||
|
||||
void viewCardWindow(
|
||||
MzansiProfileProvider mzansiProfileProvider, int index, double width) {
|
||||
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++) {
|
||||
@@ -441,12 +451,14 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
if (widget.cardList[index].favourite == "") {
|
||||
addToFavCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
);
|
||||
} else {
|
||||
removeFromFavCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
);
|
||||
@@ -476,6 +488,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
});
|
||||
editCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
width,
|
||||
@@ -501,6 +514,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
onTap: () {
|
||||
deleteCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
context,
|
||||
index,
|
||||
);
|
||||
@@ -705,9 +719,11 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
// final double width = size.width;
|
||||
//final double height = size.height;
|
||||
if (widget.cardList.isNotEmpty) {
|
||||
return Consumer<MzansiProfileProvider>(
|
||||
return Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
Widget? child) {
|
||||
return GridView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
@@ -732,6 +748,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
setScreenBrightness(1.0);
|
||||
viewCardWindow(
|
||||
mzansiProfileProvider,
|
||||
walletProvider,
|
||||
index,
|
||||
size.width,
|
||||
);
|
||||
|
||||
@@ -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_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_wallet_provider.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_services/mih_alert_services.dart';
|
||||
@@ -72,9 +73,6 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
context.goNamed(
|
||||
'mzansiWallet',
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
@@ -141,9 +139,11 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
padding: MzansiInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||
? EdgeInsets.symmetric(horizontal: width * 0.05)
|
||||
: EdgeInsets.symmetric(horizontal: width * 0),
|
||||
child: Consumer<MzansiProfileProvider>(
|
||||
child: Consumer2<MzansiProfileProvider, MzansiWalletProvider>(
|
||||
builder: (BuildContext context,
|
||||
MzansiProfileProvider mzansiProfileProvider, Widget? child) {
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
Widget? child) {
|
||||
return Column(
|
||||
children: [
|
||||
MihForm(
|
||||
@@ -158,9 +158,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
},
|
||||
requiredText: true,
|
||||
dropdownOptions: const [
|
||||
"+More",
|
||||
"Apple Tree",
|
||||
dropdownOptions: const <String>[
|
||||
"+More",
|
||||
"Apple Tree",
|
||||
"Auchan",
|
||||
@@ -206,7 +204,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
"Total Energies",
|
||||
"Toys R Us",
|
||||
"Woermann Brock",
|
||||
"Woolworths"
|
||||
"Woolworths",
|
||||
],
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
@@ -306,6 +304,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
} else {
|
||||
int statusCode = await MIHMzansiWalletApis
|
||||
.addLoyaltyCardAPICall(
|
||||
walletProvider,
|
||||
mzansiProfileProvider.user!,
|
||||
mzansiProfileProvider.user!.app_id,
|
||||
_shopController.text,
|
||||
@@ -317,7 +316,7 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
);
|
||||
if (statusCode == 201) {
|
||||
context.pop();
|
||||
KenLogger.error("Card Added Successfully");
|
||||
KenLogger.success("Card Added Successfully");
|
||||
successPopUp(
|
||||
"Successfully Added Card",
|
||||
"The loyalty card has been added to your favourites.",
|
||||
|
||||
@@ -25,24 +25,31 @@ class _MihWalletState extends State<MihWallet> {
|
||||
bool isLoading = true;
|
||||
|
||||
Future<void> setLoyaltyCards(
|
||||
MzansiProfileProvider mzansiProfileProvider) async {
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
) async {
|
||||
await MIHMzansiWalletApis.getLoyaltyCards(
|
||||
mzansiProfileProvider.user!.app_id, context);
|
||||
walletProvider, mzansiProfileProvider.user!.app_id, context);
|
||||
}
|
||||
|
||||
Future<void> setFavouritesCards(
|
||||
MzansiProfileProvider mzansiProfileProvider) async {
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
) async {
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
mzansiProfileProvider.user!.app_id, context);
|
||||
walletProvider, mzansiProfileProvider.user!.app_id, context);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
var mzansiProfileProvider = context.read<MzansiProfileProvider>();
|
||||
await setLoyaltyCards(mzansiProfileProvider);
|
||||
await setFavouritesCards(mzansiProfileProvider);
|
||||
MzansiProfileProvider mzansiProfileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
MzansiWalletProvider walletProvider =
|
||||
context.read<MzansiWalletProvider>();
|
||||
await setLoyaltyCards(mzansiProfileProvider, walletProvider);
|
||||
await setFavouritesCards(mzansiProfileProvider, walletProvider);
|
||||
context.read<MihBannerAdProvider>().loadBannerAd();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
|
||||
@@ -29,19 +29,18 @@ class MihCards extends StatefulWidget {
|
||||
class _MihCardsState extends State<MihCards> {
|
||||
final TextEditingController cardSearchController = TextEditingController();
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
List<MIHLoyaltyCard> listOfCards = [];
|
||||
final ValueNotifier<List<MIHLoyaltyCard>> searchShopName = ValueNotifier([]);
|
||||
final MobileScannerController scannerController = MobileScannerController(
|
||||
detectionSpeed: DetectionSpeed.unrestricted,
|
||||
);
|
||||
final boxFit = BoxFit.contain;
|
||||
|
||||
void searchShop() {
|
||||
void searchShop(List<MIHLoyaltyCard> allCards) {
|
||||
if (cardSearchController.text.isEmpty) {
|
||||
searchShopName.value = listOfCards;
|
||||
searchShopName.value = allCards;
|
||||
} else {
|
||||
List<MIHLoyaltyCard> temp = [];
|
||||
for (var item in listOfCards) {
|
||||
for (var item in allCards) {
|
||||
if (item.shop_name
|
||||
.toLowerCase()
|
||||
.contains(cardSearchController.text.toLowerCase()) ||
|
||||
@@ -130,24 +129,23 @@ class _MihCardsState extends State<MihCards> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
cardSearchController.removeListener(searchShop);
|
||||
final walletProvider = context.read<MzansiWalletProvider>();
|
||||
cardSearchController.removeListener(() {
|
||||
searchShop(walletProvider.loyaltyCards);
|
||||
});
|
||||
cardSearchController.dispose();
|
||||
searchShopName.dispose();
|
||||
searchFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void getLoyaltyCards(BuildContext context) async {
|
||||
setState(() {
|
||||
listOfCards = context.read<MzansiWalletProvider>().loyaltyCards;
|
||||
});
|
||||
searchShop();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
getLoyaltyCards(context);
|
||||
cardSearchController.addListener(searchShop);
|
||||
final walletProvider = context.read<MzansiWalletProvider>();
|
||||
searchShopName.value = walletProvider.loyaltyCards;
|
||||
cardSearchController.addListener(() {
|
||||
searchShop(walletProvider.loyaltyCards);
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -162,76 +160,89 @@ class _MihCardsState extends State<MihCards> {
|
||||
}
|
||||
|
||||
Widget getBody(double width) {
|
||||
return Stack(
|
||||
children: [
|
||||
MihSingleChildScroll(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: MihSearchBar(
|
||||
controller: cardSearchController,
|
||||
hintText: "Search Cards",
|
||||
// prefixIcon: Icons.search,
|
||||
prefixIcon: Icons.search,
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
hintColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onPrefixIconTap: () {
|
||||
// print("Search Icon Pressed: ${cardSearchController.text}");
|
||||
},
|
||||
searchFocusNode: searchFocusNode,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Consumer<MzansiWalletProvider>(
|
||||
builder: (context, mzansiWalletProvider, child) {
|
||||
listOfCards = mzansiWalletProvider.loyaltyCards;
|
||||
return ValueListenableBuilder<List<MIHLoyaltyCard>>(
|
||||
valueListenable: searchShopName,
|
||||
builder: (context, filteredCards, child) {
|
||||
return BuildLoyaltyCardList(
|
||||
cardList: filteredCards, //listOfCards,
|
||||
navIndex: 0,
|
||||
favouritesMode: false,
|
||||
searchText: cardSearchController,
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 10,
|
||||
bottom: 10,
|
||||
child: MihFloatingMenu(
|
||||
animatedIcon: AnimatedIcons.menu_close,
|
||||
children: [
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
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(
|
||||
children: [
|
||||
MihSingleChildScroll(
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width / 20),
|
||||
child: MihSearchBar(
|
||||
controller: cardSearchController,
|
||||
hintText: "Search Cards",
|
||||
// prefixIcon: Icons.search,
|
||||
prefixIcon: Icons.search,
|
||||
fillColor: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
hintColor: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onPrefixIconTap: () {
|
||||
// print("Search Icon Pressed: ${cardSearchController.text}");
|
||||
},
|
||||
searchFocusNode: searchFocusNode,
|
||||
),
|
||||
),
|
||||
label: "Add Loyalty Card",
|
||||
labelBackgroundColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontWeight: FontWeight.bold,
|
||||
const SizedBox(height: 10),
|
||||
ValueListenableBuilder<List<MIHLoyaltyCard>>(
|
||||
valueListenable: searchShopName,
|
||||
builder: (context, filteredCards, child) {
|
||||
return BuildLoyaltyCardList(
|
||||
cardList: filteredCards, //listOfCards,
|
||||
navIndex: 0,
|
||||
favouritesMode: false,
|
||||
searchText: cardSearchController,
|
||||
);
|
||||
},
|
||||
),
|
||||
backgroundColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
onTap: () {
|
||||
addCardWindow(context, width);
|
||||
},
|
||||
)
|
||||
]),
|
||||
)
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 10,
|
||||
bottom: 10,
|
||||
child: MihFloatingMenu(
|
||||
animatedIcon: AnimatedIcons.menu_close,
|
||||
children: [
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
),
|
||||
label: "Add Loyalty Card",
|
||||
labelBackgroundColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
onTap: () {
|
||||
addCardWindow(context, width);
|
||||
},
|
||||
)
|
||||
]),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
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/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:flutter/material.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 '../mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import '../mih_components/mih_pop_up_messages/mih_success_message.dart';
|
||||
import '../mih_config/mih_env.dart';
|
||||
@@ -17,6 +16,7 @@ class MIHMzansiWalletApis {
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
static Future<void> getLoyaltyCards(
|
||||
MzansiWalletProvider walletProvider,
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
@@ -26,7 +26,7 @@ class MIHMzansiWalletApis {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from(
|
||||
l.map((model) => MIHLoyaltyCard.fromJson(model)));
|
||||
context.read<MzansiWalletProvider>().setLoyaltyCards(cards: myCards);
|
||||
walletProvider.setLoyaltyCards(cards: myCards);
|
||||
// return myCards;
|
||||
} else {
|
||||
throw Exception('failed to fatch loyalty cards');
|
||||
@@ -34,6 +34,7 @@ class MIHMzansiWalletApis {
|
||||
}
|
||||
|
||||
static Future<void> getFavouriteLoyaltyCards(
|
||||
MzansiWalletProvider walletProvider,
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
@@ -44,7 +45,7 @@ class MIHMzansiWalletApis {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from(
|
||||
l.map((model) => MIHLoyaltyCard.fromJson(model)));
|
||||
context.read<MzansiWalletProvider>().setFavouriteCards(cards: myCards);
|
||||
walletProvider.setFavouriteCards(cards: myCards);
|
||||
}
|
||||
// else {
|
||||
// throw Exception('failed to fatch loyalty cards');
|
||||
@@ -60,6 +61,7 @@ class MIHMzansiWalletApis {
|
||||
///
|
||||
/// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS)
|
||||
static Future<int> deleteLoyaltyCardAPICall(
|
||||
MzansiWalletProvider walletProvider,
|
||||
AppUser signedInUser,
|
||||
int idloyalty_cards,
|
||||
BuildContext context,
|
||||
@@ -77,9 +79,7 @@ class MIHMzansiWalletApis {
|
||||
//print(response.statusCode);
|
||||
context.pop();
|
||||
if (response.statusCode == 200) {
|
||||
context
|
||||
.read<MzansiWalletProvider>()
|
||||
.deleteLoyaltyCard(cardId: idloyalty_cards);
|
||||
walletProvider.deleteLoyaltyCard(cardId: idloyalty_cards);
|
||||
}
|
||||
return response.statusCode;
|
||||
// if (response.statusCode == 200) {
|
||||
@@ -111,6 +111,7 @@ class MIHMzansiWalletApis {
|
||||
///
|
||||
/// Returns VOID (TRIGGERS SUCCESS pop up)
|
||||
static Future<int> addLoyaltyCardAPICall(
|
||||
MzansiWalletProvider walletProvider,
|
||||
AppUser signedInUser,
|
||||
String app_id,
|
||||
String shop_name,
|
||||
@@ -137,6 +138,10 @@ class MIHMzansiWalletApis {
|
||||
}),
|
||||
);
|
||||
context.pop();
|
||||
KenLogger.success("Response: $response");
|
||||
if (response.statusCode == 201) {
|
||||
await getLoyaltyCards(walletProvider, app_id, context);
|
||||
}
|
||||
return response.statusCode;
|
||||
// if (response.statusCode == 201) {
|
||||
// // Navigator.pop(context);
|
||||
@@ -164,6 +169,7 @@ class MIHMzansiWalletApis {
|
||||
///
|
||||
/// Returns VOID (TRIGGERS NOTIGICATIOPN ON SUCCESS)
|
||||
static Future<int> updateLoyaltyCardAPICall(
|
||||
MzansiWalletProvider walletProvider,
|
||||
AppUser signedInUser,
|
||||
int idloyalty_cards,
|
||||
String shopName,
|
||||
@@ -190,17 +196,17 @@ class MIHMzansiWalletApis {
|
||||
);
|
||||
context.pop();
|
||||
if (response.statusCode == 200) {
|
||||
context.read<MzansiWalletProvider>().editLoyaltyCard(
|
||||
updatedCard: MIHLoyaltyCard(
|
||||
idloyalty_cards: idloyalty_cards,
|
||||
app_id: signedInUser.app_id,
|
||||
shop_name: shopName,
|
||||
card_number: card_number,
|
||||
favourite: favourite,
|
||||
priority_index: priority_index,
|
||||
nickname: nickname,
|
||||
),
|
||||
);
|
||||
walletProvider.editLoyaltyCard(
|
||||
updatedCard: MIHLoyaltyCard(
|
||||
idloyalty_cards: idloyalty_cards,
|
||||
app_id: signedInUser.app_id,
|
||||
shop_name: shopName,
|
||||
card_number: card_number,
|
||||
favourite: favourite,
|
||||
priority_index: priority_index,
|
||||
nickname: nickname,
|
||||
),
|
||||
);
|
||||
}
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user