From 96c1604c55f0800a15cafb98183adbdbcbf4c268 Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Mon, 10 Mar 2025 13:05:57 +0200 Subject: [PATCH] fix overflow issue --- .../mzansi_wallet/app_tools/mih_cards.dart | 97 +++++++++++-------- .../builder/build_loyalty_card_list.dart | 71 ++++++++------ .../components/mih_card_display.dart | 95 ++++-------------- 3 files changed, 112 insertions(+), 151 deletions(-) diff --git a/Frontend/lib/mih_packages/mzansi_wallet/app_tools/mih_cards.dart b/Frontend/lib/mih_packages/mzansi_wallet/app_tools/mih_cards.dart index 6393efcc..c3a1c6be 100644 --- a/Frontend/lib/mih_packages/mzansi_wallet/app_tools/mih_cards.dart +++ b/Frontend/lib/mih_packages/mzansi_wallet/app_tools/mih_cards.dart @@ -226,25 +226,15 @@ class _MihCardsState extends State { Widget build(BuildContext context) { return MihAppToolBody( borderOn: true, - bodyItem: bodyItem(), + bodyItem: getBody(), ); } - Widget bodyItem() { - return FutureBuilder( - future: cardList, - builder: (context, snapshot) { - //print(snapshot.connectionState); - if (snapshot.connectionState == ConnectionState.waiting) { - return const Center( - child: Mihloadingcircle(), - ); - } else if (snapshot.connectionState == ConnectionState.done && - snapshot.hasData) { - listOfCards = snapshot.data!; - searchShop(); - //print(listOfCards); - return Column( + Widget getBody() { + return Stack( + children: [ + SingleChildScrollView( + child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.center, @@ -260,20 +250,8 @@ class _MihCardsState extends State { .secondaryColor(), ), ), - IconButton( - icon: const Icon(Icons.add_card), - alignment: Alignment.topRight, - color: - MzanziInnovationHub.of(context)!.theme.secondaryColor(), - onPressed: () { - addCardWindow(context); - }, - ) ], ), - // Divider( - // color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), - // ), const SizedBox(height: 10), Row( mainAxisAlignment: MainAxisAlignment.center, @@ -304,24 +282,57 @@ class _MihCardsState extends State { ], ), const SizedBox(height: 10), - ValueListenableBuilder( - valueListenable: searchShopName, - builder: (BuildContext context, List value, - Widget? child) { - return BuildLoyaltyCardList( - cardList: searchShopName.value, - signedInUser: widget.signedInUser, - ); + 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( + valueListenable: searchShopName, + builder: (BuildContext context, + List value, Widget? child) { + return BuildLoyaltyCardList( + cardList: searchShopName.value, + signedInUser: widget.signedInUser, + ); + }, + ); + } else { + return const Center( + child: Text("Error Loading Loyalty Cards"), + ); + } }, ), ], - ); - } else { - return const Center( - child: Text("Error Loading Loyalty Cards"), - ); - } - }, + ), + ), + Positioned( + right: 0, + bottom: 0, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(50), + color: MzanziInnovationHub.of(context)!.theme.secondaryColor(), + ), + child: IconButton( + color: MzanziInnovationHub.of(context)!.theme.primaryColor(), + onPressed: () { + addCardWindow(context); + }, + icon: const Icon( + Icons.add_card, + size: 50, + ), + ), + )) + ], ); } } diff --git a/Frontend/lib/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart b/Frontend/lib/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart index bf61f6b1..2834c78b 100644 --- a/Frontend/lib/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart +++ b/Frontend/lib/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart @@ -143,32 +143,35 @@ class _BuildLoyaltyCardListState extends State { // final double width = size.width; //final double height = size.height; if (widget.cardList.isNotEmpty) { - return GridView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - padding: EdgeInsets.only( - left: getHorizontalPaddingSize(size), - right: getHorizontalPaddingSize(size), - //bottom: height / 5, - //top: 20, + return SizedBox( + height: size.height, + child: GridView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + padding: EdgeInsets.only( + left: getHorizontalPaddingSize(size), + right: getHorizontalPaddingSize(size), + //bottom: height / 5, + //top: 20, + ), + // physics: , + // shrinkWrap: true, + itemCount: widget.cardList.length, + gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( + mainAxisSpacing: 0, + crossAxisSpacing: 10, + maxCrossAxisExtent: 200, + ), + itemBuilder: (context, index) { + return GestureDetector( + child: MihCardDisplay( + shopName: widget.cardList[index].shop_name, height: 100), + onTap: () { + viewCardWindow(index); + }, + ); + }, ), - // physics: , - // shrinkWrap: true, - itemCount: widget.cardList.length, - gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( - mainAxisSpacing: 0, - crossAxisSpacing: 10, - maxCrossAxisExtent: 175, - ), - itemBuilder: (context, index) { - return GestureDetector( - child: MihCardDisplay( - shopName: widget.cardList[index].shop_name, height: 100), - onTap: () { - viewCardWindow(index); - }, - ); - }, ); // return ListView.separated( // shrinkWrap: true, @@ -191,13 +194,17 @@ class _BuildLoyaltyCardListState extends State { // }, // ); } else { - return const Padding( - padding: EdgeInsets.only(top: 25.0), - child: Center( - child: Text( - "No Cards Available", - style: TextStyle(fontSize: 25, color: Colors.grey), - textAlign: TextAlign.center, + return Padding( + padding: const EdgeInsets.only(top: 25.0), + child: SizedBox( + height: size.height, + child: const Align( + alignment: Alignment.topCenter, + child: Text( + "No Cards Available", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, + ), ), ), ); diff --git a/Frontend/lib/mih_packages/mzansi_wallet/components/mih_card_display.dart b/Frontend/lib/mih_packages/mzansi_wallet/components/mih_card_display.dart index a1014fc6..78c96447 100644 --- a/Frontend/lib/mih_packages/mzansi_wallet/components/mih_card_display.dart +++ b/Frontend/lib/mih_packages/mzansi_wallet/components/mih_card_display.dart @@ -17,100 +17,43 @@ class _MihCardDisplayState extends State { Widget displayLoyaltyCard() { switch (widget.shopName.toLowerCase()) { case "best before": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/best_before.png'), - ); + return Image.asset('images/loyalty_cards/best_before.png'); case "checkers": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/checkers.png'), - ); + return Image.asset('images/loyalty_cards/checkers.png'); case "clicks": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/Clicks_Club.png'), - ); + return Image.asset('images/loyalty_cards/Clicks_Club.png'); case "cotton:on": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/cotton_on_perks.png'), - ); + return Image.asset('images/loyalty_cards/cotton_on_perks.png'); case "dis-chem": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/dischem_benefit.png'), - ); + return Image.asset('images/loyalty_cards/dischem_benefit.png'); case "pick n pay": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/pnp_smart.png'), - ); + return Image.asset('images/loyalty_cards/pnp_smart.png'); case "shoprite": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/shoprite.png'), - ); + return Image.asset('images/loyalty_cards/shoprite.png'); case "spar": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/spar_rewards.png'), - ); + return Image.asset('images/loyalty_cards/spar_rewards.png'); case "woolworths": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/wrewards.png'), - ); + return Image.asset('images/loyalty_cards/wrewards.png'); case "makro": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/makro.png'), - ); + return Image.asset('images/loyalty_cards/makro.png'); case "fresh stop": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/fresh_stop.png'), - ); + return Image.asset('images/loyalty_cards/fresh_stop.png'); case "panarottis": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/panarottis.png'), - ); + return Image.asset('images/loyalty_cards/panarottis.png'); case "shell": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/Shell.png'), - ); + return Image.asset('images/loyalty_cards/Shell.png'); case "edgars": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/edgars.png'), - ); + return Image.asset('images/loyalty_cards/edgars.png'); case "jet": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/jet.png'), - ); + return Image.asset('images/loyalty_cards/jet.png'); case "spur": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/spur.png'), - ); + return Image.asset('images/loyalty_cards/spur.png'); case "infinity": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/infinity.png'), - ); + return Image.asset('images/loyalty_cards/infinity.png'); case "eskom": - return SizedBox( - height: widget.height, - child: Image.asset('images/loyalty_cards/eskom.png'), - ); + return Image.asset('images/loyalty_cards/eskom.png'); default: - return SizedBox( - height: widget.height, - child: const Placeholder(), - ); + return const Placeholder(); } }