Reputation: 1
I am working a flutter project that is an ecommerce app that sells sneakers. In my checkout page I have used the checkout_screen_ui widget version 1.0.1 which a prebuild widget by flutter. While using the widget I am getting '$' in front of product prices but I want Indian rupees sign '₹'. Checkout Page
I tried formatting the $ symbol by ₹ manually in the code but it still doesn't work.
class paymenTpage extends StatefulWidget {
paymenTpage({super.key, required this.orderedShoes, required this.quant});
List<Sneakers> orderedShoes;
List<String> quant;
@override
State<paymenTpage> createState() => _paymenTpageState();
}
class _paymenTpageState extends State<paymenTpage> {
final List<PriceItem> _priceItems = [];
void setData() {
int index = 0;
for (var element in widget.orderedShoes) {
double productPrice = double.parse(element.price);
int totalPriceInCents =
(productPrice * 100).round(); // Multiply by 100 to convert to cents
int quantity = int.parse(widget.quant[index]);
String formattedPrice =
'\u{20B9}${productPrice.toStringAsFixed(2)}'; // Add rupee symbol and format
print("Formatted Price: $formattedPrice");
_priceItems.add(
PriceItem(
name: element.name,
quantity: quantity,
itemCostCents: totalPriceInCents,
description: formattedPrice,
),
);
print("Description of added PriceItem: ${_priceItems.last.description}");
index++;
}
setState(() {});
}
void Function(CheckOutResult)? onNativePay;
@override
void initState() {
// implement initState
super.initState();
setData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
toolbarHeight: 0,
elevation: 0,
systemOverlayStyle: SystemUiOverlayStyle(
systemNavigationBarColor: Colors.grey.shade100, // Navigation bar
statusBarColor: Colors.grey.shade100, // Status bar
),
),
body: CheckoutPage(
data: CheckoutData(
priceItems: _priceItems,
payToName: 'Atharva Enterprises',
onCardPay: (cardformresults, checkoutresult) =>
print('Credit card : $CardFormResults, $CheckOutResult'),
onNativePay: (checkoutresult) {
int index = 0;
// ignore: avoid_function_literals_in_foreach_calls
widget.orderedShoes.forEach((element) async {
await FirebaseFirestore.instance
.collection("users")
.doc(FirebaseAuth.instance.currentUser!.email)
.collection("ordered")
.add({
"id": element.id,
"gend": element.category,
"paid": "true",
"delivered": "pending",
"amount":
"${(int.parse(element.price) * int.parse(widget.quant[index]))}",
});
await FirebaseFirestore.instance
.collection("users")
.doc(FirebaseAuth.instance.currentUser!.email)
.collection("shoes")
.doc(element.id)
.update({"cart": "false", "quantity": "1"});
});
Navigator.push(context,
MaterialPageRoute(builder: (context) => const successfull()));
},
),
),
);
}
}
Upvotes: 0
Views: 69