saafe_aa_sdk 0.1.2 copy "saafe_aa_sdk: ^0.1.2" to clipboard
saafe_aa_sdk: ^0.1.2 copied to clipboard

Flutter SDK for integrating SAAFE's secure authentication and financial experience

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'dart:io' show Platform;
import 'package:flutter_saafe_sdk/saafe_sdk.dart';

void main() {
  // Initialize SAAFE SDK
  SaafeSdk.initialize();
  
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'SAAFE SDK Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const SaafeDemo(),
    );
  }
}

class SaafeDemo extends StatefulWidget {
  const SaafeDemo({Key? key}) : super(key: key);

  @override
  State<SaafeDemo> createState() => SaafeDemoState();
}

class SaafeDemoState extends State<SaafeDemo> {
  // This would be your secure token information
  final String fi = 'Wk1AUUBGV0dWVh1SX0E=';
  final String reqdate = '240420251304642';
  final String ecreq = 'Gf3JyORgx-lcPhuX95YLGVpTEU1yHbvEebJMjetIv6UO5OYL-TihpbYwPI05b__w5xJGCydqIC0bqCJVLrmYmDSCqOAbKrhBbKBXXwcL8XyRDN6iMLUWJY8AeOIbB7lb1pfToh7zstOGCW4FGriLlvbhr50fpKR57VZQjtjoj0BYt3fcubYTC71V-rZQthpeHDfO-aQRE0z9hNKaHZa2wOb9fOERzlrogXfPIs5Evpy9Y3uG5aWpvEW4bw8sm4lLGtGE4XEBLk-cmcKdKT3uMyI0m6zz_YaKoFBK43mQFMaTwBJL7puq2I7dmkx-1Qde2v702oA-mSoYShFei06lJW6SsdLmZQaa36wMt2rYZ_0=';
  
  SaafeRedirectInstance? _redirectInstance;
  String _status = 'Not started';
  bool _isSupported = true;

  @override
  void initState() {
    super.initState();
    // Check if platform is supported
    _checkPlatformSupport();
  }

  void _checkPlatformSupport() {
    setState(() {
      // Check if the current platform supports WebView
      if (kIsWeb || 
          !(Platform.isAndroid || Platform.isIOS)) {
        _isSupported = false;
        _status = 'Platform not supported';
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('SAAFE SDK Demo'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Status: $_status',
              style: const TextStyle(fontSize: 18),
            ),
            const SizedBox(height: 30),
            if (!_isSupported)
              const Padding(
                padding: EdgeInsets.all(16.0),
                child: Text(
                  'This platform does not support WebView. SAAFE SDK requires Android or iOS.',
                  textAlign: TextAlign.center,
                  style: TextStyle(color: Colors.red, fontSize: 16),
                ),
              )
            else
              ...[
                const SizedBox(height: 20),
                ElevatedButton(
                  onPressed: _startSaafeFlow,
                  child: const Text('Start SAAFE Flow'),
                ),
                if (_redirectInstance != null)
                  Padding(
                    padding: const EdgeInsets.only(top: 16.0),
                    child: ElevatedButton(
                      onPressed: _closeFlow,
                      style: ElevatedButton.styleFrom(
                        backgroundColor: Colors.red,
                      ),
                      child: const Text('Close Flow'),
                    ),
                  ),
              ],
          ],
        ),
      ),
    );
  }

  void _startSaafeFlow() async {
    setState(() {
      _status = 'Starting...';
    });

    final options = SaafeRedirectOptions(
      fi: fi,
      reqdate: reqdate,
      ecreq: ecreq,
      onLoad: () {
        setState(() {
          _status = 'Flow loaded';
        });
      },
      onComplete: (data) {
        setState(() {
          _status = 'Completed: $data';
          _redirectInstance = null;
        });
      },
      onCancel: () {
        setState(() {
          _status = 'Cancelled by user';
          _redirectInstance = null;
        });
      },
      onError: (error) {
        setState(() {
          _status = 'Error: $error';
          _redirectInstance = null;
        });
      },
    );

    _redirectInstance = await SaafeSdk.triggerRedirect(context, options);
  }

  void _closeFlow() {
    if (_redirectInstance != null) {
      _redirectInstance!.close();
      setState(() {
        _status = 'Closed by app';
        _redirectInstance = null;
      });
    }
  }
}
2
likes
0
points
118
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

Flutter SDK for integrating SAAFE's secure authentication and financial experience

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cupertino_icons, flutter, url_launcher, webview_flutter

More

Packages that depend on saafe_aa_sdk