NEW: Mzansi Wallet Provider Setup
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/loyalty_card.dart';
|
||||
|
||||
class MzansiWalletProvider extends ChangeNotifier {
|
||||
List<MIHLoyaltyCard> loyaltyCards;
|
||||
List<MIHLoyaltyCard> favouriteCards;
|
||||
int toolIndex;
|
||||
|
||||
MzansiWalletProvider({
|
||||
this.loyaltyCards = const [],
|
||||
this.favouriteCards = const [],
|
||||
this.toolIndex = 0,
|
||||
});
|
||||
|
||||
void setToolIndex(int index) {
|
||||
toolIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setLoyaltyCards({required List<MIHLoyaltyCard> cards}) async {
|
||||
loyaltyCards = cards;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setFavouriteCards({required List<MIHLoyaltyCard> cards}) async {
|
||||
favouriteCards = cards;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addLoyaltyCard({required MIHLoyaltyCard newCard}) {
|
||||
loyaltyCards.add(newCard);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void deleteLoyaltyCard({required int cardId}) {
|
||||
loyaltyCards.removeWhere((card) => card.idloyalty_cards == cardId);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void editLoyaltyCard({required MIHLoyaltyCard updatedCard}) {
|
||||
int index = loyaltyCards.indexWhere(
|
||||
(card) => card.idloyalty_cards == updatedCard.idloyalty_cards);
|
||||
if (index != -1) {
|
||||
loyaltyCards[index] = updatedCard;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Frontend/lib/mih_packages/mine_sweeper/mih_mine_sweeper.dart
Normal file
15
Frontend/lib/mih_packages/mine_sweeper/mih_mine_sweeper.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MihMineSweeper extends StatefulWidget {
|
||||
const MihMineSweeper({super.key});
|
||||
|
||||
@override
|
||||
State<MihMineSweeper> createState() => _MihMineSweeperState();
|
||||
}
|
||||
|
||||
class _MihMineSweeperState extends State<MihMineSweeper> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ 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:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_banner_ad.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.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_wallet_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_wallet_services.dart';
|
||||
@@ -22,6 +22,7 @@ import 'package:mzansi_innovation_hub/mih_components/mih_objects/loyalty_card.da
|
||||
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';
|
||||
|
||||
class BuildLoyaltyCardList extends StatefulWidget {
|
||||
@@ -149,6 +150,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
.updateLoyaltyCardAPICall(
|
||||
widget.signedInUser,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
widget.cardList[index].favourite,
|
||||
widget.cardList[index].priority_index,
|
||||
_nicknameController.text,
|
||||
@@ -158,13 +160,28 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.goNamed(
|
||||
"mzansiWallet",
|
||||
extra: WalletArguments(
|
||||
widget.signedInUser,
|
||||
0,
|
||||
),
|
||||
);
|
||||
// context
|
||||
// .read<MzansiWalletProvider>()
|
||||
// .editLoyaltyCard(
|
||||
// updatedCard: MIHLoyaltyCard(
|
||||
// idloyalty_cards:
|
||||
// widget.cardList[index].idloyalty_cards,
|
||||
// app_id: widget.signedInUser.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.goNamed(
|
||||
// "mzansiWallet",
|
||||
// extra: WalletArguments(
|
||||
// widget.signedInUser,
|
||||
// 0,
|
||||
// ),
|
||||
// );
|
||||
} else {
|
||||
internetConnectionPopUp();
|
||||
}
|
||||
@@ -212,9 +229,6 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
context,
|
||||
);
|
||||
if (statusCode == 200) {
|
||||
setState(() {
|
||||
widget.cardList.removeAt(index);
|
||||
});
|
||||
context.pop();
|
||||
context.pop();
|
||||
} else {
|
||||
@@ -260,6 +274,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
|
||||
widget.signedInUser,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
"Yes",
|
||||
_noFavourites,
|
||||
widget.cardList[index].nickname,
|
||||
@@ -269,13 +284,9 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.goNamed(
|
||||
"mzansiWallet",
|
||||
extra: WalletArguments(
|
||||
widget.signedInUser,
|
||||
1,
|
||||
),
|
||||
);
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
widget.signedInUser.app_id, context);
|
||||
context.read<MzansiWalletProvider>().setToolIndex(1);
|
||||
} else {
|
||||
internetConnectionPopUp();
|
||||
}
|
||||
@@ -345,6 +356,7 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
await MIHMzansiWalletApis.updateLoyaltyCardAPICall(
|
||||
widget.signedInUser,
|
||||
widget.cardList[index].idloyalty_cards,
|
||||
widget.cardList[index].shop_name,
|
||||
"",
|
||||
0,
|
||||
widget.cardList[index].nickname,
|
||||
@@ -354,13 +366,9 @@ class _BuildLoyaltyCardListState extends State<BuildLoyaltyCardList> {
|
||||
if (statusCode == 200) {
|
||||
context.pop();
|
||||
context.pop();
|
||||
context.goNamed(
|
||||
"mzansiWallet",
|
||||
extra: WalletArguments(
|
||||
widget.signedInUser,
|
||||
0,
|
||||
),
|
||||
);
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
widget.signedInUser.app_id, context);
|
||||
context.read<MzansiWalletProvider>().setToolIndex(0);
|
||||
} else {
|
||||
internetConnectionPopUp();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
// ignore_for_file: must_be_immutable
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/loyalty_card.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_dropdwn_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart';
|
||||
@@ -22,12 +19,10 @@ import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart'
|
||||
|
||||
class MihAddCardWindow extends StatefulWidget {
|
||||
final AppUser signedInUser;
|
||||
Future<List<MIHLoyaltyCard>> cardList;
|
||||
|
||||
MihAddCardWindow({
|
||||
const MihAddCardWindow({
|
||||
super.key,
|
||||
required this.signedInUser,
|
||||
required this.cardList,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -133,8 +128,6 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
}
|
||||
}
|
||||
|
||||
// ... rest of your existing methods
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double width = MediaQuery.sizeOf(context).width;
|
||||
@@ -320,11 +313,6 @@ class _MihAddCardWindowState extends State<MihAddCardWindow> {
|
||||
context,
|
||||
);
|
||||
if (statusCode == 201) {
|
||||
setState(() {
|
||||
widget.cardList =
|
||||
MIHMzansiWalletApis.getLoyaltyCards(
|
||||
widget.signedInUser.app_id);
|
||||
});
|
||||
context.pop();
|
||||
KenLogger.error("Card Added Successfully");
|
||||
successPopUp(
|
||||
|
||||
@@ -3,17 +3,19 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_wallet_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/package_tools/mih_card_favourites.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/mzansi_wallet/package_tools/mih_cards.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_wallet_services.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihWallet extends StatefulWidget {
|
||||
final WalletArguments arguments;
|
||||
// final AppUser signedInUser;
|
||||
const MihWallet({
|
||||
super.key,
|
||||
required this.arguments,
|
||||
// required this.signedInUser,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -21,13 +23,34 @@ class MihWallet extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MihWalletState extends State<MihWallet> {
|
||||
late int _selcetedIndex;
|
||||
bool isLoading = true;
|
||||
|
||||
void setPackageIndex() {
|
||||
if (widget.arguments.index >= 0 && widget.arguments.index <= 3) {
|
||||
context.read<MzansiWalletProvider>().setToolIndex(widget.arguments.index);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setLoyaltyCards() async {
|
||||
await MIHMzansiWalletApis.getLoyaltyCards(
|
||||
widget.arguments.signedInUser.app_id, context);
|
||||
}
|
||||
|
||||
Future<void> setFavouritesCards() async {
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
widget.arguments.signedInUser.app_id, context);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
_selcetedIndex = widget.arguments.index;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
setPackageIndex();
|
||||
await setLoyaltyCards();
|
||||
await setFavouritesCards();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,12 +61,13 @@ class _MihWalletState extends State<MihWallet> {
|
||||
appTools: getTools(),
|
||||
appBody: getToolBody(),
|
||||
appToolTitles: getToolTitle(),
|
||||
selectedbodyIndex: _selcetedIndex,
|
||||
onIndexChange: (newValue) {
|
||||
setState(() {
|
||||
_selcetedIndex = newValue;
|
||||
});
|
||||
print("Index: $_selcetedIndex");
|
||||
selectedbodyIndex: context.watch<MzansiWalletProvider>().toolIndex,
|
||||
onIndexChange: (newIndex) {
|
||||
context.read<MzansiWalletProvider>().setToolIndex(newIndex);
|
||||
// setState(() {
|
||||
// _selcetedIndex = newValue;
|
||||
// });
|
||||
// print("Index: $_selcetedIndex");
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -65,19 +89,15 @@ class _MihWalletState extends State<MihWallet> {
|
||||
MihPackageTools getTools() {
|
||||
Map<Widget, void Function()?> temp = {};
|
||||
temp[const Icon(Icons.card_membership)] = () {
|
||||
setState(() {
|
||||
_selcetedIndex = 0;
|
||||
});
|
||||
context.read<MzansiWalletProvider>().setToolIndex(0);
|
||||
};
|
||||
temp[const Icon(Icons.favorite)] = () {
|
||||
setState(() {
|
||||
_selcetedIndex = 1;
|
||||
});
|
||||
context.read<MzansiWalletProvider>().setToolIndex(1);
|
||||
};
|
||||
|
||||
return MihPackageTools(
|
||||
tools: temp,
|
||||
selcetedIndex: _selcetedIndex,
|
||||
selcetedIndex: context.watch<MzansiWalletProvider>().toolIndex,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -90,6 +110,13 @@ class _MihWalletState extends State<MihWallet> {
|
||||
signedInUser: widget.arguments.signedInUser,
|
||||
),
|
||||
];
|
||||
if (isLoading) {
|
||||
return [
|
||||
const Center(
|
||||
child: Mihloadingcircle(),
|
||||
)
|
||||
];
|
||||
}
|
||||
return toolBodies;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_banner_ad.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_wallet_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mzansi_wallet_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.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_packages/mzansi_wallet/builder/build_loyalty_card_list.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihCardFavourites extends StatefulWidget {
|
||||
final AppUser signedInUser;
|
||||
@@ -24,13 +24,17 @@ class _MihCardFavouritesState extends State<MihCardFavourites> {
|
||||
late MihBannerAd _bannerAd;
|
||||
List<MIHLoyaltyCard> listOfCards = [];
|
||||
|
||||
void getFavouriteLoyaltyCards(BuildContext context) async {
|
||||
setState(() {
|
||||
listOfCards = context.read<MzansiWalletProvider>().favouriteCards;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bannerAd = MihBannerAd();
|
||||
cardList = MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
widget.signedInUser.app_id,
|
||||
);
|
||||
getFavouriteLoyaltyCards(context);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -47,69 +51,23 @@ class _MihCardFavouritesState extends State<MihCardFavourites> {
|
||||
MihSingleChildScroll(
|
||||
child: Column(
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: cardList,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child: Mihloadingcircle(),
|
||||
);
|
||||
} else if (snapshot.connectionState == ConnectionState.done &&
|
||||
snapshot.hasData) {
|
||||
listOfCards = snapshot.data!;
|
||||
// searchShop();
|
||||
return BuildLoyaltyCardList(
|
||||
cardList: listOfCards,
|
||||
signedInUser: widget.signedInUser,
|
||||
navIndex: 0,
|
||||
bannerAd: _bannerAd,
|
||||
favouritesMode: true,
|
||||
searchText: TextEditingController(),
|
||||
onCardViewClose: () {
|
||||
setState(() {
|
||||
_bannerAd = MihBannerAd();
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: Text("Error Loading Loyalty Cards"),
|
||||
);
|
||||
}
|
||||
BuildLoyaltyCardList(
|
||||
cardList: listOfCards,
|
||||
signedInUser: widget.signedInUser,
|
||||
navIndex: 0,
|
||||
bannerAd: _bannerAd,
|
||||
favouritesMode: true,
|
||||
searchText: TextEditingController(),
|
||||
onCardViewClose: () {
|
||||
setState(() {
|
||||
_bannerAd = MihBannerAd();
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Positioned(
|
||||
// right: 0,
|
||||
// bottom: 0,
|
||||
// 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);
|
||||
// },
|
||||
// )
|
||||
// ]),
|
||||
// )
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,21 +3,21 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_banner_ad.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.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_add_card_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_wallet_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_single_child_scroll.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_floating_menu.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_search_bar.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_loading_circle.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_packages/mzansi_wallet/builder/build_loyalty_card_list.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class MihCards extends StatefulWidget {
|
||||
final AppUser signedInUser;
|
||||
@@ -33,7 +33,6 @@ class MihCards extends StatefulWidget {
|
||||
class _MihCardsState extends State<MihCards> {
|
||||
final TextEditingController cardSearchController = TextEditingController();
|
||||
final FocusNode searchFocusNode = FocusNode();
|
||||
late Future<List<MIHLoyaltyCard>> cardList;
|
||||
MihBannerAd _bannerAd = MihBannerAd();
|
||||
List<MIHLoyaltyCard> listOfCards = [];
|
||||
final ValueNotifier<List<MIHLoyaltyCard>> searchShopName = ValueNotifier([]);
|
||||
@@ -132,7 +131,6 @@ class _MihCardsState extends State<MihCards> {
|
||||
barrierDismissible: false,
|
||||
builder: (context) => MihAddCardWindow(
|
||||
signedInUser: widget.signedInUser,
|
||||
cardList: cardList,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -146,9 +144,16 @@ class _MihCardsState extends State<MihCards> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void getLoyaltyCards(BuildContext context) async {
|
||||
setState(() {
|
||||
listOfCards = context.read<MzansiWalletProvider>().loyaltyCards;
|
||||
});
|
||||
searchShop();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
cardList = MIHMzansiWalletApis.getLoyaltyCards(widget.signedInUser.app_id);
|
||||
getLoyaltyCards(context);
|
||||
cardSearchController.addListener(searchShop);
|
||||
super.initState();
|
||||
}
|
||||
@@ -187,23 +192,14 @@ class _MihCardsState extends State<MihCards> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FutureBuilder(
|
||||
future: cardList,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child: Mihloadingcircle(),
|
||||
);
|
||||
} else if (snapshot.connectionState == ConnectionState.done &&
|
||||
snapshot.hasData) {
|
||||
listOfCards = snapshot.data!;
|
||||
searchShop();
|
||||
return ValueListenableBuilder(
|
||||
Consumer<MzansiWalletProvider>(
|
||||
builder: (context, mzansiWalletProvider, child) {
|
||||
listOfCards = mzansiWalletProvider.loyaltyCards;
|
||||
return ValueListenableBuilder<List<MIHLoyaltyCard>>(
|
||||
valueListenable: searchShopName,
|
||||
builder: (BuildContext context,
|
||||
List<MIHLoyaltyCard> value, Widget? child) {
|
||||
builder: (context, filteredCards, child) {
|
||||
return BuildLoyaltyCardList(
|
||||
cardList: value,
|
||||
cardList: filteredCards, //listOfCards,
|
||||
signedInUser: widget.signedInUser,
|
||||
navIndex: 0,
|
||||
bannerAd: _bannerAd,
|
||||
@@ -216,13 +212,7 @@ class _MihCardsState extends State<MihCards> {
|
||||
// Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: Text("Error Loading Loyalty Cards"),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@@ -5,6 +5,8 @@ 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';
|
||||
@@ -14,45 +16,39 @@ import '../mih_config/mih_env.dart';
|
||||
class MIHMzansiWalletApis {
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
|
||||
/// This function is used to fetch a list of loyalty cards for a user.
|
||||
///
|
||||
/// Patameters: app_id .
|
||||
///
|
||||
/// Returns List<PatientQueue>.
|
||||
static Future<List<MIHLoyaltyCard>> getLoyaltyCards(
|
||||
static Future<void> getLoyaltyCards(
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/mzasni-wallet/loyalty-cards/$app_id"));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<MIHLoyaltyCard> patientQueue = List<MIHLoyaltyCard>.from(
|
||||
List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from(
|
||||
l.map((model) => MIHLoyaltyCard.fromJson(model)));
|
||||
return patientQueue;
|
||||
context.read<MzansiWalletProvider>().setLoyaltyCards(cards: myCards);
|
||||
// return myCards;
|
||||
} else {
|
||||
throw Exception('failed to fatch loyalty cards');
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is used to fetch a list of loyalty cards for a user.
|
||||
///
|
||||
/// Patameters: app_id .
|
||||
///
|
||||
/// Returns List<PatientQueue>.
|
||||
static Future<List<MIHLoyaltyCard>> getFavouriteLoyaltyCards(
|
||||
static Future<void> getFavouriteLoyaltyCards(
|
||||
String app_id,
|
||||
BuildContext context,
|
||||
) async {
|
||||
//print("Patien manager page: $endpoint");
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/mzasni-wallet/loyalty-cards/favourites/$app_id"));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<MIHLoyaltyCard> patientQueue = List<MIHLoyaltyCard>.from(
|
||||
List<MIHLoyaltyCard> myCards = List<MIHLoyaltyCard>.from(
|
||||
l.map((model) => MIHLoyaltyCard.fromJson(model)));
|
||||
return patientQueue;
|
||||
} else {
|
||||
throw Exception('failed to fatch loyalty cards');
|
||||
context.read<MzansiWalletProvider>().setFavouriteCards(cards: myCards);
|
||||
}
|
||||
// else {
|
||||
// throw Exception('failed to fatch loyalty cards');
|
||||
// }
|
||||
}
|
||||
|
||||
/// This function is used to Delete loyalty card from users mzansi wallet.
|
||||
@@ -80,6 +76,11 @@ class MIHMzansiWalletApis {
|
||||
//print("Here4");
|
||||
//print(response.statusCode);
|
||||
context.pop();
|
||||
if (response.statusCode == 200) {
|
||||
context
|
||||
.read<MzansiWalletProvider>()
|
||||
.deleteLoyaltyCard(cardId: idloyalty_cards);
|
||||
}
|
||||
return response.statusCode;
|
||||
// if (response.statusCode == 200) {
|
||||
// Navigator.of(context).pop();
|
||||
@@ -165,6 +166,7 @@ class MIHMzansiWalletApis {
|
||||
static Future<int> updateLoyaltyCardAPICall(
|
||||
AppUser signedInUser,
|
||||
int idloyalty_cards,
|
||||
String shopName,
|
||||
String favourite,
|
||||
int priority_index,
|
||||
String nickname,
|
||||
@@ -187,6 +189,19 @@ 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
return response.statusCode;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user