Here you can find the tutorial about E3kit integration into Flutter:

Step 1

flutter create -i swift virgil_crypto_app
[setup firebase for flutter]…

Also follow the steps from the new Firebase Cloud Functions demo. 


Step 2

Inside the Flutter project, go to ‘ios/Podfile’, then to “target ‘Runner’ do” and below use_frameworks! add pod ‘VirgilE3Kit’.


Step 3

Open terminal and inside the project folder (virgil_crypto_app) run ‘flutter run’ - it will install all pods and dependencies.


Step 4

Open iOS folder in Xcode and import from demo-firebase-ios sample (development branch, not master) the following files: Log, E3kitHelper and UserAuthorizer.


Step 5

Leave Xcode and go to Flutter project (different IDE).
Open the file where the methods need calling (for example, the code could be placed in the authentication service).

import 'dart:async';
import 'package:flutter/services.dart'; // <= Import MethodChannel
import 'package:firebase_auth/firebase_auth.dart';

abstract class BaseAuth {
  Future<Object> signIn (String email, String password);
  Future<Object> createUser (String email, String password);
  Future<void> signOut();
}

class Auth implements BaseAuth {

// =============Crypto Helper Channel Begin================
  static const MethodChannel methodChannel = MethodChannel('samples.flutter.io/crypto');

Future<String> _cryptoSignIn(String email, String password) async {
    try {
      final result = await methodChannel.invokeMethod('cryptoSignIn', [email, password]);
      return result;
    } on PlatformException {
      return 'Failed to get Virgil Crypto.';
    }
  }

Future<String> _cryptoSignUp(String email, String password) async {
    try {
      final result = await methodChannel.invokeMethod('cryptoSignUp', [email, password]);
      return result;
    } on PlatformException {
      return 'Failed to get Virgil Crypto.';
    }
  }
  // =============Crypto Helper Channel End================

// Firebase Auth
  final FirebaseAuth _fAuth = FirebaseAuth.instance;

Future<Object> signIn (String email, String password) async {
    FirebaseUser user = await _fAuth.signInWithEmailAndPassword(email: email, password: password);
    Future<String> response = _cryptoSignIn(email, password);
    print(await response);
    return await response;
  }

Future<Object> createUser (String email, String password) async {
    FirebaseUser user = await _fAuth.createUserWithEmailAndPassword(email: email, password: password);
    Future<String> response = _cryptoSignUp(email, password);
    print(await response);
    return await response;
  }

Future<void> signOut() async {
    return _fAuth.signOut();
  }
}


Step 6

Go to Runner/Runner/AppDelegate.swift and you will see:

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

static let jwtEndpoint = "https://[..].cloudfunctions.net/api/get-virgil-jwt"

override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
  ) -> Bool {
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController;
    let cryptoChannel = FlutterMethodChannel.init(name: "samples.flutter.io/crypto",
                                                   binaryMessenger: controller);
   
    cryptoChannel.setMethodCallHandler({
        (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
        let method = call.method;
        let args = call.arguments as! [String];
       
        // List of methods called from Flutter code
        if(method == "cryptoSignIn"){
            self.cryptoSignIn(result: result, email: args[0], password: args[1]);
        }
        else if (method == "cryptoSignUp"){
            self.cryptoSignUp(result: result, email: args[0], password: args[1])
        }
        else {
            result(FlutterMethodNotImplemented);
        }
 });
   
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
   
    let virgilHelper = UserAuthorizer();
   
    private func cryptoSignIn(result: @escaping FlutterResult, email: String, password: String) {
        virgilHelper.signIn(email: email, password: password) {error in
            var res: String;
            // return some feedback
            res = error == nil ? "ok" : "Virgil sign in failed with error: \(error!.localizedDescription)";
            result(res);
        }
    }
   
    private func cryptoSignUp(result: @escaping FlutterResult, email: String, password: String) {
        virgilHelper.signUp(email: email, password: password) {error in
            var res: String;
            // return some feedback
            res = error == nil ? "ok" : "Virgil sign up failed with error: \(error!.localizedDescription)";
            result(res);
        }
    }
}

Step 7
Go to Xcode and run Runner - stop after building the app - then go to Flutter and develop the app.

Did this answer your question?