welloo_sdk 0.0.39
welloo_sdk: ^0.0.39 copied to clipboard
Package de transaction Welloo
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:welloo_sdk/welloo_sdk.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await WellooSdk.init(mockMode: false);
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welloo SDK V2 Demo',
theme: ThemeData(colorSchemeSeed: Colors.blue, useMaterial3: true),
home: const DemoWello(),
);
}
}
class DemoWello extends StatefulWidget {
const DemoWello({super.key});
@override
State<DemoWello> createState() => _DemoWelloState();
}
class _DemoWelloState extends State<DemoWello> {
final _sdk = WellooSdk();
final _accessToken =
"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3V1BYTi1wZXc0a2l1T0Y2SDBQaHBuUF96UUFrU3dMZVB3c1pfU0tfbWhnIn0.eyJleHAiOjE3NjQwODY2MjIsImlhdCI6MTc2NDA4NDgyMiwianRpIjoib25ydHJvOjRmZWYyNTg5LTE3ZTQtNDFjNy05YmUwLWNhY2I4ZGQxMGQ3ZiIsImlzcyI6Imh0dHBzOi8vYXV0aC1kZXYuZmluYXBheS5uZXQvcmVhbG1zL2ZpbmFwYXkiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiN2ExODU4MzktZjBiNy00ODVjLWJmMTUtZGMxNmFiOTY0YzQ3IiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZmluYXBheS1hcGkiLCJzaWQiOiJiN2VjMWJhMi1jMTM4LTQyNjItYTRmZS00YzU0MDYwNDNiY2MiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbIi8qIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJkZWZhdWx0LXJvbGVzLWZpbmFwYXkiLCJvZmZsaW5lX2FjY2VzcyIsImRlbGV0ZV9zZXJ2aWNlIiwidW1hX2F1dGhvcml6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I3YTE4NTgzOS1mMGI3LTQ4NWMtYmYxNS1kYzE2YWI5NjRjNDciLCJ0eXAiOiJSZWZyZXNoIiwiYXpwIjoiZmluYXBheS1hcGkiLCJzaWQiOiJiN2VjMWJhMi1jMTM4LTQyNjItYTRmZS00YzU0MDYwNDNiY2MiLCJzY29wZSI6Im9wZW5pZCB3ZWItb3JpZ2lucyBwcm9maWxlIGFjciBlbWFpbCByb2xlcyBiYXNpYyJ9.B_R3ZzNQN1ZfSMr3k-A4i699PQ3HVfLQaYCWzQ_-CryV2Ex_zKBUPAV-DeN8tNcEY7p1oMffWaIts0Wn0sG9Rw";
bool _isRegistered = false;
Wallet? _wallet;
String? _pendingTransactionId;
@override
void initState() {
super.initState();
_checkRegistration();
}
Future<void> _checkRegistration() async {
final registeredResult = await _sdk.isUserRegistered();
final walletResult = await _sdk.getCurrentWallet();
setState(() {
_isRegistered = registeredResult.success
? (registeredResult.data ?? false)
: false;
_wallet = walletResult.success ? walletResult.data : null;
});
}
Future<void> _handleRegister() async {
try {
final result = await _sdk.registerClient(
accessToken: _accessToken,
refreshToken: _refreshToken,
);
if (result.success) {
await _checkRegistration();
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Registered! Phone: ${_wallet?.telephone}')),
);
} else {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Registration failed: ${result.error}')),
);
}
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Error: $e')));
}
}
Future<void> _handleDeposit() async {
if (!_isRegistered) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Please register first')));
return;
}
try {
final result = await _sdk.initDeposit(context: context);
if (!mounted) return;
if (result.status.name == 'inProgress') {
setState(() {
_pendingTransactionId = result.transactionId;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Transaction en cours (ID: ${result.transactionId}). Finalisez dans Wave puis vérifiez le statut.',
),
duration: const Duration(seconds: 5),
),
);
} else {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Deposit: ${result.status}')));
}
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Error: $e')));
}
}
Future<void> _handleCheckStatus() async {
if (_pendingTransactionId == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Aucune transaction en cours')),
);
return;
}
try {
final result = await _sdk.checkTransactionStatus(
context: context,
transactionId: _pendingTransactionId!,
);
if (!mounted) return;
if (result.status.name == 'succeeded') {
setState(() {
_pendingTransactionId = null;
});
}
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Statut: ${result.status.name}')));
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Error: $e')));
}
}
Future<void> _handleTransfer() async {
if (!_isRegistered) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Please register first')));
return;
}
try {
final result = await _sdk.initTransfer(context: context);
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Transfer: ${result.status}')));
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Error: $e')));
}
}
Future<void> _handleLogout() async {
try {
await _sdk.logout();
await _checkRegistration();
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Logged out')));
} catch (e) {}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Welloo SDK V2 Demo')),
backgroundColor: Colors.white,
body: Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Welloo SDK V2',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10),
Text(
_isRegistered
? 'Registered: ${_wallet?.telephone}'
: 'Not registered',
),
const SizedBox(height: 40),
if (!_isRegistered)
ElevatedButton.icon(
onPressed: _handleRegister,
icon: const Icon(Icons.person_add),
label: const Text("Enregistrer Client"),
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
),
),
if (_isRegistered) ...[
ElevatedButton.icon(
onPressed: _handleDeposit,
icon: const Icon(Icons.add_circle),
label: const Text("Dépôt"),
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
),
),
const SizedBox(height: 12),
if (_pendingTransactionId != null) ...[
ElevatedButton.icon(
onPressed: _handleCheckStatus,
icon: const Icon(Icons.search),
label: const Text("Vérifier statut"),
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
),
),
const SizedBox(height: 8),
Text(
'TX ID: $_pendingTransactionId',
style: const TextStyle(fontSize: 10, color: Colors.grey),
),
const SizedBox(height: 12),
],
ElevatedButton.icon(
onPressed: _handleTransfer,
icon: const Icon(Icons.send),
label: const Text("Transfert"),
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
),
),
const SizedBox(height: 20),
ElevatedButton.icon(
onPressed: _handleLogout,
icon: const Icon(Icons.logout),
label: const Text("Déconnexion"),
style: ElevatedButton.styleFrom(
minimumSize: const Size(200, 50),
),
),
],
const SizedBox(height: 40),
const Text(
'Types de transaction: Dépôt, Paiement, Transfert',
style: TextStyle(fontSize: 12, color: Colors.grey),
),
const SizedBox(height: 8),
const Text(
'Opérateurs: Wello, Wave',
style: TextStyle(fontSize: 12, color: Colors.grey),
),
],
),
),
),
);
}
}