finapay_sdk 0.0.1
finapay_sdk: ^0.0.1 copied to clipboard
SDK pour les transactions financières. By Finasys Technologies
example/lib/main.dart
import 'package:finapay_sdk/core/models/sdk_result.dart';
import 'package:finapay_sdk_example/core/theme.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:finapay_sdk/finapay_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: AppTheme.lightTheme,
home: MyHome(),
);
}
}
class MyHome extends StatefulWidget {
@override
State<MyHome> createState() => _MyHomeState();
}
class _MyHomeState extends State<MyHome> {
String _platformVersion = 'Unknown';
final _finapaySdkPlugin = FinapaySdk();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _finapaySdkPlugin.getPlatformVersion() ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
Center(
child: Text('Running on: $_platformVersion\n'),
),
ElevatedButton(
onPressed: () async {
final paymentResult =
await _finapaySdkPlugin.initPayment(context: context);
if (paymentResult.status == TransactionStatus.success) {
debugPrint("Paiement réussi : ${paymentResult.reference}");
} else {
debugPrint("Paiement échoué : ${paymentResult.message}");
}
},
child: const Text("Init Payment"),
),
ElevatedButton(
onPressed: () async {
final depositResult =
await _finapaySdkPlugin.initDeposit(context: context);
if (depositResult.status == TransactionStatus.success) {
debugPrint("Dépot réussi : ${depositResult.reference}");
} else {
debugPrint("Dépot échoué : ${depositResult.message}");
}
},
child: const Text("Init Deposit"),
),
ElevatedButton(
onPressed: () async {
final withdrawResult =
await _finapaySdkPlugin.initWithdraw(context: context);
if (withdrawResult.status == TransactionStatus.success) {
debugPrint("Retrait réussi : ${withdrawResult.reference}");
} else {
debugPrint("Retrait échoué : ${withdrawResult.message}");
}
},
child: const Text("Init Withdraw"),
),
ElevatedButton(
onPressed: () async {
final tranfertResult =
await _finapaySdkPlugin.initTransfert(context: context);
if (tranfertResult.status == TransactionStatus.success) {
debugPrint("Transfert réussi : ${tranfertResult.reference}");
} else {
debugPrint("Transfert échoué : ${tranfertResult.message}");
}
},
child: const Text("Init Transfert"),
),
],
),
);
}
}