easebuzz_flutter 0.0.3
easebuzz_flutter: ^0.0.3 copied to clipboard
The Easebuzz Flutter plugin simplifies secure payment integration in Flutter apps.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:easebuzz_flutter/easebuzz_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _paymentResponse = 'No payment response yet';
final TextEditingController _accessKeyController = TextEditingController();
bool _isProductionMode = false; // false for "test" mode, true for "production" mode
final _easebuzzFlutterPlugin = EasebuzzFlutter();
// Method to initiate payment using the plugin
Future<void> initiatePayment() async {
String accessKey = _accessKeyController.text.trim();
String payMode = _isProductionMode ? "production" : "test";
try {
// Invoke the method on the platform to initiate payment
final paymentResponse = await _easebuzzFlutterPlugin.payWithEasebuzz(accessKey,payMode);
setState(() {
_paymentResponse = paymentResponse.toString(); // Store and display response
});
} on PlatformException catch (e) {
setState(() {
_paymentResponse = "Payment failed: ${e.message}";
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: _accessKeyController,
decoration: InputDecoration(
labelText: 'Enter Access Key',
border: OutlineInputBorder(),
),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Test Mode'),
Switch(
value: _isProductionMode,
onChanged: (value) {
setState(() {
_isProductionMode = value;
});
},
),
Text('Production Mode'),
],
),
SizedBox(height: 20),
ElevatedButton(
onPressed: initiatePayment,
child: Text('Start Payment'),
),
SizedBox(height: 20),
Text('Payment Response: $_paymentResponse'),
],
),
),
),
),
);
}
}