use MIH App Widget
This commit is contained in:
327
Frontend/lib/mih_packages/mzansi_wallet/app_tools/mih_cards.dart
Normal file
327
Frontend/lib/mih_packages/mzansi_wallet/app_tools/mih_cards.dart
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_apis/mih_mzansi_wallet_apis.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_number_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_search_input.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih-app_tool_body.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_objects/app_user.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_objects/loyalty_card.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/builder/build_loyalty_card_list.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/components/mih_card_display.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||||
|
|
||||||
|
class MihCards extends StatefulWidget {
|
||||||
|
final AppUser signedInUser;
|
||||||
|
const MihCards({
|
||||||
|
super.key,
|
||||||
|
required this.signedInUser,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MihCards> createState() => _MihCardsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MihCardsState extends State<MihCards> {
|
||||||
|
final TextEditingController shopController = TextEditingController();
|
||||||
|
final TextEditingController cardNumberController = TextEditingController();
|
||||||
|
final TextEditingController cardSearchController = TextEditingController();
|
||||||
|
late Future<List<MIHLoyaltyCard>> cardList;
|
||||||
|
List<MIHLoyaltyCard> listOfCards = [];
|
||||||
|
//bool showSelectedCardType = false;
|
||||||
|
final ValueNotifier<String> shopName = ValueNotifier("");
|
||||||
|
final ValueNotifier<List<MIHLoyaltyCard>> searchShopName = ValueNotifier([]);
|
||||||
|
|
||||||
|
final MobileScannerController scannerController = MobileScannerController(
|
||||||
|
detectionSpeed: DetectionSpeed.unrestricted,
|
||||||
|
);
|
||||||
|
final boxFit = BoxFit.contain;
|
||||||
|
|
||||||
|
void searchShop() {
|
||||||
|
if (cardSearchController.text.isEmpty) {
|
||||||
|
searchShopName.value = listOfCards;
|
||||||
|
} else {
|
||||||
|
List<MIHLoyaltyCard> temp = [];
|
||||||
|
for (var item in listOfCards) {
|
||||||
|
if (item.shop_name
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(cardSearchController.text.toLowerCase())) {
|
||||||
|
temp.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
searchShopName.value = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void openscanner() async {
|
||||||
|
Navigator.of(context).pushNamed(
|
||||||
|
'/scanner',
|
||||||
|
arguments: cardNumberController,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shopSelected() {
|
||||||
|
if (shopController.text.isNotEmpty) {
|
||||||
|
shopName.value = shopController.text;
|
||||||
|
} else {
|
||||||
|
shopName.value = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addCardWindow(BuildContext ctxt) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (context) => MIHWindow(
|
||||||
|
fullscreen: false,
|
||||||
|
windowTitle: "Add New Loyalty Card",
|
||||||
|
windowTools: const [
|
||||||
|
SizedBox(width: 35),
|
||||||
|
// IconButton(
|
||||||
|
// onPressed: () {
|
||||||
|
// //Delete card API Call
|
||||||
|
// },
|
||||||
|
// icon: Icon(
|
||||||
|
// Icons.delete,
|
||||||
|
// color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
],
|
||||||
|
onWindowTapClose: () {
|
||||||
|
shopController.clear();
|
||||||
|
cardNumberController.clear();
|
||||||
|
shopName.value = "";
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
windowBody: [
|
||||||
|
MIHDropdownField(
|
||||||
|
controller: shopController,
|
||||||
|
hintText: "Shop Name",
|
||||||
|
dropdownOptions: const [
|
||||||
|
"Best Before",
|
||||||
|
"Checkers",
|
||||||
|
"Clicks",
|
||||||
|
"Cotton:On",
|
||||||
|
"Dis-Chem",
|
||||||
|
"Edgars",
|
||||||
|
"Eskom",
|
||||||
|
"Fresh Stop",
|
||||||
|
"Infinity",
|
||||||
|
"Jet",
|
||||||
|
"Makro",
|
||||||
|
"Panarottis",
|
||||||
|
"Pick n Pay",
|
||||||
|
"Shell",
|
||||||
|
"Shoprite",
|
||||||
|
"Spar",
|
||||||
|
"Spur",
|
||||||
|
"Woolworths"
|
||||||
|
],
|
||||||
|
required: true,
|
||||||
|
editable: true,
|
||||||
|
enableSearch: false,
|
||||||
|
),
|
||||||
|
ValueListenableBuilder(
|
||||||
|
valueListenable: shopName,
|
||||||
|
builder: (BuildContext context, String value, Widget? child) {
|
||||||
|
return Visibility(
|
||||||
|
visible: value != "",
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
MihCardDisplay(shopName: shopName.value, height: 200),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
child: MIHNumberField(
|
||||||
|
controller: cardNumberController,
|
||||||
|
hintText: "Card Number",
|
||||||
|
editable: true,
|
||||||
|
required: true,
|
||||||
|
enableDecimal: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
MIHButton(
|
||||||
|
onTap: () async {
|
||||||
|
openscanner();
|
||||||
|
},
|
||||||
|
buttonText: "Scan",
|
||||||
|
buttonColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
textColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
SizedBox(
|
||||||
|
width: 300,
|
||||||
|
height: 50,
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
if (shopController.text == "" ||
|
||||||
|
cardNumberController.text == "") {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return const MIHErrorMessage(errorType: "Input Error");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
MIHMzansiWalletApis.addLoyaltyCardAPICall(
|
||||||
|
widget.signedInUser,
|
||||||
|
widget.signedInUser.app_id,
|
||||||
|
shopController.text,
|
||||||
|
cardNumberController.text,
|
||||||
|
context,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonText: "Add",
|
||||||
|
buttonColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
cardNumberController.dispose();
|
||||||
|
shopController.removeListener(shopSelected);
|
||||||
|
shopController.dispose();
|
||||||
|
cardSearchController.removeListener(searchShop);
|
||||||
|
cardSearchController.dispose();
|
||||||
|
searchShopName.dispose();
|
||||||
|
shopName.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
cardList = MIHMzansiWalletApis.getLoyaltyCards(widget.signedInUser.app_id);
|
||||||
|
shopController.addListener(shopSelected);
|
||||||
|
cardSearchController.addListener(searchShop);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MihAppToolBody(
|
||||||
|
borderOn: true,
|
||||||
|
bodyItem: bodyItem(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Loyalty Cards",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.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,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
flex: 4,
|
||||||
|
child: SizedBox(
|
||||||
|
height: 50,
|
||||||
|
child: MIHSearchField(
|
||||||
|
controller: cardSearchController,
|
||||||
|
hintText: "Shop Name",
|
||||||
|
required: false,
|
||||||
|
editable: true,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Flexible(
|
||||||
|
flex: 1,
|
||||||
|
child: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
cardSearchController.clear();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.filter_alt_off),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
ValueListenableBuilder(
|
||||||
|
valueListenable: searchShopName,
|
||||||
|
builder: (BuildContext context, List<MIHLoyaltyCard> value,
|
||||||
|
Widget? child) {
|
||||||
|
return BuildLoyaltyCardList(
|
||||||
|
cardList: searchShopName.value,
|
||||||
|
signedInUser: widget.signedInUser,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return const Center(
|
||||||
|
child: Text("Error Loading Loyalty Cards"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
78
Frontend/lib/mih_packages/mzansi_wallet/mih_wallet.dart
Normal file
78
Frontend/lib/mih_packages/mzansi_wallet/mih_wallet.dart
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_action.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_tools.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/app_tools/mih_cards.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class MihWallet extends StatefulWidget {
|
||||||
|
final AppUser signedInUser;
|
||||||
|
const MihWallet({
|
||||||
|
super.key,
|
||||||
|
required this.signedInUser,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MihWallet> createState() => _MihWalletState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MihWalletState extends State<MihWallet> {
|
||||||
|
late int _selcetedIndex;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
setState(() {
|
||||||
|
_selcetedIndex = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MihApp(
|
||||||
|
appActionButton: getAction(),
|
||||||
|
appTools: getTools(),
|
||||||
|
appBody: getToolBody(),
|
||||||
|
selectedbodyIndex: _selcetedIndex,
|
||||||
|
onIndexChange: (newValue) {
|
||||||
|
setState(() {
|
||||||
|
_selcetedIndex = newValue;
|
||||||
|
});
|
||||||
|
print("Index: $_selcetedIndex");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
MihAppAction getAction() {
|
||||||
|
return MihAppAction(
|
||||||
|
icon: const Icon(Icons.arrow_back),
|
||||||
|
iconSize: 35,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
MihAppTools getTools() {
|
||||||
|
Map<Widget, void Function()?> temp = {};
|
||||||
|
temp[const Icon(Icons.card_membership)] = () {
|
||||||
|
setState(() {
|
||||||
|
_selcetedIndex = 0;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return MihAppTools(
|
||||||
|
tools: temp,
|
||||||
|
selcetedIndex: _selcetedIndex,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> getToolBody() {
|
||||||
|
List<Widget> toolBodies = [
|
||||||
|
MihCards(
|
||||||
|
signedInUser: widget.signedInUser,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
return toolBodies;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user