The okto_flutter_sdk
is a Flutter SDK for integrating Okto services into mobile applications. This SDK provides functionalities to interact with Okto's features and services within your Flutter projects.
Install the package in your Flutter project:
flutter pub add okto_flutter_sdk
Ensure you have the google_sign_in
dependency in your project:
flutter pub add google_sign_in
- Go to Google Cloud Console.
- Create a new project or select an existing one.
- Enable the Google Sign-In API for your project.
- Create a Web Client ID:
- Navigate to APIs & Services > Credentials.
- Click Create Credentials > OAuth 2.0 Client IDs.
- Select Web Application as the application type.
- Copy the generated Web Client ID and paste it into
android/app/src/main/res/values/strings.xml
:<resources> <string name="default_web_client_id">YOUR_WEB_CLIENT_ID</string> </resources>
- Create an Android Client ID in the same credentials section:
- Select Android as the application type.
- Add your app's package name and SHA-1 signing certificate.
- Sync your project and rebuild.
- Go to Google Cloud Console and create an iOS Client ID:
- Navigate to APIs & Services > Credentials.
- Click Create Credentials > OAuth 2.0 Client IDs.
- Select iOS as the application type.
- Add your app's Bundle ID.
- Download the
GoogleService-Info.plist
file. - Place the
GoogleService-Info.plist
file insideios/Runner/
. - Configure
info.plist
to include your iOS Client ID and URL Scheme:<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>com.googleusercontent.apps.YOUR_IOS_CLIENT_ID</string> </array> </dict> </array>
- Run the following command to ensure your iOS project is correctly set up:
flutter build ios
- The
YOUR_CLIENT_API_KEY
is required to authenticate your application with Okto's services. - Obtain the API key from the Okto Developer Portal:
- Log in to Okto Developer Portal.
- Navigate to your project settings.
- Copy the API key for either Sandbox or Production environment.
- Replace
YOUR_CLIENT_API_KEY
in the example code with your actual key.
To utilize the SDK within your application, follow these steps:
Initialize the SDK anywhere in your codebase:
final okto = Okto('YOUR_CLIENT_API_KEY', BuildType.sandbox);
Here is an example of how to integrate Google Sign-In with Okto:
import 'package:google_sign_in/google_sign_in.dart';
import 'package:okto_flutter_sdk/okto_flutter_sdk.dart';
import 'package:flutter/material.dart';
final GoogleSignIn googleSignIn = GoogleSignIn();
final Okto okto = Okto('YOUR_CLIENT_API_KEY', BuildType.sandbox);
ElevatedButton(
onPressed: () async {
try {
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
final GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;
if (googleAuth != null) {
final String? idToken = googleAuth.idToken;
await okto.authenticate(idToken: idToken!);
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => const HomePage()));
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: ${e.toString()}')),
);
}
},
child: const Text('Login with Google, powered by Okto.'),
);
- For detailed documentation, visit the Okto Wallet SDK Documentation.
With these steps, you can easily integrate okto_flutter_sdk
into your Flutter project and start leveraging its powerful features!