Flutter Quickstart
Quickstart: Implementing Particle Auth within applications built with Flutter
Particle Auth is the standard SDK used for standalone social logins, allowing for 2-click onboarding using Google, X, email, and so on. Flutter is one of numerous platforms supported by Particle Auth and will be covered here.
Specifically, this document will go through the step-by-step process of configuring, initializing, and using Particle Auth with Flutter.
For complete documentation covering the implementation of Particle Auth with Flutter in more depth, head over to the Flutter SDK reference.
Installing Particle Auth
To begin, you’ll need to add and install Particle Auth’s primary SDK, particle_auth_core
, to your Flutter application; this is a requirement before moving onto platform-specific configuration.
This can be done through the following command.
Configuring Particle Auth
Once installed, you’re ready to configure Particle Auth and initialize the SDK.
To do this, you’ll need three key values from the Particle dashboard: your project ID, client key, and app ID. These are used to authenticate your instance of Particle Auth and connect your project to the dashboard; these are required to properly initialize the SDK.
Retrieving these keys can be done through the following steps.
For more information on the Particle dashboard, take a look at the dashboard quickstart.
Android
Prerequisites
When using Particle Auth’s Flutter SDK on Android, you’ll need to ensure your project meets a few different requirements (otherwise, you’ll likely run into compatibility issues); these are listed below.
- minSdkVersion 23 or higher.
- compileSdkVersion, targetSdkVersion 34 or higher.
- JavaVersion 17.
- Jetpack (AndroidX).
- Android Gradle Plugin Version: 8.5.1 or higher.
- Gradle Version: 8.9 or higher.
Configuring build.gradle
To begin configuring your project, you’ll need to go ahead and open your build.gradle
file, often found at the following file path: ${project name}/android/app/build.gradle
.
Within your build.gradle
file, you’ll need to add four new lines to ensure Particle Auth runs appropriately:
minSdkVersion
, which in most cases will be set to23
.manifestPlaceholders["PN_PROJECT_ID"]
, theprojectId
previously retrieved from the Particle dashboard.manifestPlaceholders["PN_PROJECT_CLIENT_KEY"]
, theclientKey
previously retrieved from the Particle dashboard.manifestPlaceholders["PN_APP_ID"]
, theappId
previously retrieved from the Particle dashboard.
Below is an example of how this may look.
Staying within your build.gradle
file, you’ll need to ensure that you’re using version 17 of Java in both compileOptions
and kotlinOptions
, alongside enabling dataBinding
, as shown below.
Finally, for dependency management, within build.gradle
you’ll need to ensure that the repositories
object in both buildscript
and allprojects
has maven { setUrl("https://jitpack.io") }
present, such as is shown in the following snippet.
iOS
Alternatively, if you’re building an iOS application with Flutter, this entails a unique and iOS-specific configuration process, as will be covered in this section.
Prerequisites
Before beginning, ensure your project meets the following prerequisites:
-
Xcode 15.0 or later.
-
iOS 14 or later.
With these requirements set, you’ll need to open an exported iOS project and navigate to apps/{project name}.xcworkspace
.
Configure ParticleNetwork-Info.plist
At the root of your Xcode project, create a new file, ParticleNetwork-Info.plist
. Ensure this is marked under Target Membership
.
Now, with a fresh ParticleNetwork-Info.plist
file, go ahead and fill it in with the following values, previously retrieved from the Particle dashboard:
Configuring Info.plist: Face ID
Furthermore, to enable Face ID for your app, add a usage description to your Info.plist
file by including the following code:
Configuring your Podfile
Finally, you’ll need to edit your Podfile to ensure particle_auth_core
is properly imported. Head over to the linked example to complete this, if you haven’t already.
Another important note before continuing.
Our SDK is a static library (XCFramework). When using the Particle Auth Flutter SDK, you’ll need to specify that you’re using a static framework through the snippet below.
Initializing Particle Auth
At this point, you’ve installed and configured Particle Auth; the only step remaining before the SDK can be used is initialization.
Particle Auth can be initialized by simply setting your project ID and client key (previously retrieved from the Particle dashboard) through ParticleInfo.set
. An example of this has been included in the snippet below.
Upon setting these values, you’ll need to call the init
method on ParticleBase
. This takes the following parameters:
chainInfo
, representing the primary chain you intend to use (for example,ChainInfo.Ethereum
,chainInfo.Polygon
).env
, affecting the information logged within your environment (Env.dev
,Env.production
, orEnv.staging
).
Facilitating social login
You’re now ready to facilitate social login and interacting with the resulting accounts.
As shown below, you’ll need to call ParticleAuthCore.connect
to initiate social login, passing in the specific login type you’d like the user to onboard through (.google
, .twitter
, .discord
, etc.) alongside, if applicable, the type of account prompt used by the OAuth provider (.select_account
, .consent
, .none
).
chainInfo
, a new address will be generated. For example, if the current chain is EVM-compatible, only an EVM address will be generated; if it’s the Solana chain, only a Solana address will be generated. If you want to obtain both addresses, you can use ParticleAuthCore.switchChain
to switch chains, and after waiting for 2 seconds, a new address for the selected chain will be generated for you.Examples of Utilization
Retrieve User Information
With a user logged in, you’ll be able to retrieve information about their account (such as their address, or specific details regarding the social login mechanism they used) through methods such as Evm.getAddress
and ParticleAuthCore.getUserInfo
(getUserInfo
returns an object with numerous points of information; to learn more, head over to its API reference).
The following snippet is an example of retrieving a user’s address on both EVM and Solana alongside pulling their broader account information.
Send a Transaction
Now, as a final example, you can send a transaction, such as burning 0.000000001 ETH.
To do this, you’ll need to construct a transaction with EvmService.createTransaction
using standard parameters such as evmAddress
, data
, value
, and receiverAddress
,
Upon construction, the transaction can be sent through Evm.sendTransaction
; once the user signs/confirms, it’ll be pushed to the network; an example of this is shown below.
Was this page helpful?