You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
void main() {
|
|
runApp(MaterialApp(home: UpiIntentExample()));
|
|
}
|
|
|
|
class UpiIntentExample extends StatelessWidget {
|
|
final String upiId = "sneha.reddymalla@ybl"; // Replace with your UPI ID
|
|
final String name = "Sneha Reddy";
|
|
final String note = "Sample";
|
|
final String amount = "1.00";
|
|
|
|
void launchUPIApp(BuildContext context) async {
|
|
final uri = Uri.parse(
|
|
"upi://pay?pa=$upiId&pn=$name&tn=$note&am=$amount&cu=INR");
|
|
|
|
if (await canLaunchUrl(uri)) {
|
|
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text("No UPI app found to handle this request")),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text("UPI Payment via Intent")),
|
|
body: Center(
|
|
child: ElevatedButton(
|
|
onPressed: () => launchUPIApp(context),
|
|
child: Text("Pay with UPI App"),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|