Flutter
Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications.

Let's Get your Flutter App running with SAWO
🙌

Steps:

1. To get started with the integration of SAWO API on your Flutter App, add the plugin in dependencies:
dependencies:
sawo: ^0.1.2
2. After this, install the plugin, by running the mentioned command:
flutter pub get
3. As part of the next step, import the plugin into class by using the code given below:
import 'package:sawo/sawo.dart';
4. To use SAWO Login you would need an API key which can be obtained by creating a project in the sawo dashboard.
5. Once you create your project, you would need to set your project name.
6. Copy the API key from the project and keep it safe and secure.
It is always recommended to store your apiKey and secretKey in a .env file. Otherwise, create a separate .dart file and add it to the .gitignore. Just make sure that you are not exposing the keys publicly and also add them to the .gitignore before pushing the project to a public repo.
7. Next, create a Sawo Instance
Sawo sawo = new Sawo(
apiKey: <YOUR-API-KEY>,
secretKey: <YOUR-Secret-Key>,
);
8. Use the following code to redirect the user to the login page.
SAWO provides two ways to authenticate users, one by email and one by phone number.
// sawo object
Sawo sawo = Sawo(
apiKey: "Your API Key",
secretKey: "Your Secret key",
);
// user payload
String user = "";
void payloadCallback(context, payload) {
if (payload == null || (payload is String && payload.length == 0)) {
payload = "Login Failed :(";
}
setState(() {
user = payload;
});
}
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("UserData :- $user"),
ElevatedButton(
onPressed: () {
sawo.signIn(
context: context,
identifierType: 'email',
callback: payloadCallback,
);
},
child: Text('Email Login'),
),
ElevatedButton(
onPressed: () {
sawo.signIn(
context: context,
//can be one of 'email' or 'phone_number_sms' or 'both_email_phone'
identifierType: 'phone_number_sms',
callback: payloadCallback,
);
},
child: Text('Phone Login'),
),
],
),
),
);
}
When a user is successfully verified, the callback method will get invoked with the payload which contains userID and when something is wrong the payload will be null.
Once the SAWO SDK is successfully set up, a login form will be rendered in the provided container as displayed in the picture below:
Congratulations !! The SAWO API is now ready to be used in your Flutter application 🤘.

You can also check out SAWO's
Flutter Sample Code and Deployed App.

It's okay, we get it! You got Stuck!
😞
Feel free to contact us on #ask-for-help on our Discord

Copy link
On this page
Let's Get your Flutter App running with SAWO
Steps: