Mzansi Wallet Display done
This commit is contained in:
parent
003c8b7c0d
commit
f588e9f715
11 changed files with 246 additions and 39 deletions
|
|
@ -20,50 +20,32 @@ class MihWallet extends StatefulWidget {
|
|||
|
||||
class _MihWalletState extends State<MihWallet> {
|
||||
bool _isLoadingInitialData = true;
|
||||
late final MihCards _cards;
|
||||
late final MihCardFavourites _cardFavourites;
|
||||
|
||||
Future<void> _loadInitialData() async {
|
||||
setState(() {
|
||||
_isLoadingInitialData = true;
|
||||
});
|
||||
MzansiProfileProvider mzansiProfileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
mzansiProfileProvider.loadCachedProfileState();
|
||||
MzansiWalletProvider walletProvider = context.read<MzansiWalletProvider>();
|
||||
walletProvider.loadCachedWallet();
|
||||
if (mzansiProfileProvider.user == null) {
|
||||
await MihDataHelperServices().loadUserDataWithBusinessesData(
|
||||
mzansiProfileProvider,
|
||||
);
|
||||
mzansiProfileProvider.syncWithMihServerData();
|
||||
}
|
||||
if (walletProvider.loyaltyCards.isEmpty) {
|
||||
walletProvider.syncWithMihServerData(mzansiProfileProvider);
|
||||
}
|
||||
await setLoyaltyCards(mzansiProfileProvider, walletProvider);
|
||||
await setFavouritesCards(mzansiProfileProvider, walletProvider);
|
||||
setState(() {
|
||||
_isLoadingInitialData = false;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> setLoyaltyCards(
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
) async {
|
||||
await MIHMzansiWalletApis.getLoyaltyCards(
|
||||
walletProvider, mzansiProfileProvider.user!.app_id, context);
|
||||
}
|
||||
|
||||
Future<void> setFavouritesCards(
|
||||
MzansiProfileProvider mzansiProfileProvider,
|
||||
MzansiWalletProvider walletProvider,
|
||||
) async {
|
||||
await MIHMzansiWalletApis.getFavouriteLoyaltyCards(
|
||||
walletProvider, mzansiProfileProvider.user!.app_id, context);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cards = MihCards();
|
||||
_cardFavourites = MihCardFavourites();
|
||||
_loadInitialData();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
_loadInitialData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -122,8 +104,8 @@ class _MihWalletState extends State<MihWallet> {
|
|||
|
||||
List<Widget> getToolBody() {
|
||||
return [
|
||||
_cards,
|
||||
_cardFavourites,
|
||||
MihCards(),
|
||||
MihCardFavourites(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
import 'package:mih_package_toolkit/mih_package_toolkit.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_add_card_window.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_objects/loyalty_card.dart';
|
||||
|
|
@ -161,6 +162,37 @@ class _MihCardsState extends State<MihCards> {
|
|||
onTap: () {
|
||||
addCardWindow(context, width);
|
||||
},
|
||||
),
|
||||
SpeedDialChild(
|
||||
child: Icon(
|
||||
Icons.cloud_sync_rounded,
|
||||
color: MihColors.primary(),
|
||||
),
|
||||
label: "Sync Wallet",
|
||||
labelBackgroundColor: MihColors.green(),
|
||||
labelStyle: TextStyle(
|
||||
color: MihColors.primary(),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
backgroundColor: MihColors.green(),
|
||||
onTap: () async {
|
||||
MzansiProfileProvider profileProvider =
|
||||
context.read<MzansiProfileProvider>();
|
||||
bool success = await walletProvider
|
||||
.syncWithMihServerData(profileProvider);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
MihSnackBar(
|
||||
child: Text(
|
||||
success
|
||||
? "Wallet Synced with MIH Server."
|
||||
: "MIH App operation in Offline Mode",
|
||||
),
|
||||
// backgroundColor: success ? null : MihColors.red(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
]),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue