Skip to content

Instantly share code, notes, and snippets.

@ShaiqAhmedkhan
Last active March 4, 2020 14:21
Show Gist options
  • Save ShaiqAhmedkhan/94718b216679267a356b07620271846a to your computer and use it in GitHub Desktop.
Save ShaiqAhmedkhan/94718b216679267a356b07620271846a to your computer and use it in GitHub Desktop.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:razorpay_flutter/razorpay_flutter.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
class CoffeePage extends StatefulWidget {
@override
_CoffeePageState createState() => _CoffeePageState();
}
class _CoffeePageState extends State<CoffeePage> {
int totalAmount = 0;
Razorpay _razorpay;
@override
void initState() {
super.initState();
_razorpay = Razorpay();
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
}
@override
void dispose() {
super.dispose();
_razorpay.clear();
}
void openCheckout() async {
var options = {
'key': 'rzp_test_NNbwJ9tmM0fbxj',
'amount': totalAmount * 100,
'name': 'Shaiq',
'description': 'Payment',
'prefill': {'contact': '8888888888', 'email': 'test@razorpay.com'},
'external': {
'wallets': ['paytm']
}
};
try {
_razorpay.open(options);
} catch (e) {
debugPrint(e);
}
}
void _handlePaymentSuccess(PaymentSuccessResponse response) {
Fluttertoast.showToast(
msg: "SUCCESS: " + response.paymentId, timeInSecForIos: 4);
}
void _handlePaymentError(PaymentFailureResponse response) {
Fluttertoast.showToast(
msg: "ERROR: " + response.code.toString() + " - " + response.message,
timeInSecForIos: 4);
}
void _handleExternalWallet(ExternalWalletResponse response) {
Fluttertoast.showToast(
msg: "EXTERNAL_WALLET: " + response.walletName, timeInSecForIos: 4);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
automaticallyImplyLeading: true,
pinned: true,
backgroundColor: Color(0xFF6FC5DA),
expandedHeight: 440,
title: Text("Cappuccino Coffee",
style: TextStyle(
fontFamily: 'varela',
fontSize: 25.0,
fontWeight: FontWeight.bold,
color: Colors.white)),
flexibleSpace: FlexibleSpaceBar(
//title: Text("Coffee"),
background: Padding(
padding: const EdgeInsets.only(left: 8.0, top: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: <Widget>[
Container(
child: Text(
'Freshly steamed milk with \nvanilla-flavored syrup is \nmarked with espresso and \ntopped with caramel drizzle \nfor an oh-so-candy end.',
style: TextStyle(
fontFamily: 'nunito',
fontSize: 16.0,
color: Colors.white)),
),
SizedBox(width: 15.0),
Container(
height: 40.0,
width: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white),
child: Center(
child: Icon(Icons.favorite,
size: 18.0, color: Colors.red)))
],
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment